gpt4 book ai didi

javascript - 我怎样才能为 map 上的所有形状设置边界?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:59:20 25 4
gpt4 key购买 nike

map 上有很多形状,它们都保存在这个数组array_shapes_object[]中。如何通过 fitBounds 方法在 map 上显示所有这些?

我可以使用类似的东西:

map.fitBounds(circle.getBounds());

map.fitBounds(rectangle.getBounds());

var points = new google.maps.LatLng(arrayLatitude[aa], arrayLongitude[aa]);
bounds.extend(points);
map.fitBounds(bounds);

但它们都只适用于一种形状,而且不会超过一种。似乎只有三种形状。 (圆形、矩形、多边形)。

当我点击一个运行函数的按钮时,我想在 map 上调整所有形状。

最佳答案

您需要创建一个 google.maps.LatLngBounds对象,它是您要显示的所有对象的边界的并集。

union(other:LatLngBounds) | LatLngBounds | Extends this bounds to contain the union of this and the given bounds.

伪代码(需要把所有你想在 map 上显示的形状的bounds都加进去):

var bounds = circle.getBounds();
bounds.union(rectangle.getBounds();
for (var aa=0; aa < arrayLatitude.length; aa++) {
var points = new google.maps.LatLng(arrayLatitude[aa], arrayLongitude[aa]);
bounds.extend(points);
}
map.fitBounds(bounds);

关于javascript - 我怎样才能为 map 上的所有形状设置边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19887218/

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