|
|
| വരി 3: |
വരി 3: |
|
| |
|
| document.addEventListener("DOMContentLoaded", function () { | | document.addEventListener("DOMContentLoaded", function () { |
| // Function to replace the marker URL | | // Find all images in the leaflet-marker-pane class and replace their src |
| function replaceMarkerIcons() {
| | const images = document.querySelectorAll('.leaflet-marker-pane img'); |
| // Select all img elements in the leaflet-marker-pane
| | images.forEach(function (img) { |
| const markerIcons = document.querySelectorAll('.leaflet-marker-pane img');
| | img.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png"; |
| 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.");
| |
| }
| |
| }); | | }); |
|
| |
|