You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GCSGUI/src/utils/map/TDTProvider.ts

95 lines
2.6 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-07 16:04:55
* @LastEditors: cbwu
* @LastEditTime: 2024-04-02 14:01:22
* @Description:
*/
// 天地图影像服务
import {
WebMapTileServiceImageryProvider,
GeographicTilingScheme,
WebMercatorTilingScheme,
} from 'cesium'
//地图服务枚举类型_c为墨卡托投影_w为经纬度投影
enum TDTLayerType {
Vec = 'vec', //矢量底图
Cva = 'cva', //矢量注记
Img = 'img', //影像底图
Cia = 'cia', //影像注记
Ter = 'ter', //地形晕渲
Cta = 'cta', //地形注记
Ibo = 'ibo', //全球境界
}
enum TDTProjectionType {
WebMercator = 'w',
WGS84 = 'c',
}
//天地图token
const TDT_tk = '1c5b7cbf9da7d33b221f68c32b6a1791'
// 服务域名
const tdtUrl = 'https://t{s}.tianditu.gov.cn'
// 服务负载子域
const subdomains = ['0', '1', '2', '3', '4', '5', '6', '7']
/**
* 获取天地图影像服务
* @param layerType :影像类型
* @param projectionType :投影类型
* @param minimumLevel :最小缩放级别
* @param maximumLevel :最大缩放级别
* @returns :ImageryProvider
*/
export function getTDTProvider(
layerType: string,
projectionType: string,
minimumLevel: number = 0,
maximumLevel: number = 18,
) {
// 切片方式
const tilingScheme =
projectionType == TDTProjectionType.WGS84
? new GeographicTilingScheme()
: new WebMercatorTilingScheme()
const tileMatrixLabels =
projectionType == TDTProjectionType.WGS84
? new Array(19).fill(1).map((v, i) => `${i}`)
: undefined
const imageryProvider = new WebMapTileServiceImageryProvider({
//影像底图
url:
`${tdtUrl}/DataServer?T=${layerType}_${projectionType}&x={TileCol}&y={TileRow}&l={TileMatrix}&tk=` +
TDT_tk,
subdomains: subdomains, //天地图8个服务器
minimumLevel: minimumLevel, //定义最小缩放级别
maximumLevel: maximumLevel, //定义最大缩放级别
layer: layerType,
style: 'default',
format: 'tiles',
tileMatrixSetID: projectionType, //'GoogleMapsCompatible', //使用谷歌的瓦片切片方式
tilingScheme: tilingScheme,
tileMatrixLabels: tileMatrixLabels,
})
return imageryProvider
}
/**
* 获取天地图三维地形服务
* @returns ImageryProvider
*/
export function getTDTTerrainProvider() {
const terrainUrls: string[] = []
for (let i = 0; i < subdomains.length; i++) {
const url =
tdtUrl.replace('{s}', subdomains[i]) +
'/mapservice/swdx?T=elv_c&tk=' +
TDT_tk
terrainUrls.push(url)
}
const provider = new window.cesium.GeoTerrainProvider({
urls: terrainUrls,
})
return provider
}
export { TDTLayerType, TDTProjectionType }