效果如下

注:高德使用天地圖底圖獲取到的地位坐標系近似為 WGS84
如果入庫需要高德坐標系 需要自己轉化
同理 使用高德逆地理等高德API ,獲取的點位需要轉換成 WGS84 進行地圖打點 否則看起來或有偏移
下述代碼 需要自己提供天地圖的key
附上代碼:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>批量修改圖層</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申請的key值"></script>
<script src='https://a.amap.com/jsapi_demos/static/citys.js'></script>
<style>
html,
body,
#container {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="input-card" style="width: auto;">
<div class="input-item">
<button class="btn" onclick="layerGroup.show()">顯示圖層</button>
</div>
<div class="input-item">
<button class="btn" onclick="layerGroup.hide()">隱藏圖層</button>
</div>
<div class="input-item">
<button class="btn" onclick="layerGroup.setOptions({ opacity: Math.random() })">隨機修改圖層透明度</button>
</div>
<div class="input-item">
<button class="btn" onclick="layerGroup.reload()">重載圖層</button>
</div>
</div>
<script src="https://unpkg.com/gcoord/dist/gcoord.js"></script>
<script>
var key = '天地圖的key'
var xyzTileLayer = new AMap.TileLayer({
// 天地圖底圖圖塊取圖地址
getTileUrl: `http://t{0,1,2,3,4,5,6,7}.tianditu.gov.cn/DataServer?T=vec_w&tk=${key}&x=[x]&y=[y]&l=[z]`,
zIndex: 1
})
var wordTileLayer = new AMap.TileLayer({
// 天地圖文字標注圖塊取圖地址
getTileUrl: `http://t{0,1,2,3,4,5,6,7}.tianditu.gov.cn/DataServer?T=cva_w&tk=${key}&x=[x]&y=[y]&l=[z]`,
zIndex: 2
})
var map = new AMap.Map('container', {
resizeEnable: true,
center: [120.18870707737302, 30.2356591501443],
zoom: 17,
layers: [
xyzTileLayer,
wordTileLayer
],
});
map.on('click', function(e) {
console.log('e.lnglat.getLng() + ',' + e.lnglat.getLat()',e.lnglat.getLng() + ',' + e.lnglat.getLat());
var tra = gcoord.transform(
[e.lnglat.getLng(), e.lnglat.getLat()], // 經緯度坐標
gcoord.WGS84, // 當前坐標系
gcoord.GCJ02 // 目標坐標系
);
console.log('tra',tra);
});
</script>
</body>
</html>
相關文章: