超图默认加载天地图的方法为TiandituImageryProvider,发现在放大到一定层级后会显示无图层
如果使用原版cesium加载天地图的方法会出现400报错
改为使用拼接后完整的天地图url地址才能正常加载
type TMapType = 'vec' | 'cva' | 'img' | 'cia' | 'ter' | 'cta' | 'ibo' | 'eva' | 'eia' | 'img_c' | 'cia_c' | 'img_w' | 'cia_w';
const tdtToekn = import.meta.env.VITE_MAP_KEY
/**
* 为cesimu添加天地图的底图
* @param viewer
* @param layer
* vec:矢量底图、cva:矢量标注、img:影像底图、cia:影像标注
* ter:地形晕渲、cta:地形标注、eva:矢量英文标注、eia:影像英文标注
*/
export function addTMap(viewer: any, layer: TMapType) {
if (!tdtToekn) {
console.warn('天地图 token 未配置,无法加载底图')
return
}
const isGeographic = layer.endsWith('_c')
const matrixSet = isGeographic ? 'w' : 'w'
const layerName = isGeographic ? layer.replace('_w', '') : layer
// 明确写出 WMTS 参数,避免超图定制版 Cesium 省略 layer 参数触发 400
const tMapImagery = new Cesium.WebMapTileServiceImageryProvider({
url: `https://t{s}.tianditu.gov.cn/${layerName}_${matrixSet}/wmts?service=WMTS&request=GetTile&version=1.0.0&LAYER=${layerName}&STYLE=default&TILEMATRIXSET=${matrixSet}&FORMAT=tiles&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&tk=${tdtToekn}`,
layer: layerName,
style: 'default',
format: 'tiles',
tileMatrixSetID: matrixSet,
subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
maximumLevel: 18,
// tilingScheme: isGeographic ? new Cesium.GeographicTilingScheme() : undefined
})
viewer.imageryLayers.addImageryProvider(tMapImagery)
}