From f9e8c72508cedfa78ed69bd714d7b7bc5edbd387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Deckert?= Date: Mon, 9 Nov 2015 10:01:20 +0100 Subject: [PATCH 1/2] map: add coordinates picker --- lib/map.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ scss/_map.scss | 4 ++++ 2 files changed, 69 insertions(+) diff --git a/lib/map.js b/lib/map.js index bcab1a8..d2aaf4a 100644 --- a/lib/map.js +++ b/lib/map.js @@ -68,6 +68,46 @@ define(["map/clientlayer", "map/labelslayer", } }) + var CoordsPickerButton = L.Control.extend({ + options: { + position: "bottomright" + }, + + active: false, + button: undefined, + + initialize: function (f, options) { + L.Util.setOptions(this, options) + this.f = f + }, + + onAdd: function () { + var button = L.DomUtil.create("button", "coord-picker") + button.textContent = "" + + L.DomEvent.disableClickPropagation(button) + L.DomEvent.addListener(button, "click", this.onClick, this) + + this.button = button + + return button + }, + + update: function() { + this.button.classList.toggle("active", this.active) + }, + + set: function(v) { + this.active = v + this.update() + }, + + onClick: function () { + this.f(!this.active) + } + + }) + function mkMarker(dict, iconFunc, router) { return function (d) { var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d)) @@ -152,6 +192,13 @@ define(["map/clientlayer", "map/labelslayer", }) } + var showCoordsPickerButton = new CoordsPickerButton(function (d) { + if (d) + enableCoords() + else + disableCoords() + }) + function saveView() { savedView = {center: map.getCenter(), zoom: map.getZoom()} @@ -171,6 +218,23 @@ define(["map/clientlayer", "map/labelslayer", locateUserButton.set(false) } + function enableCoords() { + map.getContainer().classList.add("pick-coordinates") + map.on("click", showCoordinates) + showCoordsPickerButton.set(true) + } + + function disableCoords() { + map.getContainer().classList.remove("pick-coordinates") + map.off("click", showCoordinates) + showCoordsPickerButton.set(false) + } + + function showCoordinates(e) { + window.prompt("Koordinaten (Lat, Lng)", e.latlng.lat.toFixed(6) + ", " + e.latlng.lng.toFixed(6)) + disableCoords() + } + function locationFound(e) { if (!userLocation) userLocation = new LocationMarker(e.latlng).addTo(map) @@ -228,6 +292,7 @@ define(["map/clientlayer", "map/labelslayer", map.on("dragend", saveView) addButton(locateUserButton) + addButton(showCoordsPickerButton) addButton(new AddLayerButton(function () { /*eslint no-alert:0*/ diff --git a/scss/_map.scss b/scss/_map.scss index f0b340c..bc3a919 100644 --- a/scss/_map.scss +++ b/scss/_map.scss @@ -2,6 +2,10 @@ paint-order: stroke; } +.pick-coordinates { + cursor: crosshair; +} + .map { width: 100%; height: 100%; From 6fbc531c17e6228f82cca5a033931fe5dcde38dc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 30 Dec 2015 08:21:46 +0100 Subject: [PATCH 2/2] map: fix coord picker on first click --- lib/map.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/map.js b/lib/map.js index d2aaf4a..ea40998 100644 --- a/lib/map.js +++ b/lib/map.js @@ -85,7 +85,8 @@ define(["map/clientlayer", "map/labelslayer", var button = L.DomUtil.create("button", "coord-picker") button.textContent = "" - L.DomEvent.disableClickPropagation(button) + // Click propagation isn't disabled as this causes problems with the + // location picking mode; instead propagation is stopped in onClick(). L.DomEvent.addListener(button, "click", this.onClick, this) this.button = button @@ -102,7 +103,8 @@ define(["map/clientlayer", "map/labelslayer", this.update() }, - onClick: function () { + onClick: function (e) { + L.DomEvent.stopPropagation(e) this.f(!this.active) }