How can I change the location center of a map using Leaflet API?

前端 未结 4 1763
礼貌的吻别
礼貌的吻别 2021-02-04 21:11

My map (Mapbox) takes up the whole background of the site so the center is in the middle of the site. But the focus of the map for the user is on the right side because I have

4条回答
  •  梦谈多话
    2021-02-04 21:51

    First you will need to know the lat and long of the point on the map you want to center on. Then it is simple, just call Map.map.setView passing in your coordinates and zoom level. Api reference: http://leafletjs.com/reference.html#map-set-methods

    If you don't know your coordinates then you can find it by trial and error, just create a marker and add it to the map.

提交回复
热议问题