Ho can I invert a GeoJson of a country, so that it defines the country as a hole in the polygon of the worldmap? I need this to create a mask of the GeoJson VectorLayer in OpenLayers 5.3.
In the coordinates array add this array as the the first coordinates and it'll do the invert
[
[
0,
90
],
[
180,
90
],
[
180,
-90
],
[
0,
-90
],
[
-180,
-90
],
[
-180,
0
],
[
-180,
90
],
[
0,
90
]
],
And you can find examples to exactly what you want to do here https://github.com/minaalfy/city-map
Here a code snippet for leaflet + GeoJson, to add a world rectangle to the coordinates. That will cut out/invert/reverse the polygon in geoJson.
geoJson.geometry.coordinates[0].unshift([[180, -90], [180, 90], [-180, 90], [-180, -90]]);
L.geoJSON(geoJson, { style: { color: '#ccc', weight: 2, fillOpacity: 0.5 } }).addTo(map);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With