@dvt3d/maplibre-three-plugin

中文文档
1.7.1发布于 2026/07/26Apache-2.0TypeScriptES Module零依赖近 30 天下载 1.4万

maplibre-three-plugin is a bridge plugin that cleverly connects MapLibre GL JS with Three.js, enabling developers to implement 3D rendering and animation on maps.

原始使用文档
文档目录8 节
  1. Install
  2. Quickly Start
  3. Examples
  4. Docs
  5. MapScene
  6. SceneTransform
  7. Sun
  8. Creator

maplibre-three-plugin

maplibre-three-plugin is a bridge plugin that cleverly connects MapLibre GL JS with Three.js, enabling developers to implement 3D rendering and animation on maps.

Install

npm install @dvt3d/maplibre-three-plugin
----------------------------------------
yarn add @dvt3d/maplibre-three-plugin

Quickly Start

maplibre-three-plugin depends on three, please make sure three is installed before using it.


<div id="map-container"></div>

import maplibregl from 'maplibre-gl'
import * as THREE from 'three'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
import * as MTP from '@dvt3d/maplibre-three-plugin'

const map = new maplibregl.Map({
  container: 'map-container', // container id
  style: 'https://api.maptiler.com/maps/basic-v2/style.json?key=get_access_key',
  zoom: 18,
  center: [148.9819, -35.3981],
  pitch: 60,
  canvasContextAttributes: { antialias: true },
  maxPitch: 85,
})

//init three scene
const mapScene = new MTP.MapScene(map)

//add light
mapScene.addLight(new THREE.AmbientLight())

// add model
const glTFLoader = new GLTFLoader()

glTFLoader.load('./assets/34M_17/34M_17.gltf', (gltf) => {
  let rtcGroup = MTP.Creator.createRTCGroup([148.9819, -35.39847])
  rtcGroup.add(gltf.scene)
  mapScene.addObject(rtcGroup)
})

Examples

| pic | pic | pic | pic |
|:------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------:| | model | sun-light | point | point-collection | | pic | pic | pic | pic |
| billboard | div-icon | 3d-tiles | 3d-tiles-osgb |
| pic | pic | pic | pic | | 3d-tiles-cesium-ion | 3d-gs-cesium-ion | 3d-gs-splat | heat-map |

Docs

MapScene

examples

const mapScene = new MapScene(map)

creation

  • constructor(map,[options])
    • params
      • {Map} map : map instance
      • {Object} options : config
// config
Object({
  /**
   * Existing THREE.Scene instance.
   * If not provided, an internal default scene will be created.
   */
  scene: null,

  /**
   * Existing THREE.Camera instance.
   * If not provided, an internal default camera will be created.
   */
  camera: null,

  /**
   * Existing THREE.WebGLRenderer instance.
   * If not provided, an internal default renderer will be created.
   */
  renderer: null,

  /**
   * Whether to preserve the drawing buffer.
   * When enabled, the canvas content will be retained after rendering,
   * which is useful for screenshots or readPixels operations.
   * Note: Enabling this may have a performance impact.
   */
  preserveDrawingBuffer: false,

  /**
   * Whether to enable post-processing rendering.
   * When enabled, Three.js content will be rendered through
   * an offscreen render target before being composited onto the map.
   * When disabled, Three.js renders directly into the shared MapLibre canvas
   * for maximum performance and stability.
   */
  enablePostProcessing: false,

  /**
   * Custom frame render loop.
   *
   * This function will be called every frame.
   * If not provided, the internal default render loop will be used.
   *
   * ⚠️ Note:
   * Providing a custom renderLoop means you take full control
   * of the render lifecycle. The built-in rendering pipeline
   * will be bypassed.
   *
   * As a result, the following internal event hooks will
   * NOT be triggered automatically:
   *
   * - preReset
   * - postReset
   * - preRender
   * - postRender
   *
   * If needed, you must manually call the corresponding logic
   * inside your custom renderLoop.
   *
   * @param {MapScene} ins - The current MapScene instance
   */
  renderLoop: (ins) => {
  }
})

event hooks

These hooks are only triggered when using the internal render loop.

  • preReset : A hook that calls renderer.resetState before each animation frame
  • postReset: A hook that calls renderer.resetState after each animation frame
  • preRender: A hook that calls renderer.render before each animation frame
  • postRender: A hook that calls renderer.render after each animation frame

properties

  • {maplibregl.Map} map : readonly
  • {HTMLCanvasElement} canvas : readonly
  • {THREE.Camera} camera : readonly
  • {THREE.Sence} scene : readonly
  • {THREE.Group} lights: readonly
  • {THREE.Group} world : readonly
  • {THREE.WebGLRenderer} renderer : readonly
  • {EffectComposer} composer : readonly
  • {RenderPass} renderPass : readonly
  • {OutputPass} outputPass : readonly

methods

  • addLight(light)

    Add light to the scene, support custom light objects, but the custom light objects need to support the delegate property, and the delegate type is THREE.Object3D

    • params
      • {THREE.Object3D | Sun | CustomLight } light
    • returns
      • this
  • removeLight(light)

    Remove light from the scene

    • params
      • {THREE.Object3D | Sun | CustomLight } light
    • returns
      • this
  • addObject(object)

    Add an object to world,support custom object, but the custom object need to support the delegate property, and the delegate type is THREE.Object3D

    • params
      • {THREE.Object3D | CustomObject} object
    • returns
      • this
  • removeObject(object)

    Remove an object from world

    • params
      • {THREE.Object3D | CustomObject} object
    • returns
      • this
  • flyTo(target,[completed],[duration])

    Fly the map to the provided target over a period of time, the completion callback will be triggered when the flight is complete, the target needs to contain the position property

    • params
      • {THREE.Object3D | CustomObject} target
      • {Function} completed
      • {Number} duration
    • returns
      • this
  • zoomTo(target,[completed])

    Zoom the map to the provided target

    • params
      • {Ojbect} target
      • {Function} completed
    • returns
      • this
  • on(type,callback)

    Registers an event listener for the specified event type

    • params
      • {String} type
      • {Function} callback
    • returns
      • this
  • off(type,callback)

    Removes a previously registered event listener for the specified event type

    • params
      • {String} type
      • {Function} callback
    • returns
      • this
  • layerBeforeTo([beforeId])

    Moves the three to a different z-position, If beforeId is omitted, the layer will be appended to the end of the layers array and appear above all other layers on the map.

    • params
      • {String} beforeId
    • returns
      • this
  • addPass(pass)

    Adds a post-processing pass to the internal EffectComposer. The pass will be inserted before the final output pass to ensure correct rendering order.

    • params
      • {THREE.Pass} pass
    • returns
      • this
  • removePass(pass)

    Removes a previously added post-processing pass from the internal EffectComposer.

    • params
      • {THREE.Pass} pass
    • returns
      • this

SceneTransform

examples

const scale = new SceneTransform.projectedUnitsPerMeter(24)

static methods

  • projectedMercatorUnitsPerMeter()

    • params
    • returns
      • {Number} value
  • projectedUnitsPerMeter(lat)

    • params
      • {Number} lat
    • returns
      • {Number} value
  • lngLatToVector3(lng, [lat], [alt] )

    • params
      • {Array | Number} lng
      • {Number} lat
      • {Number} alt
    • returns
      • {THREE.Vector3} v
  • vector3ToLngLat(v)

    • params
      • {THREE.Vector3} v
    • returns
      • {Array} value

Sun

examples

const sun = new Sun()

creation

  • constructor()
    • params

properties

  • {THREE.Group} delegate : readonly
  • {Boolean} castShadow
  • {Date | String} currentTime
  • {THREE.DirectionalLight} sunLight : readonly
  • {THREE.HemisphereLight} hemiLight: readonly

methods

  • update(frameState)
    • params
      • {Object} frameState:
    • returns
      • this

Creator

examples

const rtcGroup = Creator.createRTCGroup([-1000, 0, 0])

static methods

  • createRTCGroup(center, [rotation], [scale])

    • params
      • {Array} center
      • {Array} rotation: default value is [0,0,0]
      • {Array} scale: scale corresponding to the current latitude
    • returns
      • {THREE.Group} group
  • createMercatorRTCGroup(center, [rotation], [scale])

    • params
      • {Array} center
      • {Array} rotation: default value is [0,0,0]
      • {Array} scale: scale corresponding to the current latitude
    • returns
      • {THREE.Group} group
  • createShadowGround(center, [width], [height])

    • params
      • {THREE.Vector3} center
      • {Number} width: default value is 100
      • {Number} height : default value is 100
    • returns
      • {THREE.Mesh} mesh

版本与发布记录

@dvt3d/maplibre-three-plugin 共发布 12 个版本,首次发布于 2025/07/29;过去 12 个月发布了 8 个版本。

版本发布日期距今
1.7.1latest2026/07/263 个月前
1.7.02026/07/253 个月前
1.6.02026/03/167 个月前
1.5.22026/03/058 个月前
1.5.12026/02/288 个月前
1.5.02026/02/268 个月前

关于 @dvt3d/maplibre-three-plugin 的常见问题

@dvt3d/maplibre-three-plugin 是什么?

maplibre-three-plugin is a bridge plugin that cleverly connects MapLibre GL JS with Three.js, enabling developers to implement 3D rendering and animation on maps.

如何安装 @dvt3d/maplibre-three-plugin?

在项目目录运行 npm install @dvt3d/maplibre-three-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:three(^0.178.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dvt3d/maplibre-three-plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dvt3d/maplibre-three-plugin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dvt3d/maplibre-three-plugin 可以商用吗?

@dvt3d/maplibre-three-plugin 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dvt3d/maplibre-three-plugin 的下载量有多少?

根据 npm 官方下载统计,@dvt3d/maplibre-three-plugin 在 2026/10/13 – 2026/11/11 这 30 天内被下载 14,468 次,日均约 482 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dvt3d/maplibre-three-plugin 还在维护吗?

最新版本 1.7.1 发布于 2026/07/26(3 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 8 个;首次发布于 2025/07/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。