javascript - 在 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" />
<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=de-de" type="text/javascript" charset="UTF-8"></script>
</head>
<body onload="init()">
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=AhrgxvPMzaWNe4oDZqelNzT-SoWigBK7H8cSBqZ2jLXpq4O9IcQ1YktvHhqT7_8F' async defer></script> "
<div id="map" style="position: relative; width: 800px; height: 300px;"></div>
<script type="text/javascript">
function init(){
// Initialize the map
var map = new Microsoft.Maps.Map(
document.getElementById("map"),
{
credentials: "My Bing Maps API Key",
mapTypeId: Microsoft.Maps.MapTypeId.road
}
);
var infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
visible: false
});
infobox.setMap(map);
// Create a collection to store multiple pins
var pins = new Microsoft.Maps.EntityCollection();
// Create pins
for (var i = 0; i < 5; i++){
var position = new Microsoft.Maps.Location(53 + i, -1);
// Creates a Pushpin
var pin = new Microsoft.Maps.Pushpin(position, {title: 'pin' + i} );
pin.metadata = {
title: 'Pin ' + i,
description: 'Description for pin ' + i
};
Microsoft.Maps.Events.addHandler(pin, 'click', pushpinClicked);
// Adds the pin to the collection instead of adding it directly to the Map
pins.push(pin);
}
// Adds all pins at once
map.entities.push(pins);
}
function pushpinClicked(e) {
//Make sure the infobox has metadata to display.
if (e.target.metadata) {
//Set the infobox options with the metadata of the pushpin.
infobox.setOptions({
location: e.target.getLocation(),
title: e.target.metadata.title,
description: e.target.metadata.description,
visible: true
});
}
}
</script>
</body>
</html>
解决方案
您在脚本标记中引用 Bing Maps V7。该版本在几年前已被弃用。它在幕后重定向到 v8,但这不是 100% 向后兼容,可能会导致问题。这是在 V8 上运行的相同示例:https ://bingmapsv8samples.azurewebsites.net/#Infobox_MultiplePushpins
推荐阅读
- python - 从文件而不是完整文件导入特定类是否重要?
- oracle-adf - 如何在按钮单击时从片段重定向到另一个 .jsf 页面
- jquery - jQuery 验证动态创建的 reCaptcha 表单
- python-3.x - 导入错误:python 中没有名为 pyimgur 的模块
- python - 如何从熊猫的给定行中删除仅包含零的列
- amazon-web-services - 数组中的突变响应我想在 AppSync 控制台的订阅中显示突变数组响应
- typescript - Typescript Angular中带有索引的最后状态数组
- angular - 垫表可扩展行 Angular 7
- python - 正则表达式 findall python
- java - 如何在 RecyclerView 中选择多个项目并将它们放入 List