Skip to content

Instantly share code, notes, and snippets.

@nedSaf
Last active March 19, 2022 21:18
Show Gist options
  • Save nedSaf/9c19cb8662eb4ddc3cd8 to your computer and use it in GitHub Desktop.
Save nedSaf/9c19cb8662eb4ddc3cd8 to your computer and use it in GitHub Desktop.
Get center of a layer (GeoJson) in leaflet map.
// Assuming you are inside an event (Mouseover, Click).
// Layer comes from the event.
// Get the bounds of the layer to display the popup on the north-east bounds.
var bounds = layer.getBounds();
var latLng = bounds.getCenter();
@ohoroyoi
Copy link

waht do you mean $scope?

@pshassett
Copy link

I found this useful, thanks.

@nedSaf
Copy link
Author

nedSaf commented Sep 23, 2019

@pshassett I'm glad.

@ohoroyoi Sorry, I missed this, if I remember correctly, this scope was something to do with Angular, it should be just any variable.
I'll change it.

@rullymartanto
Copy link

thanks,..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment