From ca1284d364fc9bfe91844699a9aafcc1320e94ed Mon Sep 17 00:00:00 2001 From: Aleksandr Elmekeev Date: Sat, 26 Oct 2024 21:05:54 +0100 Subject: [PATCH 1/2] Fix map loading --- js/map.js | 11 ++++++++--- map/index.html | 16 +++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/js/map.js b/js/map.js index a381b1b..5de783a 100644 --- a/js/map.js +++ b/js/map.js @@ -74,12 +74,15 @@ function setZoom(map, year) { } } -function initMap() { +async function initMap() { const url = new URL(window.location.href) const year = url.searchParams.get('year') const points = data.points - map = new google.maps.Map(document.getElementById('map'), { + const { Map } = await google.maps.importLibrary("maps"); + const {AdvancedMarkerElement} = await google.maps.importLibrary("marker") + + map = new Map(document.getElementById('map'), { clickableIcons: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, @@ -110,7 +113,7 @@ function initMap() { yearMarker.className = 'year-marker' yearMarker.textContent = title - const marker = new google.maps.marker.AdvancedMarkerElement({ + const marker = new AdvancedMarkerElement({ position: points[year].latlng, map: year.length == 4 ? map : null, // hide replacement initially title, @@ -135,3 +138,5 @@ function initMap() { } } } + +initMap() \ No newline at end of file diff --git a/map/index.html b/map/index.html index d5904ed..7a3a1f1 100644 --- a/map/index.html +++ b/map/index.html @@ -23,11 +23,17 @@ mainScript.async = false; document.head.appendChild(mainScript); - const mapScript = document.createElement('script'); - mapScript.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyCoiKEmUCSlurpp6Qs5aCLt1O5x4WnKWKw&callback=initMap&v=weekly&libraries=marker' - mapScript.defer = false; - mapScript.async = false; - document.head.appendChild(mapScript); + // const mapScript = document.createElement('script'); + // mapScript.src = 'https://maps.googleapis.com/maps/api/js?key=&callback=initMap&v=weekly&libraries=marker' + // mapScript.defer = false; + // mapScript.async = false; + // document.head.appendChild(mapScript); + + From 0714b92a66e7959b2d9b445d317d4114ddef31f0 Mon Sep 17 00:00:00 2001 From: Aleksandr Elmekeev Date: Sat, 26 Oct 2024 21:08:56 +0100 Subject: [PATCH 2/2] Remove commented code --- map/index.html | 6 ------ 1 file changed, 6 deletions(-) diff --git a/map/index.html b/map/index.html index 7a3a1f1..2d6c589 100644 --- a/map/index.html +++ b/map/index.html @@ -22,12 +22,6 @@ mainScript.defer = false; mainScript.async = false; document.head.appendChild(mainScript); - - // const mapScript = document.createElement('script'); - // mapScript.src = 'https://maps.googleapis.com/maps/api/js?key=&callback=initMap&v=weekly&libraries=marker' - // mapScript.defer = false; - // mapScript.async = false; - // document.head.appendChild(mapScript);