diff --git a/web_assets/overviewer.js b/web_assets/overviewer.js index eea2f7d..8b3cd97 100644 --- a/web_assets/overviewer.js +++ b/web_assets/overviewer.js @@ -225,13 +225,23 @@ var overviewer = { overviewer.collections.mapTypes[i].name, overviewer.collections.mapTypes[i]); } - + + /* // Make the link again whenever the map changes google.maps.event.addListener(overviewer.map, 'maptypeid_changed', function() { $('#'+overviewerConfig.CONST.mapDivId).css( 'background-color', overviewer.util.getMapTypeBackgroundColor( overviewer.map.getMapTypeId())); }); + */ + + // Add live hash update listener + google.maps.event.addListener(overviewer.map, 'dragend', function() { overviewer.updateHash(); }); + google.maps.event.addListener(overviewer.map, 'zoom_changed', function() { overviewer.updateHash(); }); + // Jump to the hash if given + overviewer.initHash(); + + // We can now set the map to use the 'coordinate' map type overviewer.map.setMapTypeId(overviewer.util.getDefaultMapTypeId()); }, @@ -858,6 +868,22 @@ var overviewer = { this.tileSize = tileSize; } }, + 'initHash': function() { + if(window.location.hash.split("/").length > 1) { + overviewer.goToHash(); + } + }, + 'setHash': function(lat, lng, zoom) { + window.location.replace("#/" + lat + "/" + lng + "/" + zoom); + }, + 'updateHash': function() { + overviewer.setHash(overviewer.map.getCenter().lat(), overviewer.map.getCenter().lng(), overviewer.map.getZoom()); + }, + 'goToHash': function() { + coords = window.location.hash.split("/"); + overviewer.map.setCenter(coords[1], coords[2]); + overviewer.map.setZoom(coords[3]); + }, /** * Stuff that we give to the google maps code instead of using ourselves * goes in here.