MediaWiki:Common.js: Difference between revisions

From Imperial Minerals Wiki
No edit summary
No edit summary
Tag: Reverted
Line 2: Line 2:




function initMap() {
// Assuming your div has an id 'map'
    var element = document.getElementById('map');
var element = document.getElementById('map');
    var coordinates = element.getAttribute('data-src').split(/[;,]/).map(function(coord) {
        return parseFloat(coord.trim());
    });


    var mapOptions = {
// Check if the element has a data-src attribute
        center: { lat: coordinates[0], lng: coordinates[1] },
if (element && element.hasAttribute('data-src')) {
        zoom: 15
    // If data-src exists, proceed to display the map
     };
    displayMap(element.getAttribute('data-src'));
     var map = new google.maps.Map(element, mapOptions);
} else {
     // If data-src doesn't exist, hide the div
     element.style.display = 'none';
}


     var marker = new google.maps.Marker({
function displayMap(coordinates) {
        position: { lat: coordinates[0], lng: coordinates[1] },
    // Your existing initMap and Google Maps API script inclusion code
        map: map,
     function initMap() {
        title: 'Marker Title'
        var coordinatesArray = coordinates.split(/[;,]/).map(function(coord) {
     });
            return parseFloat(coord.trim());
        });
 
        var mapOptions = {
            center: { lat: coordinatesArray[0], lng: coordinatesArray[1] },
            zoom: 15
        };
        var map = new google.maps.Map(element, mapOptions);
 
        var marker = new google.maps.Marker({
            position: { lat: coordinatesArray[0], lng: coordinatesArray[1] },
            map: map,
            title: 'Marker Title'
        });
     }
 
    var script = document.createElement('script');
    script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
    script.async = true;
    script.defer = true;
    document.head.appendChild(script);
}
}
// Include the Google Maps JavaScript API script with your API key
var script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
script.async = true;
script.defer = true;
document.head.appendChild(script);

Revision as of 20:47, 19 February 2024

/* Any JavaScript here will be loaded for all users on every page load. */


// Assuming your div has an id 'map'
var element = document.getElementById('map');

// Check if the element has a data-src attribute
if (element && element.hasAttribute('data-src')) {
    // If data-src exists, proceed to display the map
    displayMap(element.getAttribute('data-src'));
} else {
    // If data-src doesn't exist, hide the div
    element.style.display = 'none';
}

function displayMap(coordinates) {
    // Your existing initMap and Google Maps API script inclusion code
    function initMap() {
        var coordinatesArray = coordinates.split(/[;,]/).map(function(coord) {
            return parseFloat(coord.trim());
        });

        var mapOptions = {
            center: { lat: coordinatesArray[0], lng: coordinatesArray[1] },
            zoom: 15
        };
        var map = new google.maps.Map(element, mapOptions);

        var marker = new google.maps.Marker({
            position: { lat: coordinatesArray[0], lng: coordinatesArray[1] },
            map: map,
            title: 'Marker Title'
        });
    }

    var script = document.createElement('script');
    script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
    script.async = true;
    script.defer = true;
    document.head.appendChild(script);
}