MediaWiki:Common.js: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
Line 2: | Line 2: | ||
var element = document.getElementById('map'); | var element = document.getElementById('map'); | ||
if (element && element.hasAttribute('data-src')) { | if (element && element.hasAttribute('data-src')) { | ||
displayMap(element.getAttribute('data-src')); | displayMap(element.getAttribute('data-src')); | ||
} else { | } else { | ||
element.style.display = 'none'; | element.style.display = 'none'; | ||
} | } | ||
function displayMap(coordinates) { | function displayMap(coordinates) { | ||
function initMap() { | function initMap() { | ||
var coordinatesArray = coordinates.split(/[;,]/).map(function(coord) { | var coordinatesArray = coordinates.split(/[;,]/).map(function(coord) { |
Revision as of 20:48, 19 February 2024
/* Any JavaScript here will be loaded for all users on every page load. */ var element = document.getElementById('map'); if (element && element.hasAttribute('data-src')) { displayMap(element.getAttribute('data-src')); } else { element.style.display = 'none'; } function displayMap(coordinates) { 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); }