@dvt3d/maplibre-three-plugin

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

maplibre-three-plugin 是一个巧妙的桥接插件 连接 MapLibre GL 联合来文 与 3个J,启用 在地图上执行3D渲染和动画.

中文使用文档
文档目录8 节
  1. 安装
  2. 快开始
  3. 实例
  4. 文档
  5. 地图景
  6. 场景变形
  7. 太阳
  8. 创建者

映射三插图

maplibre-three-plugin 是一个巧妙的桥接插件 连接 MapLibre GL 联合来文 与 3个J,启用 在地图上执行3D渲染和动画.

安装

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

快开始

maplibre-three-plugin 取决于3,请在使用前确定安装了3个.


<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)
})

实例

| pic | pic | pic | pic |
QQ:------------------------------------------------------------------------- ----------- --- -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 模式 | 日光灯 | 点 | 点集 | | pic | pic | pic | pic |
| 广告牌 | divi- icon (英语) | 3d-平面图 | 3d-平面图 |
| pic | pic | pic | pic | | 3d-平方厘米离子 | 3d-克-ce离子 | 3d- gs- splate (3d- gs- splate) (英语) | 热映射 |

文档

地图景

实例

const mapScene = new MapScene(map)

创建

  • 构造器( 映射, [选项])
    • 段落
      • {Map} map : 映射实例
      • {Object} options : 配置
// 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) => {
  }
})

事件钩子

这些钩子只在使用内部渲染回路时被触发.

  • preReset : 一个召唤的钩子 renderer.resetState 每个动画框之前
  • postReset: 一个召唤的钩子 renderer.resetState 每个动画框之后
  • preRender: 一个召唤的钩子 renderer.render 每个动画框之前
  • postRender: 一个召唤的钩子 renderer.render 每个动画框之后

属性

  • {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

方法

  • 添加光( 光)

    在场景中添加光线,支持自定义光线对象,但自定义光线对象需要支持 delegate 财产,以及 delegate 类型是 THREE.Object3D

    • 段落
      • {THREE.Object3D | Sun | CustomLight } light
    • 返回时
      • this
  • 删除光( 光)

    从现场取出光

    • 段落
      • {THREE.Object3D | Sun | CustomLight } light
    • 返回时
      • this
  • 添加对象(对象)

    添加对象到世界,支持自定义对象,但自定义对象需要支持 delegate 财产,以及 delegate 类型是 THREE.Object3D

    • 段落
      • {THREE.Object3D | CustomObject} object
    • 返回时
      • this
  • 删除对象(对象)

    从世界中删除对象

    • 段落
      • {THREE.Object3D | CustomObject} object
    • 返回时
      • this
  • flyto(目标,[完成],[期限])

    在一段时间内将地图飞到提供的目标,当飞行时将触发完成回调 完成后,目标需要控制 position 属性

    • 段落
      • {THREE.Object3D | CustomObject} target
      • {Function} completed
      • {Number} duration
    • 返回时
      • this
  • 缩放为( 目标, [完成])

    将地图缩放到提供的目标

    • 段落
      • {Ojbect} target
      • {Function} completed
    • 返回时
      • this
  • 打开( 类型, 回调)

    注册指定事件类型的事件听众

    • 段落
      • {String} type
      • {Function} callback
    • 返回时
      • this
  • 关闭( 类型, 回调)

    删除先前为指定事件类型的已注册事件听众

    • 段落
      • {String} type
      • {Function} callback
    • 返回时
      • this
  • 层到( [Id] 之前)

    将 3 移动到不同的 Z- 位置, 如果省略前的 Id , 则图层将附加到图层的末尾 数组,并显示在地图上所有其他图层之上.

    • 段落
      • {String} beforeId
    • 返回时
      • this
  • 添加Pass( 通过)

    向内部效应计算器添加处理后通行证。 通行证将在最后输出通过前插入 确保正确的渲染顺序.

    • 段落
      • {THREE.Pass} pass
    • 返回时
      • this
  • 删除 Pass( 通过)

    从内部EffectComposer中删除先前添加的后处理通道.

    • 段落
      • {THREE.Pass} pass
    • 返回时
      • this

场景变形

实例

const scale = new SceneTransform.projectedUnitsPerMeter(24)

静态方法

  • 预测计算器单元PerMeter ()

    • 段落
    • 返回时
      • {Number} value
  • 预测的单位

    • 段落
      • {Number} lat
    • 返回时
      • {Number} value
  • ingLatToVector3 (lng, [lat], [alt]) (英语)

    • 段落
      • {Array | Number} lng
      • {Number} lat
      • {Number} alt
    • 返回时
      • {THREE.Vector3} v
  • 向量 3ToLngLat( v)

    • 段落
      • {THREE.Vector3} v
    • 返回时
      • {Array} value

太阳

实例

const sun = new Sun()

创建

  • 构造器( )
    • 段落

属性

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

方法

  • 更新(框架状态)
    • 段落
      • {Object} frameState数字 :
    • 返回时
      • this

创建者

实例

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

静态方法

  • 创建RTC Group( 中心, [旋转], [比例)

    • 段落
      • {Array} center
      • {Array} rotation: 默认值为 [0, 0]
      • {Array} scale: 与当前纬度相对应的尺度
    • 返回时
      • {THREE.Group} group
  • 创建MercatorRTC Group( 中心, [旋转], [比例])

    • 段落
      • {Array} center
      • {Array} rotation: 默认值为 [0, 0]
      • {Array} scale: 与当前纬度相对应的尺度
    • 返回时
      • {THREE.Group} group
  • 创建 ShadowGround( 中心, [宽], [高])

    • 段落
      • {THREE.Vector3} center
      • {Number} width: 默认值为 100
      • {Number} height : 默认值为 100
    • 返回时
      • {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 是一个巧妙的桥接插件 连接 MapLibre GL 联合来文 与 3个J,启用 在地图上执行3D渲染和动画.

如何安装 @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 和提交记录判断。