From 0040cc4f4720efbe6dd50c77394b9af6fe16342b Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 2 Aug 2022 18:09:34 -0700 Subject: [PATCH] clean up js --- templates/map.html | 36 +++++++++++++++++++----------------- templates/photo.html | 13 ------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/templates/map.html b/templates/map.html index 0d24ba5..29a7810 100644 --- a/templates/map.html +++ b/templates/map.html @@ -25,7 +25,7 @@ var initial_pos = [parseFloat(hash[0]), parseFloat(hash[1])]; var initial_zoom = parseInt(hash[2]); } else { - var initial_pos = points[0].coord; + var initial_pos = points.length == 0 ? [0, 0] : points[0].coord; var initial_zoom = 5; } @@ -35,10 +35,23 @@ attributionControl: false }).setView(initial_pos, initial_zoom); + for(var i=0;i' + + '' + + '' + + '' + points[i].date + ''); + } + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {}).addTo(map); + // when resolving_hash is > 0 we ignore the map's moveend events as to avoid pushing state during a pop var resolving_hash = 0; + // last_hash is used to avoid pushing duplicate states (e.g. zoom/panning an amount that is rounded out) var last_hash = window.location.hash; + // we set a dynamic title by prepending the coordinates onto the original html title var base_title = document.getElementsByTagName("title")[0].text var updateTitle = function() { @@ -68,27 +81,11 @@ updateTitle(); } - map.on('moveend', updateState); - - for(var i=0;i' + - '' + - '' + - '' + points[i].date + ''); - } - - updateState(); - updateTitle(); - addEventListener('popstate', function(state) { var state = state.state; if (!state) { return; } - console.log("pop") resolving_hash += 1; map.setView(state.pos, state.zoom); setTimeout( @@ -98,6 +95,11 @@ 500 ) }); + + map.on('moveend', updateState); + + updateState(); + updateTitle(); {% endblock %} diff --git a/templates/photo.html b/templates/photo.html index bd2fca1..94691e2 100644 --- a/templates/photo.html +++ b/templates/photo.html @@ -42,19 +42,6 @@ }).addTo(map); L.marker(position).addTo(map); - - var refreshResults = function() { - var southWest = map.getBounds().getSouthWest(); - var northEast = map.getBounds().getNorthEast(); - var northWest = map.getBounds().getNorthWest(); - var southEast = map.getBounds().getSouthEast(); - console.log(southWest, northEast, northWest, southEast) - } - - map.on('moveend', refreshResults); - - refreshResults(); -
{{ image.lat }}, {{ image.lon }}