How to change the map center in Leaflet.js

后端 未结 4 1187
无人及你
无人及你 2020-12-23 00:34

The following code initializes a leaflet map. The initialize function centers the map based on user location. How do I change the center of the map to a new position after c

4条回答
  •  一向
    一向 (楼主)
    2020-12-23 00:56

    You could also use:

    var latLon = L.latLng(40.737, -73.923);
    var bounds = latLon.toBounds(500); // 500 = metres
    map.panTo(latLon).fitBounds(bounds);
    

    This will set the view level to fit the bounds in the map leaflet.

提交回复
热议问题