加载天地图-new
2023-07-25 本文已影响0人
xueyueshuai
import {get as getProjection} from 'ol/proj'
import TileLayer from "ol/layer/Tile";
import {XYZ} from "ol/source";
let typeObj = {
'vec': '矢量底图',
'cva': '矢量注记',
'img': '影像底图',
'cia': '影像注记',
'ter': '地形晕渲',
'cta': '地形注记',
'ibo': '全球境界',
'eva': '矢量英文注记',
'eia': '影像英文注记',
}
let projectionWayObj = {
'c': '经纬度投影',
'w': '球面墨卡托投影',
}
let xysGetTDT = (epsg = 'EPSG:4326', type = 'vec', projectionWay = 'w', layerOption = {}) => {
let sourceOption = {}
if (projectionWay === 'c') {
sourceOption.projection = getProjection(epsg)
}
if(epsg === 'EPSG:3857' && projectionWay==='c'){
projectionWay = 'w'
}
return new TileLayer({
name: '天地图-' + typeObj[type] + '-' + projectionWayObj[projectionWay],
source: new XYZ({
url: 'http://t0.tianditu.gov.cn/DataServer?T=' + type + '_' + projectionWay + '&x={x}&y={y}&l={z}&tk=6d6732d7f432d1a70b3c0c9fc0e4d8fd',
...sourceOption
}),
...layerOption
})
}
export default xysGetTDT