diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js index d656c7a3d..7f22db12d 100644 --- a/loleaflet/build/deps.js +++ b/loleaflet/build/deps.js @@ -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'], diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html index bb0020390..446bb004c 100644 --- a/loleaflet/debug/document/document_simple_example.html +++ b/loleaflet/debug/document/document_simple_example.html @@ -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()); diff --git a/loleaflet/src/control/Permission.js b/loleaflet/src/control/Permission.js index 6933f6430..f48d2e43d 100644 --- a/loleaflet/src/control/Permission.js +++ b/loleaflet/src/control/Permission.js @@ -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); } }); diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index fb69720ce..8c88a360b 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -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](); }