gpt4 book ai didi

event-handling - 处理 Bing map 的 onchangeview 事件

转载 作者:行者123 更新时间:2023-12-05 00:05:42 24 4
gpt4 key购买 nike

我正在尝试处理 bing map 的 onchangeview 事件

在 js 初始化方法中,我有以下代码:

map = new Microsoft.Maps.Map(document.getElementById("mapviewer"), {
credentials: bingMapsKey,
center : new Microsoft.Maps.Location(42.3508, -71.0717),
zoom: 12
});
//Microsoft.Maps.Events.addHandler(map, "onchangeview", handleChangeView);
Microsoft.Maps.Events.addHandler(map, "onclick", handleChangeView);
mapviewer.attachEvent("onchangeview", handleChangeView);

我也有这个功能

函数 handleChangeView(e) {

}

这个函数永远不会被调用,我不知道为什么因为处理程序设置正确。

我也不明白以下两行之间的区别以及何时应该以一种或另一种方式附加事件
Microsoft.Maps.Events.addHandler(map, "onclick", handleChangeView);
mapviewer.attachEvent("onchangeview", handleChangeView);

有任何想法吗?

最佳答案

许多事件在 7 中被重命名,我想你要使用“ click ”而不是“onclick”和“ viewchangeend ”而不是“onchangeview”。

根据您的需要,您可能更喜欢事件“ viewchangestart ”、“ viewchange ”或“ targetviewchanged ”。

另外,您绝对应该使用“ Microsoft.Maps.Events.addHandler ”来设置7个监听器,现在所有事件都使用Events对象。

例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0" type="text/javascript" charset="UTF-8"></script>
</head>
<body onload="init()">

<div id="map" style="position: relative; width: 800px; height: 350px;"></div>


<script type="text/javascript">

/**
* Map click event handler.
*/
function onclick(e){
var map = this.target; //reference to the Map object from which it came
//...
var x = e.getX(); // horizontal position of the click
var y = e.getY(); // vertical position of the click
//...
console.log('The map has been clicked');
}

/**
* View change event handler.
*/
function onview(){
var map = this.target; //reference to the Map object from which it came
//...
console.log('The view has changed');
}

/**
* Load the map and setup event listeners
*/
function init(){
var map = new Microsoft.Maps.Map(
document.getElementById("map"),
{
credentials: "YOUR-BING-KEY",
mapTypeId: Microsoft.Maps.MapTypeId.road
}
);
Microsoft.Maps.Events.addHandler(map, "click", onclick);
Microsoft.Maps.Events.addHandler(map, "viewchangeend", onview);
}

</script>


</body>
</html>

事件列表(在页面底部): http://msdn.microsoft.com/en-us/library/gg427609.aspx

关于event-handling - 处理 Bing map 的 onchangeview 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4259129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com