Make marker draggable.

This commit is contained in:
David Molineus
2016-10-05 08:39:28 +02:00
parent 0e10a3d7c4
commit f4a54cdec3

View File

@@ -10,6 +10,7 @@
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map); }).addTo(map);
var element = $('<?php echo $this->field; ?>');
var geocoder = L.Control.geocoder({ var geocoder = L.Control.geocoder({
collapsed: false, collapsed: false,
placeholder: '<?php echo $GLOBALS['TL_LANG']['leaflet']['searchPosition']; ?>' placeholder: '<?php echo $GLOBALS['TL_LANG']['leaflet']['searchPosition']; ?>'
@@ -18,7 +19,6 @@
geocoder.on('markgeocode', function(event) { geocoder.on('markgeocode', function(event) {
var container = document.createElement('div'); var container = document.createElement('div');
var link = document.createElement('button'); var link = document.createElement('button');
var element = $('<?php echo $this->field; ?>');
var result = event.geocode; var result = event.geocode;
link.set('style', 'margin-left: 10px;'); link.set('style', 'margin-left: 10px;');
@@ -42,14 +42,22 @@
this._geocodeMarker = new L.Marker(result.center) this._geocodeMarker = new L.Marker(result.center)
.bindPopup(container, { .bindPopup(container, {
keepInView: true, keepInView: true,
draggable: true,
autoPanPaddingTopLeft: [0, 70] autoPanPaddingTopLeft: [0, 70]
}) })
.addTo(map) .addTo(map)
.openPopup(); .openPopup();
this._geocodeMarker.on('dragend', function (event) {
element.set('value', event.target._latlng.lat + ',' + event.target._latlng.lng);
});
}); });
<?php if ($this->marker): ?> <?php if ($this->marker): ?>
geocoder._geocodeMarker = L.marker(<?php echo $this->marker; ?>).addTo(map); geocoder._geocodeMarker = L.marker(<?php echo $this->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.setZoom(16);
map.panTo(<?php echo $this->marker; ?>); map.panTo(<?php echo $this->marker; ?>);
<?php endif; ?> <?php endif; ?>