1 获取天地图Token
进入天地图官网,打开“天地图应用开发许可升级说明”,使用天地图服务,也是要申请 Token 的,接下来注册天地图账号,打开注册页面,根据提示注册即可,注册完成后点击右上角的“控制台”:
点击右上角的“创建新应用”,由于天地图系统对 Token 严格区分,所以我们就在“应用类型”里选择“浏览器端”。
2 使用天地图Token
创建成功后,复制 Token,接下来在 Cesium 中加载天地图服务,在第10行的 url
中,将末尾的“你的Token”更换为你自己刚刚创建的 Token。
var viewer = new Cesium.Viewer("cesiumContainer", {
animation: false, //是否显示动画控件
baseLayerPicker: false, //是否显示图层选择控件
geocoder: true, //是否显示地名查找控件
timeline: false, //是否显示时间线控件
sceneModePicker: true, //是否显示投影方式控件
navigationHelpButton: false, //是否显示帮助信息控件
infoBox: true, //是否显示点击要素之后显示的信息
imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
url: "http://t0.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=你的Token",
layer: "tdtBasicLayer",
style: "default",
format: "image/jpeg",
tileMatrixSetID: "GoogleMapsCompatible",
show: false
})
});
刷新页面,天地图就加载出来了:
一般地图上需要有地点标注,接下来为天地图加一层矢量注记,在上面代码后面添加(同样修改 url
中的 Token):
viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({
url: "http://t0.tianditu.com/cva_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cva&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=你的Token",
layer: "tdtAnnoLayer",
style: "default",
format: "image/jpeg",
tileMatrixSetID: "GoogleMapsCompatible",
show: false
}));
刷新页面后:
关于上述这部分,可以查阅天地图的 API。