MediaWiki:Common.js: Difference between revisions
No edit summary Tag: Manual revert |
No edit summary |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
function initMap() { | function initMap() { | ||
var element = document.getElementById('map'); | var element = document.getElementById('map'); | ||
var | var dataSrc = element.getAttribute('data-src'); | ||
if (dataSrc) { | |||
var coordinates = dataSrc.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' | |||
}); | |||
} | |||
} | } | ||
var script = document.createElement('script'); | var script = document.createElement('script'); | ||
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap'; | script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap'; |
Revision as of 22:56, 19 February 2024
/* Any JavaScript here will be loaded for all users on every page load. */ function initMap() { var element = document.getElementById('map'); var dataSrc = element.getAttribute('data-src'); if (dataSrc) { var coordinates = dataSrc.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' }); } } 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);