sha*_*bda 1 javascript gis openstreetmap leaflet
我有一个lat长对列表.(或者我可以创建GeoJSON).我想在传单地图上映射它们.
如何找到我应该设置的中心和缩放级别,以便显示所有点.
所有的传单示例似乎都使用固定的中心和缩放,但我接受用户输入,所以我需要计算它们.
最简单的方法是使用LatLngBounds对象.然后,您可以使用地图fitBounds.或者如果您愿意,可以手动获取其中心.
var myPoints = [[1,1],[2,2] /*, ...*/ ];
var myBounds = new L.LatLngBounds(myPoints);
myMap.fitBounds(myBounds); //Centers and zooms the map around the bounds
Run Code Online (Sandbox Code Playgroud)
如果您愿意,甚至可以放弃实例化bounds对象:
myMap.fitBounds([[1,1],[2,2] /*, ...*/ ]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7008 次 |
| 最近记录: |