我有一个经纬度对的列表。 (或者我可以创建 GeoJSON)。我想将它们全部映射到传单 map 上。
如何找到应该设置为中心和缩放级别的内容,以便显示所有点。
所有传单示例似乎都使用固定的中心和缩放,但我正在接受用户输入,所以我需要计算它们。
最佳答案
最简单的方法是使用 LatLngBounds
目的。然后你可以得到 map fitBounds .或获取其中心manually如果你更喜欢。
var myPoints = [[1,1],[2,2] /*, ...*/ ];
var myBounds = new L.LatLngBounds(myPoints);
myMap.fitBounds(myBounds); //Centers and zooms the map around the bounds
如果您愿意,您甚至可以放弃实例化边界对象:
myMap.fitBounds([[1,1],[2,2] /*, ...*/ ]);
关于javascript - 给定经纬对列表,在传单中查找中心和缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18146070/