Add feature to pick a new location by clicking on the map.

This commit is contained in:
David Molineus
2018-02-12 16:51:24 +01:00
parent 572b58edeb
commit 178520dd6f
5 changed files with 53 additions and 5 deletions

View File

@@ -124,6 +124,9 @@ var LeafletGeocodeWidget = L.Class.extend({
modalTitle: 'Choose coordinates',
searchPositionLabel: 'Search',
applyPositionLabel: 'Apply',
confirmPositionLabel: 'Set as new position',
okLabel: 'Ok',
cancelLabel: 'Cancel',
radius: null,
picker: LeafletGeocodeMarkerPicker,
map: {
@@ -194,6 +197,38 @@ var LeafletGeocodeWidget = L.Class.extend({
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
map.on('click', function (event) {
var marker = new L.marker(event.latlng).addTo(map);
var container = document.createElement('div');
var okButton = document.createElement('button');
var cancelButton = document.createElement('button');
okButton.set('class', 'leaflet-geocode-btn').appendHTML(this.options.okLabel);
okButton.addEvent('click', function (event) {
event.stop();
this.picker.show(marker.getLatLng());
map.removeLayer(marker);
}.bind(this));
cancelButton.set('class', 'leaflet-geocode-btn').appendHTML(this.options.cancelLabel);
cancelButton.addEvent('click', function (event) {
map.removeLayer(marker);
});
container.appendHTML('<h2>' + this.options.confirmPositionLabel + '</h2>');
container.appendChild(okButton);
container.appendChild(cancelButton);
marker.bindPopup (container, {
keepInView: true,
autoPanPaddingTopLeft: this.options.bboxPadding,
autoClose: false,
closeOnClick: false,
closeButton: false
}).openPopup();
}.bind(this));
var geoCoder = L.Control.geocoder({
defaultMarkGeocode: false,
collapsed: false,