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?

  • Did you have any luck with please? I am looking to do something similar
    – Aenaon
    Sep 23, 2019 at 5:57
  • I set up my own DB and created a custom leaflet plugin that connects to the DB and fetches the required POIs.
    – Robin
    Sep 23, 2019 at 7:39
  • ah ok, thanks. You followed BritishSteel's comments or you found an other way around it please?
    – Aenaon
    Sep 23, 2019 at 7:51
  • I did follow the answer more or less. Essentially I build my own solution as proposed. I used a PostGIS DB and some custom Leaflet code.
    – Robin
    Sep 24, 2019 at 8:34

1 Answer 1


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.

  • Thanks for your comment. You have a really good point. I was hoping that there might be a pre-existing solution. Building it my-self would be possible though.
    – Robin
    Apr 26, 2016 at 8:23
  • 1
    The hardest thing might just be getting the data and keeping it up to date. Other than that it should be pretty simple :-) Apr 26, 2016 at 8:37
  • You mean getting the POI data into the db or getting the POI data from the db to the map?
    – Robin
    Apr 26, 2016 at 8:42
  • More getting into the DB. If you are using worldwide data then it might be hard to get all of that data. Or does Overpass let you download all the data of one type at once for the entire world? Not sure about that... Getting the data from the DB into the map will not be a problem as long as you know a server-side language that can talk to the DB and receive requests from your application. PHP would be a good choice as you do not need to install any additional modules. But there are plenty of other languages that could be used as well. Apr 26, 2016 at 8:51
  • 1
    You are right! I was thinking of Overpass Turbo, where you cannot download such masses of data, I think. Cool link, I will have a look at it! You can install PostGIS and you can send the data to your web application but to do this you need an intermediate language that can handle this, as you cannot use JavaScript to directly communicate with the DB. Apr 26, 2016 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.