From fcc26a7fa573569a20fbbabaf768ae53ff29bfa6 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 14 Jun 2020 12:02:32 +0200 Subject: Add mouse coordinate display to bottom left --- htdocs/mapscript.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index 3eccb65..a27ee10 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -606,6 +606,31 @@ L.GotoControl = L.MyControl.extend({ mymap.addControl(new L.SearchControl()); mymap.addControl(new L.GotoControl()); +L.CurrentPosControl = L.Control.extend({ + options: { + position : 'bottomleft', + callback: null, + kind: "", + html: '' + }, + onAdd: function (map) { + container = L.DomUtil.create('div', 'leaflet-control-scale leaflet-bar'); + container.style.visibility = "hidden"; + div = L.DomUtil.create('div', '', container); + div.style.backgroundColor = "white"; + div.style.paddingLeft = "4px"; + div.style.paddingRight = "4px"; + div.style.borderRadius = "2px"; + div.style.margin = "2px"; + div.style.opacity = "0.6"; + div.style.fontWeight = "bold"; + div.innerHTML = ""; + div.id = "current_position_label"; + return container; + } +}); +mymap.addControl(new L.CurrentPosControl()); + var popup = L.popup(); L.AwesomeMarkers.Icon.prototype.options.prefix = 'fa'; @@ -687,6 +712,17 @@ function update_outline_visibility() { }); } +function update_current_mouse_position(e) { + var lbl = document.getElementById('current_position_label'); + if (e.type == "mouseout") { + lbl.parentElement.style.visibility = "hidden"; + return; + } + lbl.parentElement.style.visibility = "visible"; + pos = resolve_latlng(e.latlng); + lbl.innerHTML = pos.lng + "," + pos.lat; +} + mymap.on('zoomend', function () {is_user_drag = 1; update_hash_from_position();}); mymap.on('zoomend', update_aa_status); mymap.on('zoomend', update_street_width); @@ -695,6 +731,8 @@ 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;}); mymap.on('overlayadd', function (e) { update_street_width(); update_outline_visibility(); }); +mymap.on('mousemove', update_current_mouse_position); +mymap.on('mouseout', update_current_mouse_position); function onHashChange(e, hash=null) { if (!hash) -- cgit v1.2.3