"മീഡിയവിക്കി:Common.js" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
(ചെ.)No edit summary |
(ചെ.)No edit summary |
||
| വരി 3: | വരി 3: | ||
document.addEventListener("DOMContentLoaded", function () { | document.addEventListener("DOMContentLoaded", function () { | ||
// | // Function to replace the marker URL | ||
function replaceMarkerIcons() { | |||
// | // Select all img elements in the leaflet-marker-pane | ||
const | const markerIcons = document.querySelectorAll('.leaflet-marker-pane img'); | ||
markerIcons.forEach(function (img) { | |||
if (img.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) { | |||
img.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png"; | |||
} | |||
}); | }); | ||
} | |||
// Initial replacement on page load | |||
replaceMarkerIcons(); | |||
// MutationObserver to catch dynamically added markers | |||
const observer = new MutationObserver(function (mutations) { | |||
mutations.forEach(function (mutation) { | |||
mutation.addedNodes.forEach(function (node) { | |||
// If a new img is added, check if it matches the target URL | |||
if (node.nodeType === 1 && node.matches && node.matches('.leaflet-marker-pane img')) { | |||
if (node.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) { | |||
node.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png"; | |||
} | |||
} | |||
}); | |||
}); | |||
}); | |||
// Start observing the leaflet container for changes | |||
const mapContainer = document.querySelector('.leaflet-container'); | |||
if (mapContainer) { | |||
observer.observe(mapContainer, { | |||
childList: true, | |||
subtree: true | |||
}); | }); | ||
} else { | |||
console.error("Leaflet map container not found."); | |||
} | } | ||
}); | |||
//Quick Edit Box | //Quick Edit Box | ||