Maps Bing地图V8信息框可见不工作
例如。默认情况下,infobox为false,但第一次不显示它Maps Bing地图V8信息框可见不工作,maps,bing-maps,Maps,Bing Maps,例如。默认情况下,infobox为false,但第一次不显示它 <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <script type='text/javascript' src='http://www.b
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type='text/javascript'
src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
<script type="text/javascript">
var map, clusterLayer, infobox;
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {
credentials: 'Bing Map Key'
});
//Add an infobox to the map.
infobox = new Microsoft.Maps.Infobox(map.getCenter(), { visible: false });
infobox.setMap(map);
Microsoft.Maps.loadModule("Microsoft.Maps.Clustering", function () {
//Create a clustering layer
clusterLayer = new Microsoft.Maps.ClusterLayer(createCustomPushpins(100), {
clusteredPinCallback: createCustomClusterPushpins,
callback: createPushpinList
});
map.layers.insert(clusterLayer);
});
}
function createCustomPushpins(size) {
//Generate random pushpins within the map bounds.
var pins = Microsoft.Maps.TestDataGenerator.getPushpins(size, map.getBounds());
for (var i = 0; i < size; i++) {
//Create a title for each pushpin.
pins[i].setOptions({ title: 'Pushpin #' + i });
//Add handler for the pushpin click event.
Microsoft.Maps.Events.addHandler(pins[i], 'click', pushpinClicked);
}
return pins;
}
function createCustomClusterPushpins(cluster) {
//Create a title for the cluster.
cluster.setOptions({
title: 'Cluster of ' + cluster.containedPushpins.length + ' pins'
});
//Add handler for the cluster click event.
Microsoft.Maps.Events.addHandler(cluster, 'click', pushpinClicked);
}
function pushpinClicked(e) {
//Show an infobox when a pushpin is clicked.
showInfobox(e.target);
}
function createPushpinList() {
//Create a list of displayed pushpins each time clustering layer updates.
if (clusterLayer != null) {
infobox.setOptions({ visible: false });
//Get all pushpins that are currently displayed.
var data = clusterLayer.getDisplayedPushpins();
var output = [];
//Create a list of links for each pushpin that opens up the infobox for it.
for (var i = 0; i < data.length; i++) {
output.push("<a href='javascript:void(0);' onclick='showInfoboxByGridKey(", data[i].gridKey, ");'>");
output.push(data[i].getTitle(), "</a><br/>");
}
document.getElementById('listOfPins').innerHTML = output.join('');
}
}
function showInfoboxByGridKey(gridKey) {
//Look up the cluster or pushpin by gridKey.
var clusterPin = clusterLayer.getClusterPushpinByGridKey(gridKey);
//Show an infobox for the cluster or pushpin.
showInfobox(clusterPin);
}
function showInfobox(pin) {
var description = [];
//Check to see if the pushpin is a cluster.
if (pin.containedPushpins) {
//Create a list of all pushpins that are in the cluster.
description.push('<div style="max-height:75px;overflow-y:auto;"><ul>');
for (var i = 0; i < pin.containedPushpins.length; i++) {
description.push('<li>', pin.containedPushpins[i].getTitle(), '</li>');
}
description.push('</ul></div>');
}
//Display an infobox for the pushpin.
infobox.setOptions({
title: pin.getTitle(),
location: pin.getLocation(),
description: description.join(''),
visible: true
});
}
</script>
</head>
<body>
<div id="myMap" style="position:relative; width:600px; height:400px;"></div>
<br />
<div id="listOfPins" style="max-height:250px;width:250px;overflow-y:scroll;"></div>
</body>
</html>
变量映射、聚类层、信息框;
函数GetMap(){
map=new Microsoft.Maps.map(“#myMap”{
凭据:“Bing地图密钥”
});
//将信息框添加到地图。
infobox=new Microsoft.Maps.infobox(map.getCenter(),{visible:false});
infobox.setMap(map);
Microsoft.Maps.loadModule(“Microsoft.Maps.Clustering”,函数(){
//创建一个集群层
clusterLayer=新的Microsoft.Maps.clusterLayer(createCustomPushpins(100){
ClusteredPincCallback:createCustomClusterPushpins,
回调:createPushpinList
});
map.layers.insert(clusterLayer);
});
}
功能createCustomPushpins(尺寸){
//在贴图边界内生成随机图钉。
var pins=Microsoft.Maps.TestDataGenerator.getPushpins(大小,map.getBounds());
对于(变量i=0;i ”);
}
document.getElementById('listOfPins')。innerHTML=output.join(“”);
}
}
函数showInfoboxByGridKey(gridKey){
//通过网格键查找簇或图钉。
var clusterPin=clusterLayer.getClusterPushpinByGridKey(gridKey);
//显示群集或图钉的信息框。
showInfobox(clusterPin);
}
功能显示信息框(pin){
var description=[];
//检查图钉是否为簇。
if(包含销的推杆){
//创建群集中所有图钉的列表。
说明.推送(“”);
对于(变量i=0;i”,pin.containedPushpins[i].getTitle(),“”);
}
说明.推送(“
”);
}
//显示图钉的信息框。
infobox.setOptions({
标题:pin.getTitle(),
位置:pin.getLocation(),
description:description.join(“”),
可见:正确
});
}
根据官方文档,在实例化infobox对象时,我们必须传递visible false(infobox=new Microsoft.Maps.infobox(map.getCenter(),{visible:false});)有什么建议我哪里出错了吗?奇怪,刚刚尝试了IE11、Edge、Chrome和Firefox中提供的代码。它在除Chrome以外的所有浏览器中都能正常工作。不知道为什么Chrome的表现不同。我会让团队调查这件事。感谢您的报告。是否有任何事件可以识别无法挖掘的群集,因为多个图钉处于相同的纬度和长度创建群集图钉时,请检查缩放级别。如果地图已完全放大,则您正在创建的群集图钉将无法拆分,因为您已完全放大。@rbrundritt对此有何解决办法?由于假期旺季,Bing地图平台在12月份处于代码冻结状态。我们的大多数客户也处于代码冻结状态,因此我们无法在本月推出任何更新。该团队目前也在处理一些大型任务。计划在一月份对此进行调查。好消息是,这一问题现已在实验部门得到解决。此修复将在发布分支的下一次更新中进行,该更新可能在2月份进行。