[GIS] Leaflet – out of memory

javascriptleaflet

I created this web map: https://etomanon.github.io/ but whenever I add more than 1 image overlay it starts freezing. It happens on Github and local hosting too. Is my notebook that bad or does it lag for you too? Sometimes Chrome crash totally – out of memory. The largest image has only 2,1 MB. Any idea how to solve it? I do not see any errors in console. Can Leaflet handle more image overlays?

Best Answer

Displaying large images is a memory-heavy operation for web browsers (they are not designed for that, and they choke when applying CSS styling to those images). Specially when the images are several times larger than the screen, and when there are several.

You are making Leaflet load several 7000px x 11000px images. Cut down the size (there are lots of blank areas in those land cover images), or slice them in tiles (to show them as L.TileLayers).