高德地图动态绑定页面的mark标注的信息以及绑定弹窗事件

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>为多个Marker添加事件</title>
<style type="text/css">
html,body{
width:100%;
height:100%;
}
#container{
width:100%;
height:90%;
}
*{
margin:0px;
padding:0px;
}
body, button, input, select, textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
</style>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>

</head>
<body onload="init();">
<div id="container"></div>
<p>给三个标注绑定点击事件,当点击标注时,会弹出标注的序号信息。</p>
</body>
<script>
function init() {
var center = new qq.maps.LatLng(39.916527,116.397128);
var map = new qq.maps.Map(document.getElementById("container"), {
center: center,
zoom: 13
});
var infoWin = new qq.maps.InfoWindow({
map: map
});
var latlngs = [
new qq.maps.LatLng(39.91474,116.37333),
new qq.maps.LatLng(39.91447,116.39336),
new qq.maps.LatLng(39.90884,116.41306)
];

for(var i = 0;i < latlngs.length; i++) {
(function(n){
var marker = new qq.maps.Marker({
position: latlngs[n],
map: map
});
qq.maps.event.addListener(marker, ‘click‘, function() {
infoWin.open();
infoWin.setContent(‘<div style="text-align:center;white-space:‘+
‘nowrap;margin:10px;">这是第 ‘ +
n + ‘ 个标注</div>‘);
infoWin.setPosition(latlngs[n]);
});
})(i);
}
}
</script>
</html>

 

高德地图动态绑定页面的mark标注的信息以及绑定弹窗事件

上一篇:Django——Ajax


下一篇:conda环境配置以及pyinstaller报错配置