【问题标题】:Bing map clustering必应地图聚类
【发布时间】:2018-12-24 16:56:24
【问题描述】:

我正在尝试在 Javascript 中使用 bing 地图标记聚类。在场景中,我从数据库中获取大量数据,每次调用 10000 条数据,然后通过发送 lat lng 数组来在谷歌地图上渲染该集合到标记簇。我的数据集由 100000 个网点组成。我一次获取 10000 个网点,这被调用了 10 次,因此 10 个集群根据缩放级别转换为一个或两个集群。

问题是只有在加载整个数据后才会显示集群。我希望它同时保持更新地图有没有办法做到这一点?

代码:

function initializeMap(zoom)
{
    var mapDiv = document.getElementById('newmap');
    map = new Microsoft.Maps.Map('#newmap', {
        credentials: '',
        zoom:zoom
    });
     infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
        visible: false
    });
    infobox.setMap(map);
}
function addMarker1(mapData,outletname,outletData,colordata)
{

    if(clusterLayer)
    {
       clusterLayer.clear();
    }
    Microsoft.Maps.loadModule("Microsoft.Maps.Clustering", function ()
    {

            var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(mapData[i].lat, mapData[i].lng),
              {
                  icon: svgTemplate,
                  color: strokeColor,
                  text: '1',

              }
            );
            pin.metadata =
            {
              title: i,
              description: title
            };
            Microsoft.Maps.Events.addHandler(pin, 'click', pushpinClicked);
            pin.metedata = mapData[i];
            new_arr.push(pin);
        }
        clusterLayer = new Microsoft.Maps.ClusterLayer(new_arr,
        {
            clusteredPinCallback: createCustomClusteredPin,
        });
        map.layers.insert(clusterLayer);
    });

}

//this is being called as per data limit set
// new_arr is a global array which gets updated everytime with new data
addMarker1(j,outletname,outletData,colordata);

【问题讨论】:

    标签: dictionary bing-maps markerclusterer


    【解决方案1】:

    您每次都在创建一个新的集群层,这不是必需的。一旦你创建了一个 clusterLayer,在接收到新数据时,你可以调用

    clusterLayer.setPushpins(new_arr);
    

    更新集群。

    来源:https://msdn.microsoft.com/en-us/library/mt712808.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-04
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多