使用TileLayer.getTileUrl属性,通过函数指定栅格图层的取图地址。
![](https://myxmkj.com/wp-content/uploads/2021/05/sgg.png)
<!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>
<style>
html,
body,
#container {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script>
// 高德栅格路况
var traffic = new AMap.TileLayer({
'getTileUrl': function (x, y, z) {
var a = 'https://tm.amap.com/trafficengine/mapabc/traffictile?v=1.0&t=1&zoom=' + (17 - z) + '&x=' + x + '&y=' + y;
return a;
},
'zooms': [6, 20],
'zIndex': 4
});
var map = new AMap.Map('container', {
resizeEnable: true,
layers: [
new AMap.TileLayer.Satellite(),
new AMap.TileLayer.RoadNet(),
traffic
]
});
</script>
</body>
</html>