我正在尝试检测地图缩放的变化,我尝试使用以下方法:
Microsoft.Maps.Events.addHandler(map, "targetviewchanged", console.log('targetviewchanged'));
Microsoft.Maps.Events.addHandler(map, "viewchangestart", console.log('viewchangestart'));
但仅在地图更改时触发一次
如何仅检测缩放更改?
提前致谢
我正在尝试检测地图缩放的变化,我尝试使用以下方法:
Microsoft.Maps.Events.addHandler(map, "targetviewchanged", console.log('targetviewchanged'));
Microsoft.Maps.Events.addHandler(map, "viewchangestart", console.log('viewchangestart'));
但仅在地图更改时触发一次
如何仅检测缩放更改?
提前致谢
请尝试以下方法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Event view change start</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map, lastZoomLevel = 0;
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'Your Bing Maps Key'});
lastZoomLevel = map.getZoom();
Microsoft.Maps.Events.addHandler(map, 'viewchangeend', viewChanged);
}
function viewChanged(e)
{
if(lastZoomLevel != map.getZoom()){
lastZoomLevel = map.getZoom();
alert("Map Zoomed");
}
}
</script>
</head>
<body onload="getMap();">
<div id='myMap' style="; width:400px; height:400px;"></div>
</body>
</html>