Skip to content

Download shapes from leaflet map

I have online access to a leaflet map, but cannot reach the authors. Is there a way to download shapes from this map (to shp, geojson, etc.)?

I thought of running some leaflet-related javascript code in browser console, but I couldn’t find any relevant commands in the documentation.

Answer

When you look into the dev tools of the link you posted, what you’ll find is that the shapes you see there are actually part of a raster tile layer:

enter image description here

Looking into the source code (sources tab), you can see that they’re added with this code:

 L.TileLayer.Codes = L.TileLayer.extend({
        getTileUrl: function(coords) {
            return "http://mapa-kodow-pocztowych.pl/tiles/" + ((coords.x + 10 * coords.y) % 100) + '/' + coords.z + '-' + coords.x + '-' + coords.y + '.png';
        },
        getAttribution: function() {
            return 'Code Map &copy; RoboLabs, <a href ="mailto:admi' + 'n@mapa-kodow-pocztow' + 'ych.pl">email</a>';
        }
  });

Looks like those tiles are being served by the same server that’s serving the webpage. Again in the sources tab:

enter image description here

This means there’s no good way to know where the data from these tiles came from, or trace them back to their original shapefile sources (as far as I can tell). Sorry. You’d have to contact the page author and ask them for their source data.