The issue is this one:
I successfully could implmement a MultiPolygon Layer in Leaflet, but I'm getting an error while trying to convert it to a GeoJSON object.
My code is this one:
let colecccionPoligonos=[];
const multiPolygonOptions = {color:'red', weight:2, fillOpacity: 0.5};
function swapCoords(coords){
for (const val of coords[0]){
const aux=val[0];
val[0]=val[1];
val[1]=aux;
}
return coords;
}
function anadirPoligono(poligono){
colecccionPoligonos.push([[swapCoords(poligono.geometry.coordinates)]]);
if(multipolygon){
map.removeLayer(multipolygon);
}
multipolygon=L.polygon(colecccionPoligonos,multiPolygonOptions);
console.log(multipolygon);
map.addLayer(multipolygon);
console.log(colecccionPoligonos);
console.log(multipolygon.toGeoJSON(8));
}
I've implemented the 'swapCoords' since I'm recieving a GeoJSON whose lat/lng values are in inverted order.
The result I'm getting is this one, with the layer added, the structure of the array passed to L.polygon, and the error shown at the image:
The details of the error are:
GeoJSON.js:272 Uncaught TypeError: Cannot read properties of null (reading 'alt')
at Mi (GeoJSON.js:272:16)
at zi (GeoJSON.js:288:4)
at zi (GeoJSON.js:287:4)
at zi (GeoJSON.js:287:4)
at e.toGeoJSON (GeoJSON.js:368:16)
at anadirPoligono (busqueda:477:28)
at <anonymous>:1:1
Any idea of what's going wrong? Any more info needed?
Thanks a lot! Leandro