如何使用必应地图防止相同地理位置处的图钉重叠?

4
如果在同一地理位置上有两个标记,如“伦敦”,是否有API可以将它们分开,使它们都可见?
我只能找到旧的地图点API的文档,其中有PreventIconCollisions,这就是我想要的,但在新的API中没有找到任何相关参考。
我正在使用JavaScript API。
2个回答

0

0

所以如果我理解正确,您在同一位置上具有类似的信息,是吗?

为了同时显示这两个信息,您将有两个选择:

  1. 使用适当的方法合并文本框中的信息,以呈现此 UI 元素内部的信息(例如,使用自己的选项卡式信息框)
  2. 当您处于特定缩放级别时,手动取消点聚类

没有默认属性可设置,对于许多推销员进行此操作会非常混乱。但是,在主要思路方面,您需要执行以下操作:检测 viewchangeend 事件,如果您处于特定的缩放级别(或更高缩放级别),则会取消它们的聚类(我称其为取消附近的推销员聚类)。

// Bind pushpin mouseover.
    Microsoft.Maps.Events.addHandler(pin, 'mouseover', function (e) {
        var currentPin = e.target;
        currentPin.setOptions({ visible: false });
        var currentLocation = currentPin.getLocation().clone();

        var currentPoint = bmGlobals.geo.map.tryLocationToPixel(currentLocation);
        if (currentPin.associatedCluster.length == 2) {
            // Display the first pushpin
            var pinA = createPin(currentPin.associatedCluster[0]);
            var locA = bmGlobals.geo.map.tryPixelToLocation(new Microsoft.Maps.Point(currentPoint.x - pinA.getWidth(), currentPoint.y));
            pinA.setLocation(locA);
            bmGlobals.geo.layerClusteredPin.push(pinA);

            // Display the second pushpin
            var pinB = createPin(currentPin.associatedCluster[1]);
            var locB = bmGlobals.geo.map.tryPixelToLocation(new Microsoft.Maps.Point(currentPoint.x + pinB.getWidth(), currentPoint.y));
            pinB.setLocation(locB);
            bmGlobals.geo.layerClusteredPin.push(pinB);
        }
    });

我会尝试编写一个关于Bing地图的模块,但实际上,您需要获取聚合的推针(或具有两个关联数据对象的自定义推针),然后根据客户端的渲染设置它们的位置。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接