Fix map world wrapping markers
This commit is contained in:
parent
14d108cf36
commit
8179c17e22
@ -874,12 +874,20 @@
|
||||
|
||||
// ==================== MAP INIT ==================
|
||||
function initMap() {
|
||||
map = L.map("map").setView([46.8182, 8.2275], 8);
|
||||
map = L.map("map", {
|
||||
worldCopyJump: true,
|
||||
maxBounds: [
|
||||
[-85, -180],
|
||||
[85, 180],
|
||||
],
|
||||
maxBoundsViscosity: 1.0,
|
||||
}).setView([46.8182, 8.2275], 8);
|
||||
L.tileLayer(
|
||||
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
{
|
||||
attribution:
|
||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
||||
noWrap: true,
|
||||
},
|
||||
).addTo(map);
|
||||
|
||||
@ -894,7 +902,7 @@
|
||||
.getElementById("mode-create")
|
||||
.classList.contains("active")
|
||||
) {
|
||||
createMarker(e.latlng, { title: "New Marker" });
|
||||
createMarker(normalizeLatLng(e.latlng), { title: "New Marker" });
|
||||
}
|
||||
});
|
||||
|
||||
@ -902,7 +910,15 @@
|
||||
}
|
||||
|
||||
// ==================== MARKER FUNCTIONS ==========
|
||||
function normalizeLatLng(latlng) {
|
||||
return L.latLng(
|
||||
latlng.lat,
|
||||
((((latlng.lng + 180) % 360) + 360) % 360) - 180,
|
||||
);
|
||||
}
|
||||
|
||||
function createMarker(latlng, content = {}) {
|
||||
latlng = normalizeLatLng(latlng);
|
||||
const marker = L.marker(latlng, {
|
||||
draggable: true,
|
||||
title: content.title || "Untitled",
|
||||
@ -912,6 +928,10 @@
|
||||
`<strong>${content.title || "Untitled"}</strong>`,
|
||||
);
|
||||
marker.on("click", () => openMarkerEditor(marker));
|
||||
marker.on("dragend", () => {
|
||||
marker.setLatLng(normalizeLatLng(marker.getLatLng()));
|
||||
updateJourneyPath();
|
||||
});
|
||||
|
||||
marker._content = {
|
||||
...content,
|
||||
@ -1111,7 +1131,8 @@
|
||||
).value;
|
||||
|
||||
const markers = currentJourney.markers.map((m) => {
|
||||
const latlng = m.getLatLng();
|
||||
const latlng = normalizeLatLng(m.getLatLng());
|
||||
m.setLatLng(latlng);
|
||||
const content = m._content || {};
|
||||
return {
|
||||
lat: latlng.lat,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user