1

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?

Robin
  • 218
  • 3
  • 15
  • Did you have any luck with please? I am looking to do something similar – Aenaon Sep 23 '19 at 05: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 '19 at 07:39
  • ah ok, thanks. You followed BritishSteel's comments or you found an other way around it please? – Aenaon Sep 23 '19 at 07: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 '19 at 08:34

1 Answers1

2

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.

BritishSteel
  • 6,637
  • 4
  • 38
  • 64
  • 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 '16 at 08: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 :-) – BritishSteel Apr 26 '16 at 08:37
  • You mean getting the POI data into the db or getting the POI data from the db to the map? – Robin Apr 26 '16 at 08: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. – BritishSteel Apr 26 '16 at 08:51
  • Getting the data into the db is actually the easy part in my opinion. You can download the osm.pbf and extract the POIs you are looking for using this nice tool https://github.com/MorbZ/OsmPoisPbf. Afterwards you have csv data that you need to load to a DB, which should be straight forward. For me getting the data to leaflet seems the hard part :). As server-side I would probably use dropwizard. Or maybe setup the PostGis DB to communicate directly with leaflet. Not sure if that is possible. – Robin Apr 26 '16 at 09:07
  • 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. – BritishSteel Apr 26 '16 at 09:13