三国志战略版下载安装教程(2026 最新版):电脑版下载 + 安装配置全流程图文详解
2026/1/14 17:16:33
Leaflet/Mapbox/OpenLayers默认用Web墨卡托(EPSG:3857),Cesium默认用WGS-84(EPSG:4326),但都支持坐标系扩展。
| 框架 | 默认坐标系 | 显示方式 | 内部计算 | 坐标单位 | 典型应用 |
|---|---|---|---|---|---|
| Leaflet | EPSG:3857 (Web墨卡托) | 平面XY像素 | 墨卡托投影 | 米 | 轻量级Web地图 |
| Mapbox GL | EPSG:3857 | 瓦片+矢量切片 | 墨卡托投影 | 米/像素 | 高性能矢量地图 |
| OpenLayers | EPSG:3857 | 支持多种投影 | 可配置 | 米/度 | 专业GIS应用 |
| Cesium | EPSG:4979 (WGS-84 3D) | 三维球面 | 地心直角坐标 | 米/弧度 | 三维地球/时空数据 |
// Leaflet 默认使用 Web墨卡托 (EPSG:3857)// 但接受的坐标格式是 [纬度, 经度] (WGS-84)// ❌ 错误:用墨卡托坐标L.marker([20037508.34,0]).addTo(map);// 完全错误!// ✅ 正确:用WGS-84经纬度L.marker([39.908692,116.397477]).addTo(map);// [lat, lng]// Leaflet 内部转换流程:用户输入[lat,lng](WGS-84)↓ Leaflet 内部转换 转换为[x,y](EPSG:3857米坐标)↓ 在屏幕上显示像素位置Leaflet坐标系特点:
[lat, lng])添加其他坐标系支持:
// 使用 Proj4Leaflet 插件支持其他坐标系L.CRS.CustomEPSG4326=newL.Proj.CRS('EPSG:4326','+proj=longlat +datum=WGS84 +no_defs',{resolutions:[/* 自定义分辨率 */],origin:[0,0]});constmap=L.map('map',{crs:L.CRS.CustomEPSG4326// 使用WGS-84经纬度坐标系});// Mapbox 也使用 EPSG:3857// 但通过矢量切片和样式渲染// 初始化地图(默认3857)constmap=newmapboxgl.Map({container:'map',style:'mapbox://styles/mapbox/streets-v11',center:[116.397477,39.908692],// [lng, lat] 注意顺序!zoom:12});// Mapbox 内部处理:矢量切片数据(EPSG:3857坐标)↓GPU渲染 根据样式动态渲染 ↓ 支持3D地形、建筑Mapbox坐标系特点:
[lng, lat](与Leaflet相反!)自定义坐标系示例:
// Mapbox 对非3857坐标系支持有限// 通常需要预处理数据import{transform}from'@turf/proj';// 将WGS-84数据转换为3857constwgs84Feature={type:'Feature',geometry:{type:'Point',coordinates:[116.397477,39.908692]// WGS-84}};constwebMercatorFeature=transform(wgs84Feature,'EPSG:4326','EPSG:3857');// 添加到Mapboxmap.addSource('point',{type:'geojson',data:webMercatorFeature});// OpenLayers 最灵活,支持多种坐标系import{Map,View}from'ol';import{fromLonLat,transform}from'ol/proj';// 1. 默认使用EPSG:3857constmap=newMap({target:'map',view:newView({center:fromLonLat([116.397477,39.908692]),// 转换到3857zoom:8})});// 2. 使用WGS-84经纬度坐标系import{getasgetProjection}from'ol/proj';constwgs84Map=newMap({target:'map',view:newView({projection:'EPSG:4326',// 直接使用WGS-84center:[116.397477,39.908692],// 直接使用经纬度zoom:8})});// 3. 使用中国常用坐标系importproj4from'proj4';import{register}from'ol/proj/proj4';// 注册CGCS2000投影proj4.defs('EPSG:4490','+proj=longlat +ellps=GRS80 +no_defs');register(proj4);constchinaMap=newMap({target:'map',view:newView({projection:'EPSG:4490',// CGCS2000center:[116.397477,39.908692],zoom:8})});OpenLayers坐标系优势:
import{transform,transformExtent}from'ol/proj';// 坐标转换constcoords3857=transform([116.397477,39.908692],'EPSG:4326',// 从'EPSG:3857'// 到);// 范围转换constextent3857=transformExtent([116.0,39.0,117.0,40.0],// WGS-84范围'EPSG:4326','EPSG:3857');// Cesium 使用三维坐标系// 默认:WGS-84 (EPSG:4979)constviewer=newCesium.Viewer('cesiumContainer');// 1. 地理坐标(经纬度高程)constposition=Cesium.Cartographic.fromDegrees(116.397477,// 经度39.908692,// 纬度100// 高程(米));// 2. 地心直角坐标(ECEF)constcartesian=Cesium.Cartesian3.fromDegrees(116.397477,// 经度39.908692,// 纬度100// 高程);// 3. 屏幕坐标constscreenPosition=Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene,cartesian);// 4. 局部坐标系(ENU)constenuMatrix=Cesium.Transforms.eastNorthUpToFixedFrame(cartesian);Cesium坐标系统:
| 坐标系类型 | 描述 | 用途 |
|---|---|---|
| WGS-84地理坐标 | 经度、纬度、高程 | 用户输入/输出 |
| 地心直角坐标 | (X, Y, Z) 地心坐标 | 内部计算 |
| 局部ENU | 东-北-天局部坐标系 | 模型放置、测量 |
| 屏幕坐标 | 像素坐标 | 拾取、交互 |
坐标转换示例:
// 常用转换函数// 1. 经纬度 ←→ 笛卡尔坐标constcartesian=Cesium.Cartesian3.fromDegrees(lng,lat,height);constcartographic=Cesium.Cartographic.fromCartesian(cartesian);constlng=Cesium.Math.toDegrees(cartographic.longitude);constlat=Cesium.Math.toDegrees(cartographic.latitude);// 2. 坐标系转换(如WGS-84到CGCS2000)// 注意:Cesium默认WGS-84,需自定义转换functionwgs84ToCgcs2000(cartesian){// 简化的七参数转换(示例参数)constdx=1.1,dy=2.3,dz=-3.2;constrx=0.0000012,ry=0.0000009,rz=-0.0000015;constscale=1.00000006;// 布尔莎七参数转换constx=cartesian.x;consty=cartesian.y;constz=cartesian.z;constx2=dx+scale*x+rz*y-ry*z;consty2=dy-rz*x+scale*y+rx*z;constz2=dz+ry*x-rx*y+scale*z;returnnewCesium.Cartesian3(x2,y2,z2);}| 框架 | 原生支持 | 解决方案 | 易用性 |
|---|---|---|---|
| Leaflet | ❌ 不支持 | 插件或预处理 | 中等 |
| Mapbox | ❌ 不支持 | 预处理数据 | 困难 |
| OpenLayers | ✅ 支持 | 注册投影定义 | 简单 |
| Cesium | ❌ 不支持 | 自定义转换 | 复杂 |
OpenLayers实现GCJ-02:
// 1. 定义GCJ-02投影proj4.defs('GCJ-02','+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs');// 2. 注册到OpenLayersregister(proj4);// 3. 创建使用GCJ-02的地图constgcjMap=newMap({view:newView({projection:'GCJ-02',center:[116.397477,39.908692],zoom:10})});// 4. 坐标转换constgcjCoord=transform([116.397477,39.908692],'EPSG:4326',// WGS-84'GCJ-02'// 火星坐标);// Leaflet + 高德地图(GCJ-02)L.tileLayer('https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',{subdomains:['1','2','3','4']}).addTo(map);// OpenLayers + 天地图(CGCS2000)consttianLayer=newTileLayer({source:newXYZ({projection:'EPSG:4490',// CGCS2000url:'http://t0.tianditu.gov.cn/vec_w/wmts?tk=您的密钥'})});// Cesium + 高德影像viewer.imageryLayers.addImageryProvider(newCesium.UrlTemplateImageryProvider({url:'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',subdomains:['1','2','3','4']}));| 需求场景 | 推荐框架 | 坐标系考虑 |
|---|---|---|
| 简单地图显示 | Leaflet | EPSG:3857,坐标顺序[lat,lng] |
| 高性能矢量地图 | Mapbox GL | EPSG:3857,坐标顺序[lng,lat] |
| 多坐标系GIS应用 | OpenLayers | 支持任意坐标系,转换灵活 |
| 三维地球/时空 | Cesium | WGS-84三维坐标 |
| 中国境内应用 | OpenLayers | 对国内坐标系支持最好 |
| 移动端轻量应用 | Leaflet | 体积小,支持GCJ-02插件 |
// 通用坐标处理函数classCoordinateManager{constructor(baseFramework){this.framework=baseFramework;}// 统一输入为[lng, lat]格式normalizeInput(lng,lat){return{lng,lat};}// 根据框架转换坐标toFrameworkCoord(lng,lat,targetSystem='display'){switch(this.framework){case'leaflet':// Leaflet: [lat, lng]returntargetSystem==='gcj02'?this.wgs84ToGcj02(lng,lat):[lat,lng];case'mapbox':// Mapbox: [lng, lat]returntargetSystem==='gcj02'?this.wgs84ToGcj02(lng,lat):[lng,lat];case'openlayers':// OpenLayers: 可配置returntargetSystem==='gcj02'?this.wgs84ToGcj02(lng,lat):[lng,lat];case'cesium':// Cesium: 笛卡尔坐标returnCesium.Cartesian3.fromDegrees(lng,lat);default:thrownewError('Unsupported framework');}}// WGS-84转GCJ-02wgs84ToGcj02(lng,lat){// 实现GCJ-02加密算法// ... 转换逻辑 ...return{lng:gcjLng,lat:gcjLat};}}// ❌ 常见错误:框架间坐标顺序不一致constleafletCoords=[39.9,116.4];// Leaflet: [lat, lng]constmapboxCoords=[116.4,39.9];// Mapbox: [lng, lat]// ✅ 解决方案:统一处理函数functionnormalizeCoords(lat,lng,framework){constcoords={leaflet:[lat,lng],mapbox:[lng,lat]};returncoords[framework]||[lng,lat];}// 问题:WGS-84坐标在中国地图上显示偏移// 原因:国内地图使用GCJ-02// 解决方案:显示前转换functiondisplayInChina(lng,lat,framework){// 1. 转换为GCJ-02constgcj=wgs84ToGcj02(lng,lat);// 2. 根据框架使用正确格式switch(framework){case'leaflet':return[gcj.lat,gcj.lng];case'mapbox':case'openlayers':return[gcj.lng,gcj.lat];case'cesium':// Cesium需要特殊处理returnCesium.Cartesian3.fromDegrees(gcj.lng,gcj.lat);}}// 处理不同坐标系的数据源asyncfunctionloadMultiSourceData(){// 数据源1:WGS-84 (GPS)constgpsData=awaitfetchGPSData();// EPSG:4326// 数据源2:GCJ-02 (高德)constamapData=awaitfetchAmapData();// GCJ-02// 数据源3:CGCS2000 (国内测绘)constsurveyData=awaitfetchSurveyData();// EPSG:4490// 统一转换到地图坐标系constunifiedData=[...gpsData,// 已经是WGS-84...amapData.map(d=>gcj02ToWgs84(d)),// GCJ-02转WGS-84...surveyData.map(d=>transform(d,'EPSG:4490','EPSG:4326'))];returnunifiedData;}[lat,lng],其他一般是[lng,lat]// 1. 定义项目坐标系策略constCOORDINATE_CONFIG={storage:'EPSG:4326',// 存储用WGS-84display:'GCJ-02',// 中国地图显示用GCJ-02framework:'openlayers',// 使用OpenLayersinputFormat:[lng,lat]// 统一输入格式};// 2. 创建坐标转换器classProjectionManager{constructor(config){this.config=config;this.initProj4();}initProj4(){// 注册所有需要的坐标系proj4.defs('EPSG:4326','+proj=longlat +datum=WGS84 +no_defs');proj4.defs('EPSG:3857','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs');proj4.defs('GCJ-02',GCJ02_PROJ_DEF);register(proj4);}// 统一转换接口transform(coords,fromCRS,toCRS){returntransform(coords,fromCRS,toCRS);}}| 操作 | Leaflet | Mapbox | OpenLayers | Cesium |
|---|---|---|---|---|
| 默认坐标系 | 3857 | 3857 | 3857 | 4979 |
| 坐标格式 | [lat,lng] | [lng,lat] | [lng,lat] | 笛卡尔坐标 |
| 支持GCJ-02 | 需插件 | 需预处理 | 原生支持 | 需自定义 |
| 多坐标系 | 需插件 | 有限 | 强大支持 | 需自定义 |
| 中国底图 | 直接支持 | 需处理切片 | 直接支持 | 需自定义 |
| 学习曲线 | 简单 | 中等 | 较陡 | 陡峭 |
简单选择指南: