summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Koch <markus@notsyncing.net>2020-04-19 10:45:26 +0200
committerMarkus Koch <markus@notsyncing.net>2020-04-19 10:45:26 +0200
commit255e81ce9f0c333827f1a2977a0ece8a83cc3071 (patch)
tree787a2e0f0a4ea3b1644d783c4a03067f8e35f460
parent1a2f9908fac4917abdb54ef0c52dcf702a140ba2 (diff)
Improve location history
Before, script initiated moves would mess with the history through hash updates partway through the move. This commit fixes this behavior by checking for a human source.
-rw-r--r--htdocs/mapscript.js28
-rw-r--r--htdocs/streeteditor.js2
2 files changed, 22 insertions, 8 deletions
diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js
index 4bdec93..89d32a9 100644
--- a/htdocs/mapscript.js
+++ b/htdocs/mapscript.js
@@ -183,12 +183,14 @@ function get_current_location_str() {
function jump_to(latlng, zoom = -1) {
if (zoom == -1)
zoom = mymap.getZoom();
- document.location.hash = "#" + Math.round(latlng.lat) + "," + Math.round(latlng.lng) + "," + zoom;
+ if (!editor_mode)
+ document.location.hash = "#" + Math.round(latlng.lat) + "," + Math.round(latlng.lng) + "," + zoom;
+ else
+ mymap.setView(latlng, zoom);
}
function jump_to_marker(e) {
- if (!editor_mode)
- jump_to(e.target.getLatLng());
+ jump_to(e.target.getLatLng());
}
function prompt_location() {
@@ -244,11 +246,25 @@ function onMapClick(e) {
mymap.on('click', onMapClick);
+var is_user_drag = 0;
+
function update_hash_from_position(e) {
- document.location.hash = "#" + get_current_location_str();
+ if (is_user_drag)
+ is_user_drag = 0;
+ else
+ return;
+ if (!editor_mode)
+ document.location.hash = "#" + get_current_location_str();
}
-mymap.on('zoomend', update_hash_from_position);
-mymap.on('dragend', update_hash_from_position);
+
+function dragstart(e) {
+ is_user_drag = 1;
+}
+
+mymap.on('zoomend', function () {is_user_drag = 1; update_hash_from_position();});
+mymap.on('moveend', update_hash_from_position);
+mymap.on('dragstart', function () { is_user_drag = 1;});
+mymap.on('keydown', function (e) { if (e.originalEvent.code.match(/Arrow.*/)) is_user_drag = 1;});
function onHashChange(e) {
if (document.location.hash == "#" + get_current_location_str())
diff --git a/htdocs/streeteditor.js b/htdocs/streeteditor.js
index 27addb5..a5e9e17 100644
--- a/htdocs/streeteditor.js
+++ b/htdocs/streeteditor.js
@@ -78,8 +78,6 @@ if (editor_mode) {
document.getElementById('mapid').classList.add("no-aa");
mymap.setMaxZoom(14);
mymap.off('click', onMapClick);
- mymap.off('zoomend', update_hash_from_position);
- mymap.off('dragend', update_hash_from_position);
onLoad();
function get_location_string() {