您正在使用底图上的事件,因此我建议将事件绑定到图钉本身,以避免不必要地调用此特定事件。
但是,如果您想更新您的代码,这里有一个真正有效的完整示例,因为当鼠标悬停在基本地图上时,“手”是 Bing 地图中的默认元素,请参见代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bing Maps Cursor</title>
<script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
function getMap() {
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById('map'), {
credentials: "YOURKEY",
center: new Microsoft.Maps.Location(47.5, 2.75),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road
});
var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(47.5, 2.75));
map.entities.push(pin);
Microsoft.Maps.Events.addHandler(map, 'mousemove', function(event) {
if(event.targetType === 'pushpin') {
map.getRootElement().style.cursor = 'pointer';
} else {
map.getRootElement().style.cursor = 'url("' + Microsoft.Maps.Globals.cursorPath + 'grab.cur"), move';
}
});
}
</script>
</head>
<body onload="getMap();">
<div id="map" style="position: relative; width: 800px; height: 600px;">
</div>
</body>
</html>
如果您想要基于图钉事件的推荐方法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bing Maps Cursor</title>
<script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
var cursorStyle = null;
function getMap() {
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById('map'), {
credentials: "YOURKEY",
center: new Microsoft.Maps.Location(47.5, 2.75),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road
});
var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(47.5, 2.75));
map.entities.push(pin);
Microsoft.Maps.Events.addHandler(pin, 'mouseover', changeCursor);
Microsoft.Maps.Events.addHandler(pin, 'mouseout', revertCursor);
}
function changeCursor(e) {
map.getRootElement().style.cursor = 'pointer';
}
function revertCursor(e) {
map.getRootElement().style.cursor = 'url("' + Microsoft.Maps.Globals.cursorPath + 'grab.cur"), move';
}
</script>
</head>
<body onload="getMap();">
<div id="map" style="position: relative; width: 800px; height: 600px;">
</div>
</body>
</html>