Created
January 19, 2024 10:54
-
-
Save LuisSevillano/f4531e72181d3641cfc4dbb2a726fc54 to your computer and use it in GitHub Desktop.
Gell all polygons from a rendered Leaflet map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// chrome snippet | |
var layersMarkers = []; | |
var layersPolygons = []; | |
var layers = [] | |
var geojson = { | |
"type": "FeatureCollection", | |
"features": [] | |
} | |
var output = { | |
"type": "FeatureCollection", | |
"features": [] | |
} | |
map.eachLayer(function(layer) { | |
layers.push(layer); | |
if (layer instanceof L.Marker) | |
layersMarkers.push(layer); | |
if (layer instanceof L.Polygon) | |
layersMarkers.push(layer); | |
if (typeof layer.toGeoJSON === 'function') | |
geojson.features.push(layer.toGeoJSON()); | |
}); | |
output.features = (geojson.features.filter(d=>d.geometry?.type === 'Polygon' && d.geometry?.coordinates[0][0])) | |
copy(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment