Search code examples
leafletmapsreact-leaflet

How check if marker is within viewport in Leaflet, given center and zoom level?


Is it possible to check whether a point is within viewport using Leaflet?

I have center of viewport and zoom level. Is it possible to calculate boundaries having only those values?


Solution

  • I have center of viewport and zoom level. Is it possible to calculate boundaries having those values?

    No.

    One needs the size of the map (e.g. in pixels) in order to calculate the visible bounds of the map viewport.

    Think about the edge cases: a map 0 pixels high and 0 pixels wide will never contain a marker within its bounds, whereas a map of infinite size on an infinitely large screen will always contain any marker.