gpt4 book ai didi

azure - 如何在群集单击事件上缩放 Azure Maps 边界框?

转载 作者:行者123 更新时间:2023-12-02 08:02:19 25 4
gpt4 key购买 nike

Azure Maps 中的数据源可以聚集特定半径内的点要素(图钉)。当此类群集上发生单击事件时,我想将边界框重置为群集所代表的区域,并放大以显示群集内的各个引脚。

使用 Google map ,您可以将集群的默认行为设置为点击时自动缩放。此功能在旧版 Bing Maps API 中也相对容易实现。 。如何在不使用大量 JavaScript 的情况下在 Azure Maps 中添加此功能?

最佳答案

确实,Azure Maps 似乎不直接支持它,可以考虑以下方法:

一旦我们点击图层,事件就会返回目标对象的像素位置以及其他属性。然后通过atlas.Map.pixelsToPositions函数确定簇圆的minmax坐标:

const coordinates = e.map.pixelsToPositions([
[e.pixel[0] + (clusterRadius*2), e.pixel[1] + (clusterRadius*2)],
[e.pixel[0] - (clusterRadius*2), e.pixel[1] - (clusterRadius*2)],
]);

然后,通过 atlas.data.BoundingBox.fromPositions function 确定簇气泡内可能包含引脚的区域边界。 :

const bounds = atlas.data.BoundingBox.fromPositions(coordinates);

最后设置 map 视口(viewport):

 map.setCamera({
bounds: bounds,
padding:0
});

这里是a demo供您引用

关于azure - 如何在群集单击事件上缩放 Azure Maps 边界框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53268908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com