[GIS] Leaflet – Load markers in the current map – dynamically

geoserverleafletmarkerspoint-of-interest

I am looking for a marker plugin for leaflet that allows loading of markers dynamically, according to the current view.

E.g. I want to add OSM POIs to a world-wide map. Obviously loading all at once would be too much. Therefore, I'd only load markers on smaller areas when zoomed in. Is there a plugin that supports this functionality?

I know there is one for the overpass-api (https://github.com/kartenkarsten/leaflet-layer-overpass), but I do not want to spam the Overpass Api. Also the response is to slow for a customer facing application (IMHO). Additionally, I do not want to only map OSM POIs.

I thought about setting up my own DataBase and changing the leaflet-layer-overpass plugin to work with that, but that seems to be a lot of work. Is there maybe a pre-existing solution to the problem?

Best Answer

Building your own solution might actually not be as hard as you think.

All you would have to do is register a moveend event and then call getBounds() or getBoundsZoom() (in case the zoom level is important). Then you send this extent to your database and query all the points that fall within it. Of course you need a database that understands geospatial data. PostgreSQL/PostGIS would be an excellent option as you can see here.