From 5b648427c1c3f490c2b629efee14bc30244b9389 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 5 Oct 2016 08:40:50 +0200 Subject: [PATCH] Close #34: Make marker draggable. --- module/templates/be_leaflet_geocode.html5 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/module/templates/be_leaflet_geocode.html5 b/module/templates/be_leaflet_geocode.html5 index 9b62205..81a262d 100644 --- a/module/templates/be_leaflet_geocode.html5 +++ b/module/templates/be_leaflet_geocode.html5 @@ -10,15 +10,16 @@ L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); + var element = $('field; ?>'); var geocoder = L.Control.geocoder({ collapsed: false, placeholder: '' }).addTo(map); - geocoder.markGeocode = function(result) { + geocoder.on('markgeocode', function(event) { var container = document.createElement('div'); var link = document.createElement('button'); - var element = $('field; ?>'); + var result = event.geocode; link.set('style', 'margin-left: 10px;'); link.appendText(''); @@ -41,16 +42,22 @@ this._geocodeMarker = new L.Marker(result.center) .bindPopup(container, { keepInView: true, + draggable: true, autoPanPaddingTopLeft: [0, 70] }) .addTo(map) .openPopup(); - return this; - }; + this._geocodeMarker.on('dragend', function (event) { + element.set('value', event.target._latlng.lat + ',' + event.target._latlng.lng); + }); + }); marker): ?> - geocoder._geocodeMarker = L.marker(marker; ?>).addTo(map); + geocoder._geocodeMarker = L.marker(marker; ?>, {draggable: true}).addTo(map); + geocoder._geocodeMarker.on('dragend', function (event) { + element.set('value', event.target._latlng.lat + ',' + event.target._latlng.lng); + }); map.setZoom(16); map.panTo(marker; ?>);