kopia lustrzana https://github.com/FacilMap/facilmap
Disable closeOnClick while mouse is down to open reverse geocode popup
rodzic
b7ce68895f
commit
cf1311160d
|
@ -28,7 +28,7 @@
|
|||
var map = this;
|
||||
|
||||
map.el = el;
|
||||
map.mapEvents = $rootScope.$new(true); /* Event types: longclick, layerchange */
|
||||
map.mapEvents = $rootScope.$new(true); /* Event types: longmousedown, layerchange */
|
||||
map.socket = fmSocket(padId);
|
||||
|
||||
map.layers = { };
|
||||
|
@ -171,11 +171,11 @@
|
|||
if(L.Browser.touch && !L.Browser.pointer) {
|
||||
// Long click will call the contextmenu event
|
||||
map.map.on("contextmenu", function(e) {
|
||||
map.mapEvents.$emit("longclick", e.latlng);
|
||||
map.mapEvents.$emit("longmousedown", e.latlng);
|
||||
}.fmWrapApply(map.mapEvents));
|
||||
} else {
|
||||
fmUtils.onLongClick(map.map, function(e) {
|
||||
map.mapEvents.$emit("longclick", e.latlng);
|
||||
fmUtils.onLongMouseDown(map.map, function(e) {
|
||||
map.mapEvents.$emit("longmousedown", e.latlng);
|
||||
}.fmWrapApply(map.mapEvents));
|
||||
}
|
||||
|
||||
|
|
|
@ -113,14 +113,25 @@
|
|||
clickMarker.clearLayers();
|
||||
});
|
||||
|
||||
map.mapEvents.$on("longclick", function(e, latlng) {
|
||||
map.mapEvents.$on("longmousedown", function(e, latlng) {
|
||||
var mouseUpHasHappened = false;
|
||||
map.map.once("mouseup", function() { setTimeout(function() {
|
||||
mouseUpHasHappened = true;
|
||||
fmUtils.setCloseOnClick(clickMarker, null); // Reset to default
|
||||
}, 0); });
|
||||
|
||||
clickMarker.clearLayers();
|
||||
|
||||
map.socket.emit("find", { query: "geo:" + latlng.lat + "," + latlng.lng + "?z=" + map.map.getZoom(), loadUrls: false }).then(function(results) {
|
||||
map.socket.emit("find", { query: "geo:" + fmUtils.round(latlng.lat, 5) + "," + fmUtils.round(latlng.lng, 5) + "?z=" + map.map.getZoom(), loadUrls: false }).then(function(results) {
|
||||
clickMarker.clearLayers();
|
||||
|
||||
if(results.length > 0)
|
||||
if(results.length > 0) {
|
||||
renderResult(fmUtils.round(latlng.lat, 5) + "," + fmUtils.round(latlng.lng, 5), results, results[0], true, clickMarker);
|
||||
|
||||
// Prevent closing popup on mouseup because of map.options.closePopupOnClick
|
||||
if(!mouseUpHasHappened)
|
||||
fmUtils.setCloseOnClick(clickMarker, false);
|
||||
}
|
||||
}).catch(function(err) {
|
||||
map.messages.showMessage("danger", err);
|
||||
});
|
||||
|
|
|
@ -404,7 +404,7 @@
|
|||
};
|
||||
};
|
||||
|
||||
fmUtils.onLongClick = function(map, callback) {
|
||||
fmUtils.onLongMouseDown = function(map, callback) {
|
||||
var mouseDownTimeout, pos;
|
||||
|
||||
function clear() {
|
||||
|
@ -640,6 +640,29 @@
|
|||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables or disables the "closeOnClick" option for a Leaflet popup (normally, this option cannot be changed
|
||||
* dynamically).
|
||||
* @param layer {L.Layer} The popup layer or a layer or layer group that has popup(s)
|
||||
* @param enable {Boolean} true/false: Whether to enable or disable, null: reset to default value
|
||||
*/
|
||||
fmUtils.setCloseOnClick = function(layer, enable) {
|
||||
if(layer.eachLayer)
|
||||
return layer.eachLayer(function(layer) { fmUtils.setCloseOnClick(layer, enable); });
|
||||
|
||||
if(layer instanceof L.Popup) {
|
||||
if(enable == null)
|
||||
enable = ('closeOnClick' in layer.options ? layer.options.closeOnClick : layer._map.options.closePopupOnClick);
|
||||
|
||||
if(enable)
|
||||
layer._map.on("preclick", layer._close, layer);
|
||||
else
|
||||
layer._map.off("preclick", layer._close, layer);
|
||||
} else if(layer.getPopup())
|
||||
fmUtils.setCloseOnClick(layer.getPopup(), enable);
|
||||
|
||||
};
|
||||
|
||||
return fmUtils;
|
||||
});
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue