commit adc07196dc156cf5471269a079bcaa9a390ff2ef
parent 8632d78149a2a71959bbeea67f3a241ab73cb59b
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Tue, 7 Nov 2017 07:48:31 +0300
Revert "[coordinates control] removed Copy item from context menu on control; added showing context menu for left click on map"
This reverts commit 395b0ad564fe7a4bc41f6b67250df6dc1e07c361.
Diffstat:
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/lib/leaflet.control.coordinates/index.js b/src/lib/leaflet.control.coordinates/index.js
@@ -52,6 +52,8 @@ L.Control.Coordinates = L.Control.extend({
}, this
);
this.menu = new Contextmenu([
+ {text: 'Click map to copy coordinates to clipboard', callback: this.prepareForClickOnMap.bind(this)},
+ '-',
{text: '±ddd.ddddd', callback: this.onMenuSelect.bind(this, 'd')},
{text: 'ddd.ddddd°', callback: this.onMenuSelect.bind(this, 'D')},
{text: 'ddd°mm.mmm\'', callback: this.onMenuSelect.bind(this, 'DM')},
@@ -147,16 +149,16 @@ L.Control.Coordinates = L.Control.extend({
L.DomUtil.addClass(this._container, 'expanded');
L.DomUtil.addClass(this._map._container, 'coordinates-control-active');
this._map.on('mousemove', this.onMouseMove, this);
- this._map.on('contextmenu click', this.onMapClick, this);
+ this._map.on('contextmenu', this.onMapRightClick, this);
} else {
L.DomUtil.removeClass(this._container, 'expanded');
L.DomUtil.removeClass(this._map._container, 'coordinates-control-active');
- this._map.off('contextmenu click', this.onMapClick, this);
+ this._map.off('contextmenu', this.onMapRightClick, this);
this._map.off('mousemove', this.onMouseMove, this);
}
},
- onMapClick: function(e) {
+ onMapRightClick: function(e) {
L.DomEvent.stop(e);
const items = [{text: '<b>Copy coordinates to clipboard</b>', header: true}, '-'];
@@ -193,6 +195,17 @@ L.Control.Coordinates = L.Control.extend({
this.menu.show(e);
},
+ onMapClick: function(e) {
+ var s = this.formatCoodinate(e.latlng.lat, true) + ' ' + this.formatCoodinate(e.latlng.lng, false);
+ s = s.replace(/°/g, '°');
+ copyToClipboard(s, e.originalEvent);
+ },
+
+ prepareForClickOnMap: function() {
+ this._map.once('click', this.onMapClick, this);
+ }
+
+
// TODO: onRemove