Bing Maps SpatialMath 模块与具有相同坐标的多个图钉的交点不准确

Bing Maps SpatialMath Module Intersection is not accurate with Multiple pins with same coordinates

我发现了一个问题,虽然我在地图上有数千个图钉,但我正在使用绘图工具徒手绘制形状,然后在 "drawingEnded" 事件上执行交点,虽然我可以看到交点应该return 比实际多 returns,

我错过了什么吗?例如,如果在绘制的新区域下有大约 500 个引脚,交集方法仅 returns 100 或更多,

我的蜘蛛集群配置: ` Microsoft.Maps.loadModule(['SpiderClusterManager'], 函数 () {

            spiderManager = new SpiderClusterManager(map, pinssame, {

                //clusteredPinCallback: function (cluster) {
                //    //Customize clustered pushpin.
                //    cluster.setOptions({
                //        color: 'red',
                //        icon:'https://www.bingmapsportal.com/Content/images/poi_custom.png'
                //    });
                //},
                pinSelected: function (pin, cluster) {
                    if (cluster) {
                        showInfobox(cluster.getLocation(), pin);
                    } else {
                        showInfobox(pin.getLocation(), pin);
                    }
                },
                pinUnselected: function () {
                    hideInfobox();
                },
                gridSize: 80

            });
        });

`

"drawingEnded"事件后触发的路口功能代码: ` 函数 findIntersectingData(searchArea) { //确保搜索区域是一个有效的多边形,它的环中应该有 4 个位置,因为它会自动关闭。 if (searchArea && searchArea.getLocations().length >= 4) {

            //Get all the pushpins from the pinLayer.
            //var pins = spiderManager._data;

            //Using spatial math find all pushpins that intersect with the drawn search area.
            //The returned data is a copy of the intersecting data and not a reference to the original shapes, 
            //so making edits to them will not cause any updates on the map.
            var intersectingPins = Microsoft.Maps.SpatialMath.Geometry.intersection(pins, searchArea);
            //The data returned by the intersection function can be null, a single shape, or an array of shapes. 
            if (intersectingPins) {
                //For ease of usem wrap individudal shapes in an array.
                if (intersectingPins && !(intersectingPins instanceof Array)) {
                    intersectingPins = [intersectingPins];
                }
                var selectedPins = [];
                //Loop through and map the intersecting pushpins back to their original pushpins by comparing their coordinates.
                for (var j = 0; j < intersectingPins.length; j++) {
                    for (var i = 0; i < pins.length; i++) {
                        if (Microsoft.Maps.Location.areEqual(pins[i].getLocation(), intersectingPins[j].getLocation())) {
                            selectedPins.push(pins[i]);
                            break;
                        }
                    }
                }
                //Return the pushpins that were selected.
                console.log(selectedPins);
                return selectedPins;
            }
        }
        return null;
    }

`

该功能未 return 获取准确的引脚数据, 我在这里遗漏了什么吗?

感谢任何帮助,

感谢和问候, 肖希尔塞西亚

更新:

刚想,这是一个假设,我在图层上有多个具有相同坐标的图钉,这是否是 return 只有图钉在地图上与不同坐标相交的原因?,

感谢和问候, 肖希尔塞西亚

方法 returns 表示交叉点的对象,而不是输入形状的精确副本。所以是的,如果区域内有多个具有相同坐标的图钉,则结果中只会出现该坐标的一个图钉,因为仅此一个就足以作为表示。

您可以试试下面的示例,只返回一个图钉:

// Creates a polygon of current map bounds
var polygon = new Microsoft.Maps.SpatialMath.locationRectToPolygon(map.getBounds());

// Creates a bunch of the pushpins of the same coordinates(map center)
var pushpin1 = new Microsoft.Maps.Pushpin(map.getCenter());
var pushpin2 = new Microsoft.Maps.Pushpin(map.getCenter());
var pushpin3 = new Microsoft.Maps.Pushpin(map.getCenter());
var pushpin4 = new Microsoft.Maps.Pushpin(map.getCenter());
var pushpin5 = new Microsoft.Maps.Pushpin(map.getCenter());

// Adds the shapes to map for some visualization
map.entities.push([polygon, pushpin1, pushpin2, pushpin3, pushpin4, pushpin5]);

// Only one pushpin is returned as result
var intersectingPin = Microsoft.Maps.SpatialMath.Geometry.intersection([pushpin1, pushpin2, pushpin3, pushpin4, pushpin5], polygon);

考虑到重复的 pin 时,您是否检查过结果数量是否相加?

我得到了一个解决方案,因为交叉点 API 忽略多个 pushPins 相同的坐标 ,因此还有另一个 API 命名为 contains,它有两个参数,即形状和图钉,以及它 returns 是否包含在该形状中或不以布尔形式。如果图钉是那种形状,则为真,否则为假。

        function findIntersectingData(searchArea) {
        //Ensure that the search area is a valid polygon, should have 4 Locations in it's ring as it automatically closes.
        if (searchArea && searchArea.getLocations().length >= 4) {
            var selectedPins = [];
            for (var i = 0; i < pins.length; i++) {
                if (Microsoft.Maps.SpatialMath.Geometry.contains(searchArea, pins[i])) {
                    selectedPins.push(pins[i]);
                }
            }
            //Return the pushpins that were selected.
            console.log(selectedPins);
            //return updatePrescriberTerr(selectedPins);
            return selectedPins;
        }
        return null;
    }

因此在上面的函数中,我们可以从 pushPins 数组循环它,并根据布尔值相应地形成交集。

希望对有类似情况的朋友有所帮助!

此致,

Shohil Sethia