"മീഡിയവിക്കി:Common.js" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

(ചെ.)No edit summary
(ചെ.)No edit summary
വരി 3: വരി 3:


document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () {
     // Check if L (Leaflet) is loaded
     // Function to replace the marker URL
     if (typeof L !== "undefined" && L.Marker) {
     function replaceMarkerIcons() {
         // Define a custom icon
         // Select all img elements in the leaflet-marker-pane
         const customIcon = L.icon({
         const markerIcons = document.querySelectorAll('.leaflet-marker-pane img');
             iconUrl: "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png",
        markerIcons.forEach(function (img) {
            iconSize: [30, 70], // Size of the icon
             if (img.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) {
             iconAnchor: [15, 35] // Point of the icon which will correspond to the marker's location
                img.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png";
             }
         });
         });
    }


        // Override the default marker icon
    // Initial replacement on page load
        L.Marker.prototype.options.icon = customIcon;
     replaceMarkerIcons();
     } else {
        console.error("Leaflet is not loaded. Make sure the map is initialized properly.");
    }
});


  console.log ("map replace");
    // MutationObserver to catch dynamically added markers
    function replaceMarkerImage(newUrl) {
    const observer = new MutationObserver(function (mutations) {
        // Get all image elements with the target class
        mutations.forEach(function (mutation) {
        const imageElements = document.querySelectorAll('img.leaflet-marker-icon');
            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";
                    }
                }
            });
        });
    });


        // Loop through each image element and update the src
    // Start observing the leaflet container for changes
         imageElements.forEach(image => {
    const mapContainer = document.querySelector('.leaflet-container');
             // Update the image source directly
    if (mapContainer) {
             image.src = newUrl;
         observer.observe(mapContainer, {
             childList: true,
             subtree: true
         });
         });
    } else {
        console.error("Leaflet map container not found.");
     }
     }
 
});
    // Example usage:
    const newImageUrl = 'https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png'; // Replace with the new URL
 
    // Call the function to replace the marker images
    replaceMarkerImage(newImageUrl);
 
 


//Quick Edit Box  
//Quick Edit Box  
"https://schoolwiki.in/മീഡിയവിക്കി:Common.js" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്