loleaflet: enabled mouse selection in viewing mode

Mouse selection is enabled by by calling
map.enableSelection() which disables dragging and selection
can be disabled to re-enable dragging by calling
map.disableSelection()
The above only work for 'view' and 'readonly' mode
This commit is contained in:
Mihai Varga 2015-07-13 15:50:02 +03:00
parent df0224964e
commit 0d41a804eb
4 changed files with 30 additions and 17 deletions

View file

@ -228,6 +228,13 @@ var deps = {
desc: 'Switches edit, view and readOnly modes'
},
ControlSelection: {
src: ['control/Control.js',
'control/Control.Selection.js'],
heading: 'Controls',
desc: 'Enables selection in view mode'
},
ControlButtons: {
src: ['control/Control.js',
'control/Control.Buttons.js'],

View file

@ -71,6 +71,7 @@
map.addControl(L.control.buttons());
map.addControl(L.control.search());
map.addControl(L.control.permissionSwitch());
map.addControl(L.control.selection());
map.addControl(L.control.zoom());
map.addControl(L.control.parts());
map.addControl(L.control.statusIndicator());

View file

@ -18,6 +18,24 @@ L.Map.include({
L.DomUtil.removeClass(this._container, className);
}
this.fire('updatepermission', {perm : perm});
},
enableSelection: function () {
if (this._docLayer._permission === 'edit') {
return;
}
var className = 'leaflet-editmode';
this.dragging.disable();
L.DomUtil.addClass(this._container, className);
},
disableSelection: function () {
if (this._docLayer._permission === 'edit') {
return;
}
var className = 'leaflet-editmode';
this.dragging.enable();
L.DomUtil.removeClass(this._container, className);
}
});

View file

@ -738,10 +738,6 @@ L.TileLayer = L.GridLayer.extend({
return;
}
if (this._permission === 'readonly') {
return;
}
if (e.type === 'mousedown') {
this._mouseDown = true;
if (this._holdMouseEvent) {
@ -754,7 +750,7 @@ L.TileLayer = L.GridLayer.extend({
}
else if (e.type === 'mouseup') {
this._mouseDown = false;
if (this._permission !== 'edit') {
if (this._map.dragging.enabled()) {
if (this._mouseEventsQueue.length === 0) {
// mouse up after panning
return;
@ -779,7 +775,7 @@ L.TileLayer = L.GridLayer.extend({
if (this._mouseEventsQueue.length > 1) {
// it's a click, fire mousedown
this._mouseEventsQueue[0]();
if (this._permission !== 'edit') {
if (this._permission === 'view') {
this._map.setPermission('edit');
}
}
@ -801,7 +797,7 @@ L.TileLayer = L.GridLayer.extend({
if (this._holdMouseEvent) {
clearTimeout(this._holdMouseEvent);
this._holdMouseEvent = null;
if (this._permission !== 'edit') {
if (this._map.dragging.enabled()) {
// The user just panned the document
this._mouseEventsQueue = [];
return;
@ -813,7 +809,7 @@ L.TileLayer = L.GridLayer.extend({
}
this._mouseEventsQueue = [];
}
if (this._permission === 'edit') {
if (!this._map.dragging.enabled()) {
mousePos = this._latLngToTwips(e.latlng);
this._postMouseEvent('move', mousePos.x, mousePos.y, 1);
if (this._startMarker._icon) {
@ -835,15 +831,6 @@ L.TileLayer = L.GridLayer.extend({
_executeMouseEvents: function () {
this._holdMouseEvent = null;
if (this._mouseEventsQueue.length === 1 && this._permission !== 'edit') {
// long mouse down or a mouseup after panning
this._mouseEventsQueue = [];
return;
}
else if (this._permission !== 'edit') {
// this time we have a mousedown and mouseup
this._map.setPermission('edit');
}
for (var i = 0; i < this._mouseEventsQueue.length; i++) {
this._mouseEventsQueue[i]();
}