omarMTJ
(Omar Mtj)
1
I’m selecting a polygon on the map and then trying to save the coordinates in ‘selectedPolygon’, but for some reason only the latitude comes back correctly meanwhile the longitude is shifted by -360.
`const map = L.map("map", {
center: [33.89, 35.49],
zoom: 13,
});
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 18,
}).addTo(map);
const drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
const drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems,
},
draw: {
polyline: false,
rectangle: true,
circle: false,
circlemarker: false,
marker: false,
polygon: {
allowIntersection: false,
},
},
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (event) {
const layer = event.layer;
drawnItems.addLayer(layer);
console.log("Layer: ", layer);
console.log("Layer to GeoJSON: ", layer.toGeoJSON());
console.log("Selected polygon before: ", selectedPolygon);
selectedPolygon = layer.toGeoJSON();
console.log("Selected polygon after: ", selectedPolygon);
throw new Error("Blocking error");
});`
example:(extracted from logging the ‘layer’ variable)
- 0: v {lat: 33.804192150212806, lng: -324.36422664524537}
- 1: v {lat: 33.8021256694165, lng: -324.3684384739984}
- 2: v {lat: 33.804548434961795, lng: -324.3701575877752}
I’ve done countless runs and it always came back correctly until now.
Does anyone know why this could be happening?