简体   繁体   中英

Changing the Center of a leaflet open street map

I'm initializing a map using leaflet(openstreetmaps) in angular and setting a center that the user sees when opening the site. How can i change the center so the map rotates to the new coordinates on click of eg a button? Setting a new center doesn't appear to do anything, neither do i want to reload the site itself. Thanks!

private initMap(): void {

    this.map = L.map('map', {
      center: [48.1841234, 11.5877796],
      zoom: 16
    });}

you can use map.flyTo([latlng]) or map.panTo([latlng])

https://leafletjs.com/reference-1.6.0.html#map-panto

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM