实时路况图层
html,
body,
#container {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
显示/隐藏实时路况
var map = new AMap.Map('container', {
resizeEnable: true,
center: [116.397428, 39.90923],
zoom: 13
});
//实时路况图层
var trafficLayer = new AMap.TileLayer.Traffic({
zIndex: 10
});
trafficLayer.setMap(map);
var isVisible = true;
function toggle() {
if (isVisible) {
trafficLayer.hide();
isVisible = false;
} else {
trafficLayer.show();
isVisible = true;
}
}