I have a large GeoJSON file (now it is about 22MB with 4K polygons but it is going to contains about 10k polygons)

I load the file in Leaflet using L.GeoJSON.AJAX, on each feature I attach two handlers (click and contexmenu) and the puropose of the map si to select polygon read and edit some properties and save the selected polygon as project in a MySQL database.

When I load the map after loading the base polygons from the large file I load every saved project from MySQL database.

For now all works fine and It's quite fast but the GeoJSON file is going to grow so my question is: there is a better way to load the base polygon?

It will be faster If I store the base GeoJSON in the MySQL database?

  • 2
    Two general options: reduce payload on the server side (direct DB link, tiling, WMTS/WFS), or have the client do the job. The first option requires a setup to query data only for the current map view, or use a proxy map server, and will use constant API calls. The second option is easier to implement, but requires larger payloads. Mapbox GL has a genius high performance on-the-fly vector tiling module included, written by the Leaflet creator; it's available as a standalone library and should be able to handle your data on the client effortlessly.
    – geozelot
    Nov 21, 2019 at 11:58
  • 1
    ^ I misunderstood the question: at least the second option doesn't help much with the actual download time or file size, but it makes the handling of large GeoJSONs a lot better. The server side is where you want to improve on (as suggested above) if loading times is your concern; saving the file itself to DB will likely have the opposite effect, but storing geometries in a spatial DB is likely the way to go. TopoJSON might be sth. to look into, if your polygons tend to share topology.
    – geozelot
    Nov 21, 2019 at 12:07
  • And if I use geojson-vt to load base polygon can I attach the handlers to each polygons?
    – Cenere Blu
    Nov 21, 2019 at 12:14
  • 2
    The tiled features should keep their attributes, so it's a matter of Leaflets ability to work with Mapbox Vector Tiles (it's kinda not supposed to, so there may be problems with the general integration you need to tackle by self-implementation); there seems to be a plugin here which uses the geojson-vt library already.
    – geozelot
    Nov 21, 2019 at 12:25
  • However I have to load geojson data from my file.. In your opinion is faster load data from static file.geojson with L.GeoJSON.AJAX or from mysql database using L.geoJSON in Leaflet? (in mysql the same file is stored in a blob field)
    – Cenere Blu
    Nov 21, 2019 at 17:31


Your Answer

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

Browse other questions tagged or ask your own question.