1. 在天地图官网上申请开发者Key
2. 调用在线的天地图
直接上源码:
const EPSG = 'EPSG:4490';
this.map = new Map({
target: 'map',
controls: defaults({ attribution: false, zoom: true, rotate: false, collapsed: false }),
view: new View({
center: centerid,
zoom: 8,
projection: EPSG,
multiWorld: true
})
});
const tileLayer1 = new TileLayer({
id: 'tileLayer',
title: 'base',
layerName: 'baselayer',
source: new XYZ({
url: 'http://t0.tianditu.com/DataServer?T=vec_w&tk=申请的key&x={x}&y={y}&l={z}',
wrapX: true
})
});
const tileLayer2 = new TileLayer({
id: 'annotLayer',
title: 'annot',
layerName: 'annotlayer',
source: new XYZ({
url: 'http://t0.tianditu.com/DataServer?T=cva_w&tk=申请的key&x={x}&y={y}&l={z}',
wrapX: true
})
});
this.map.addLayer(tileLayer1);
this.map.addLayer(tileLayer2);
3. url 中的 T 底图类型根据自己的需要设置
http://t0.tianditu.com/DataServer?T=cva_w