forked from Snck3rs/contao-leaflet-maps
Close #34: Make marker draggable.
This commit is contained in:
@@ -10,15 +10,16 @@
|
|||||||
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <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']; ?>'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
geocoder.markGeocode = function(result) {
|
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;
|
||||||
|
|
||||||
link.set('style', 'margin-left: 10px;');
|
link.set('style', 'margin-left: 10px;');
|
||||||
link.appendText('<?php echo $GLOBALS['TL_LANG']['leaflet']['applyPosition']; ?>');
|
link.appendText('<?php echo $GLOBALS['TL_LANG']['leaflet']['applyPosition']; ?>');
|
||||||
@@ -41,16 +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();
|
||||||
|
|
||||||
return this;
|
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; ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user