MediaWiki:Common.js: Difference between revisions

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




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


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


if (element && element.hasAttribute('data-src')) {
    var marker = new google.maps.Marker({
    displayMap(element.getAttribute('data-src'));
        position: { lat: coordinates[0], lng: coordinates[1] },
} else {
        map: map,
    element.style.display = 'none';
        title: 'Marker Title'
    });
}
}


function displayMap(coordinates) {
// Include the Google Maps JavaScript API script with your API key
    function initMap() {
var script = document.createElement('script');
        var coordinatesArray = coordinates.split(/[;,]/).map(function(coord) {
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
            return parseFloat(coord.trim());
script.async = true;
        });
script.defer = true;
 
document.head.appendChild(script);
        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'
        });
    }
 
    // Load the Google Maps API script after defining initMap
    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:50, 19 February 2024

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


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

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

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

// 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);