随着数字孪生、智慧城市等应用场景的兴起,对三维地图渲染能力的需求日益增长。百度地图推出了基于 Three.js 的 JSAPI Three(mapvthree)引擎,为开发者提供了全新的二三维一体化地图解决方案。本文将从多个维度深入分析 JSAPI Three 与 JSAPI GL、JSAPI 2D(3.0和2.0版)等引擎的核心区别。
核心技术栈:
@baidumap/mapv-three(对外统一命名)// JSAPI Three 的安装方式(唯一支持 npm 安装的百度地图引擎)
npm i -S @baidumap/mapv-three three架构特点:
THREE.Scene、THREE.Camera、THREE.WebGLRenderer 等核心对象THREE.Object3D// JSAPI Three 可以直接添加 Three.js 原生对象
const engine = new mapvthree.Engine(container);
const mesh = new THREE.Mesh(geometry, material);
engine.add(mesh); // 直接添加 Three.js 对象核心技术栈:
架构特点:
核心技术栈:
架构特点:
二三维一体化渲染:
丰富的可视化组件:
// 点数据可视化
- SimplePoint(简单点)
- Circle(圆形点)
- BubblePoint(气泡点)
- Icon(图标点)
- Label(标签点)
- Heatmap(热力图)
- ClusterPoint(聚合点)
// 线数据可视化
- Polyline(折线)
- FatLine(粗线)
- SimpleLine(简单线)
// 面数据可视化
- Polygon(多边形)
- Grid(网格)
- Wall(墙体)
// 三维可视化
- SimpleModel(简单模型)
- InstancedMesh(实例化网格)
- Default3DTiles(3D Tiles)三维模型支持:
高级渲染特效:
// 渲染特效配置
engine.rendering.features = {
antialias: {
enabled: true,
method: 'smaa', // 抗锯齿
},
bloom: {
enabled: true,
strength: 0.1, // 泛光效果
threshold: 1,
radius: 0,
},
colorAdjustment: {
enabled: true,
brightness: 0, // 亮度调整
contrast: 0, // 对比度调整
saturation: 0, // 饱和度调整
},
};2.5D 地图渲染:
二维地图渲染:
内置 GIS 分析功能:
这些分析功能都是基于三维场景实现的,能够提供更直观、更准确的分析结果。
共同特点:
自然环境渲染:
// 支持多种天空类型
- StaticSky(静态天空)
- DynamicSky(动态天空)
- DefaultSky(默认天空)
- EmptySky(空天空,用于叠加其他地图)
// 天气系统(需要配合 DynamicSky 使用)
const sky = engine.add(new mapvthree.DynamicSky());
const weather = engine.add(new mapvthree.DynamicWeather(sky));
weather.weather = 'rainy'; // clear | partlyCloudy | cloudy | overcast | foggy | rainy | snowy光照系统:
// 时钟系统配置
engine.clock = {
currentTime: new Date('2025-05-15 12:30:00'),
tickMode: 1,
speed: 1000,
};JSAPI GL:
JSAPI 2D:
多种数据源类型:
// GeoJSON 数据源
const geoJsonSource = new mapvthree.GeoJSONDataSource.fromGeoJSON({
type: 'FeatureCollection',
features: [...]
});
// CSV 数据源
const csvSource = new mapvthree.CSVDataSource.fromCSV(csvData);
// JSON 数据源
const jsonSource = new mapvthree.JSONDataSource.fromJSON(jsonData);数据源与可视化组件解耦:
// 数据源可以灵活切换
const point = engine.add(new mapvthree.SimplePoint());
point.dataSource = geoJsonSource; // 可以随时更换数据源共同特点:
最简化初始化:
// 通过 npm 安装后引入
import * as mapvthree from '@baidumap/mapv-three';
const container = document.getElementById('container');
const engine = new mapvthree.Engine(container);
engine.map.setPitch(75);
// 清理资源
// engine.dispose();完整配置初始化:
import * as mapvthree from '@baidumap/mapv-three';
const container = document.getElementById('container');
const engine = new mapvthree.Engine(container, {
map: {
provider: new mapvthree.BaiduVectorTileProvider(),
center: [116, 39],
heading: 0,
pitch: 60,
range: 2000,
projection: 'EPSG:3857',
},
rendering: {
enableAnimationLoop: true,
features: {
bloom: { enabled: true },
antialias: { enabled: true },
},
},
clock: {
currentTime: new Date(),
speed: 1000,
},
});特点:
// 通过 script 标签引入(只能通过官方链接引入)
// <script src="https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=您的密钥"></script>
const map = new BMapGL.Map("container");
map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
map.setHeading(45); // 设置旋转角度
map.setTilt(60); // 设置倾斜角度特点:
// JSAPI 2D 3.0 版(通过 script 标签引入)
// <script src="https://api.map.baidu.com/api?v=3.0&ak=您的密钥"></script>
const map = new BMap.Map("container");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
// JSAPI 2D 2.0 版(通过 script 标签引入)
// <script src="https://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script>
const map = new BMap.Map("container");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);特点:
import * as mapvthree from '@baidumap/mapv-three';
import * as THREE from 'three';
// 添加点数据
const dataSource = new mapvthree.GeoJSONDataSource.fromGeoJSON({
type: 'FeatureCollection',
features: [...]
});
const point = engine.add(new mapvthree.SimplePoint({
size: 10,
}));
point.dataSource = dataSource;
// 添加三维模型
const model = engine.add(new mapvthree.SimpleModel({
point: [116.414, 39.915],
url: 'assets/models/building.glb',
scale: new THREE.Vector3(10, 10, 10),
}));
// 添加 Three.js 原生对象
const mesh = new THREE.Mesh(geometry, material);
engine.add(mesh);特点:
engine.add() 接口THREE.Object3D// JSAPI GL 和 JSAPI 2D 添加元素方式相同
// 添加标注点
const point = new BMap.Point(116.404, 39.915); // JSAPI 2D
// 或
const point = new BMapGL.Point(116.404, 39.915); // JSAPI GL
const marker = new BMap.Marker(point); // JSAPI 2D
// 或
const marker = new BMapGL.Marker(point); // JSAPI GL
map.addOverlay(marker);
// 添加信息窗口
const infoWindow = new BMap.InfoWindow("内容"); // JSAPI 2D
// 或
const infoWindow = new BMapGL.InfoWindow("内容"); // JSAPI GL
map.openInfoWindow(infoWindow, point);特点:
// 通过 engine.map 控制视野
engine.map.lookAt([116, 39], {
heading: 0,
pitch: 60,
range: 2000,
});
// 平滑过渡
engine.map.flyTo([116, 39], {
heading: 0,
pitch: 60,
range: 2000,
});
// 直接访问相机对象(不推荐)
engine.camera.position.set(x, y, z);特点:
engine.map 统一管理视野// JSAPI 2D - 仅支持缩放和中心点
map.centerAndZoom(point, zoom);
// 不支持旋转和倾斜
// JSAPI GL - 支持 2.5D 视角
map.centerAndZoom(point, zoom);
map.setHeading(45); // 旋转角度(0-360度)
map.setTilt(60); // 倾斜角度(0-75度,有限制)特点:
数字孪生场景:
三维数据分析:
沉浸式体验:
2.5D 地图应用:
传统二维地图应用:
业务系统集成:
优势:
性能优化建议:
// 使用实例化渲染
const instancedMesh = engine.add(new mapvthree.InstancedMesh({
// 可以高效渲染大量相同模型
}));
// 使用点聚合
const clusterPoint = engine.add(new mapvthree.ClusterPoint({
// 自动聚合相近的点,减少渲染负担
}));优势:
限制:
优势:
限制:
学习曲线:
开发体验:
学习曲线:
开发体验:
学习曲线:
开发体验:
特性 | JSAPI Three (mapvthree) | JSAPI GL | JSAPI 2D |
|---|---|---|---|
安装方式 | √ npm 安装(本地包) | × script 标签引入 | × script 标签引入 |
技术架构 | 基于 Three.js,WebGL 三维渲染 | 自研 WebGL 2.5D 渲染 | 自研 2D 渲染(Canvas/WebGL) |
三维能力 | √ 完整的真三维渲染 | √ 有限 2.5D(tilt≤75°) | × 纯二维 |
模型支持 | √ GLTF/GLB/OBJ/FBX | × 不支持 | × 不支持 |
GIS 分析 | √ 丰富的三维空间分析 | √ 基础分析功能 | √ 基础分析功能 |
环境特效 | √ 天空、天气、光照系统 | × 无 | × 无 |
数据源 | √ 多种格式,灵活切换 | √ 相对有限 | √ 相对有限 |
渲染特效 | √ Bloom、抗锯齿等 | × 有限 | × 有限 |
视野控制 | √ 自由三维视角 | √ 2.5D 视角(有限) | × 仅缩放和平移 |
性能 | √ GPU 加速,支持大规模场景 | √ WebGL 加速 | √ 2.0版Canvas,3.0版WebGL |
学习曲线 | 需要 Three.js 基础 | 简单易学 | 简单易学 |
适用场景 | 数字孪生、三维可视化 | 需要 2.5D 效果的地图应用 | 传统 LBS 应用 |
选择 JSAPI Three 的场景:
选择 JSAPI GL 的场景:
选择 JSAPI 2D 的场景:
随着数字孪生、元宇宙等概念的兴起,三维地图渲染能力正成为地图引擎的核心竞争力。JSAPI Three 作为百度地图在三维领域的创新产品,代表了地图引擎的发展方向。对于新项目,如果对三维能力有需求,建议优先考虑 JSAPI Three。
同时,JSAPI Three 也支持与 JSAPI GL 和 JSAPI 2D 叠加使用,可以在现有项目基础上逐步引入三维能力,实现平滑的技术升级。
重要提示:
@baidumap/mapv-three(@baidu/mapv-three 为内部命名)参考资源:JSAPI Three 官方文档
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。