{
const container = html`<div style="height: 500px;"></div>`;
function fixAntimeridian(coords) {
for (let i = 1; i < coords.length; i++) {
if (Math.abs(coords[i][0] - coords[i-1][0]) > 180) {
if (coords[i][0] < coords[i-1][0]) {
coords[i][0] += 360;
} else {
coords[i-1][0] += 360;
}
}
}
return coords;
}
const correctedGeoJSON = JSON.parse(JSON.stringify(especiasDeAsia3));
correctedGeoJSON.features.forEach(f => {
if (f.geometry.type === "LineString") {
f.geometry.coordinates = fixAntimeridian(f.geometry.coordinates);
} else if (f.geometry.type === "MultiLineString") {
f.geometry.coordinates = f.geometry.coordinates.map(line => fixAntimeridian(line));
}
});
const map = L.map(container);
const layer = L.geoJSON(correctedGeoJSON).addTo(map);
map.fitBounds(layer.getBounds(), { maxZoom: 9 });
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "© <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
}).addTo(map);
return container;
}