I have a table with geo location results in which the user can click to set that location in the map. The map is already loaded, and the user might have paned/scolled, and all those locations might be out of sight.
So when the user clicks the button for a location in the table, I need to check if that marker is already visible in the map. And only if invisible, call to setView
and zoom into that location; otherwise, I just change the color of the marker (no pan, no zoom).
Has leaflet any API to check if a layer/marker is currenlty been rendered in the map?
Probably map.getBounds().contains(myMarker.getLatLng())
References:
map.getBounds()
Returns the LatLngBounds of the current map view.myLatLngBounds.contains()
Returns true
if the rectangle contains the given point.marker.getLatLng()
Returns the current geographical position of the marker.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With