From a21df5fa3e427d00fcc58db23db3368b8a79538e Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Fri, 5 Apr 2024 17:20:38 +0500 Subject: [PATCH 01/15] identification is performed when right-clicking on map --- addon/components/flexberry-map.js | 35 ++++++++++++++++++- addon/components/map-commands/export.js | 33 ++++++++++------- addon/services/maptool-options.js | 13 +++++++ .../components/map-commands/export.hbs | 1 + app/services/maptool-options.js | 1 + 5 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 addon/services/maptool-options.js create mode 100644 app/services/maptool-options.js diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index fea77cb60..f527e6877 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -143,6 +143,7 @@ let FlexberryMapComponent = Ember.Component.extend( */ lat: null, + maptoolOptionsService: Ember.inject.service("maptool-options"), /** Map center longitude. @@ -503,6 +504,10 @@ let FlexberryMapComponent = Ember.Component.extend( // Store map's container as jQuery object. let $leafletContainer = this.$(); + + // Выключаем стандартный обработчик ПКМ для контейнера карты + $leafletContainer.on('contextmenu', (e) => e.preventDefault()) + this.set('_$leafletContainer', $leafletContainer); let options = this.get('options'); @@ -513,7 +518,35 @@ let FlexberryMapComponent = Ember.Component.extend( if (this.get('mainMap')) { leafletMap.mainMap = true; L.DomEvent.on(leafletMap, 'mousedown mouseup mousein mouseout', (e) => { - if (e.originalEvent.button === 1) { + if (e.originalEvent.button === 2) { + + if (!this.get('maptoolOptionsService.identifyOnRightClick')) { + return + } + + if (e.type === 'mousedown') { + this.sendAction('toggleSidebar', { + changed: true, + tabName: 'identify', + prevTab: "" + }); + let editTools = leafletMap.flexberryMap.tools.getEnabled()._editTools + + // Инициируем нажатие ЛКМ + let newMouseDownEvent = new MouseEvent('mousedown'); + editTools.onMousedown({ + latlng: e.latlng, + originalEvent: newMouseDownEvent + }) + } + + if (e.type === 'mouseup') { + leafletMap.flexberryMap.tools.getEnabled()._editTools.stopDrawing() + this.set('prevEnabledTools', null); + leafletMap.flexberryMap.tools.enable('drag'); + } + + }else if (e.originalEvent.button === 1) { if (e.type === 'mousedown') { e.originalEvent.preventDefault(); let enabledTools = { diff --git a/addon/components/map-commands/export.js b/addon/components/map-commands/export.js index 52983df37..5162c4a01 100644 --- a/addon/components/map-commands/export.js +++ b/addon/components/map-commands/export.js @@ -183,6 +183,8 @@ let ExportMapCommandComponent = Ember.Component.extend({ * Compare service. Disable before open map. */ compare: Ember.inject.service(), + + maptoolOptionsService: Ember.inject.service("maptool-options"), /** Shows export dialog. @@ -196,6 +198,8 @@ let ExportMapCommandComponent = Ember.Component.extend({ // Show dialog. this.set('_exportDialogIsVisible', true); + + this.set('maptoolOptionsService.identifyOnRightClick', false) }, actions: { @@ -231,20 +235,23 @@ let ExportMapCommandComponent = Ember.Component.extend({ leafletMap.flexberryMap.commands.execute('export', null, mapCommandExecutionOptions).then(() => { this.set('_exportIsInProgress', false); e.closeDialog = true; - this._hideExportDialog(); + this.send("hideExportDialog"); }); - } - }, - - /** - Hides export dialog. + }, + + /** + Hides export dialog. - @method _hideExportDialog - @private - */ - _hideExportDialog() { - // Hide dialog. - this.set('_exportDialogIsVisible', false); + @method hideExportDialog + @private + */ + hideExportDialog() { + // Hide dialog. + this.set('_exportDialogIsVisible', false); + + console.log('провернули') + this.set('maptoolOptionsService.identifyOnRightClick', true) + }, }, /** @@ -253,7 +260,7 @@ let ExportMapCommandComponent = Ember.Component.extend({ willDestroyElement() { this._super(...arguments); - this._hideExportDialog(); + this.send("hideExportDialog"); }, /** diff --git a/addon/services/maptool-options.js b/addon/services/maptool-options.js new file mode 100644 index 000000000..ffb26216c --- /dev/null +++ b/addon/services/maptool-options.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +export default Ember.Service.extend({ + + /** + Flag: indicates whether identification is performed when right-clicking on map. + + @property identifyOnRightClick + @type Bool + @default false + */ + identifyOnRightClick: false, +}); diff --git a/addon/templates/components/map-commands/export.hbs b/addon/templates/components/map-commands/export.hbs index 6d09802d3..c79e726fd 100644 --- a/addon/templates/components/map-commands/export.hbs +++ b/addon/templates/components/map-commands/export.hbs @@ -21,6 +21,7 @@ defaultMapCaption=defaultMapCaption timeout=timeout approve=(action "onExportDialogApprove") + hide = (action "hideExportDialog") scalesForExport=scalesForExport switchScaleControlMapName=switchScaleControlMapName }} diff --git a/app/services/maptool-options.js b/app/services/maptool-options.js new file mode 100644 index 000000000..bc1fad7ea --- /dev/null +++ b/app/services/maptool-options.js @@ -0,0 +1 @@ +export { default } from 'ember-flexberry-gis/services/maptool-options'; \ No newline at end of file From 8c224054832c0eb0aa23eb57efc1df1675a94e7b Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Fri, 5 Apr 2024 17:48:37 +0500 Subject: [PATCH 02/15] jscs fix --- addon/components/flexberry-map.js | 29 +++++++++--------- addon/components/map-commands/export.js | 30 +++++++------------ .../components/map-commands/export.hbs | 1 - 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index f527e6877..029431515 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -143,7 +143,8 @@ let FlexberryMapComponent = Ember.Component.extend( */ lat: null, - maptoolOptionsService: Ember.inject.service("maptool-options"), + maptoolOptionsService: Ember.inject.service('maptool-options'), + /** Map center longitude. @@ -504,10 +505,10 @@ let FlexberryMapComponent = Ember.Component.extend( // Store map's container as jQuery object. let $leafletContainer = this.$(); - + // Выключаем стандартный обработчик ПКМ для контейнера карты - $leafletContainer.on('contextmenu', (e) => e.preventDefault()) - + $leafletContainer.on('contextmenu', (e) => e.preventDefault()); + this.set('_$leafletContainer', $leafletContainer); let options = this.get('options'); @@ -521,27 +522,27 @@ let FlexberryMapComponent = Ember.Component.extend( if (e.originalEvent.button === 2) { if (!this.get('maptoolOptionsService.identifyOnRightClick')) { - return + return; } - + if (e.type === 'mousedown') { this.sendAction('toggleSidebar', { changed: true, tabName: 'identify', - prevTab: "" + prevTab: '' }); - let editTools = leafletMap.flexberryMap.tools.getEnabled()._editTools - + let editTools = leafletMap.flexberryMap.tools.getEnabled()._editTools; + // Инициируем нажатие ЛКМ let newMouseDownEvent = new MouseEvent('mousedown'); - editTools.onMousedown({ - latlng: e.latlng, + editTools.onMousedown({ + latlng: e.latlng, originalEvent: newMouseDownEvent - }) + }); } - + if (e.type === 'mouseup') { - leafletMap.flexberryMap.tools.getEnabled()._editTools.stopDrawing() + leafletMap.flexberryMap.tools.getEnabled()._editTools.stopDrawing(); this.set('prevEnabledTools', null); leafletMap.flexberryMap.tools.enable('drag'); } diff --git a/addon/components/map-commands/export.js b/addon/components/map-commands/export.js index 5162c4a01..f640633d8 100644 --- a/addon/components/map-commands/export.js +++ b/addon/components/map-commands/export.js @@ -183,8 +183,6 @@ let ExportMapCommandComponent = Ember.Component.extend({ * Compare service. Disable before open map. */ compare: Ember.inject.service(), - - maptoolOptionsService: Ember.inject.service("maptool-options"), /** Shows export dialog. @@ -198,8 +196,6 @@ let ExportMapCommandComponent = Ember.Component.extend({ // Show dialog. this.set('_exportDialogIsVisible', true); - - this.set('maptoolOptionsService.identifyOnRightClick', false) }, actions: { @@ -235,23 +231,19 @@ let ExportMapCommandComponent = Ember.Component.extend({ leafletMap.flexberryMap.commands.execute('export', null, mapCommandExecutionOptions).then(() => { this.set('_exportIsInProgress', false); e.closeDialog = true; - this.send("hideExportDialog"); + this._hideExportDialog(); }); }, - - /** - Hides export dialog. + }, - @method hideExportDialog - @private - */ - hideExportDialog() { - // Hide dialog. - this.set('_exportDialogIsVisible', false); - - console.log('провернули') - this.set('maptoolOptionsService.identifyOnRightClick', true) - }, + /** + Hides export dialog. + @method _hideExportDialog + @private + */ + _hideExportDialog() { + // Hide dialog. + this.set('_exportDialogIsVisible', false); }, /** @@ -260,7 +252,7 @@ let ExportMapCommandComponent = Ember.Component.extend({ willDestroyElement() { this._super(...arguments); - this.send("hideExportDialog"); + this._hideExportDialog(); }, /** diff --git a/addon/templates/components/map-commands/export.hbs b/addon/templates/components/map-commands/export.hbs index c79e726fd..6d09802d3 100644 --- a/addon/templates/components/map-commands/export.hbs +++ b/addon/templates/components/map-commands/export.hbs @@ -21,7 +21,6 @@ defaultMapCaption=defaultMapCaption timeout=timeout approve=(action "onExportDialogApprove") - hide = (action "hideExportDialog") scalesForExport=scalesForExport switchScaleControlMapName=switchScaleControlMapName }} From 99808a081a534ed683c27de911d92bd3a1482c8f Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Fri, 5 Apr 2024 18:03:01 +0500 Subject: [PATCH 03/15] jscs fix 2 --- addon/components/flexberry-map.js | 28 ++++++++++++++++++------- addon/components/map-commands/export.js | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index 029431515..f689d8cc3 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -520,7 +520,7 @@ let FlexberryMapComponent = Ember.Component.extend( leafletMap.mainMap = true; L.DomEvent.on(leafletMap, 'mousedown mouseup mousein mouseout', (e) => { if (e.originalEvent.button === 2) { - + if (!this.get('maptoolOptionsService.identifyOnRightClick')) { return; } @@ -531,23 +531,35 @@ let FlexberryMapComponent = Ember.Component.extend( tabName: 'identify', prevTab: '' }); - let editTools = leafletMap.flexberryMap.tools.getEnabled()._editTools; + + let identifyTool = leafletMap.flexberryMap.tools.getEnabled(); + let identifyEditTools = Ember.get(identifyTool, '_editTools'); + + if (Ember.isNone(identifyEditTools)) { + return; + } // Инициируем нажатие ЛКМ let newMouseDownEvent = new MouseEvent('mousedown'); - editTools.onMousedown({ + identifyEditTools.onMousedown({ latlng: e.latlng, originalEvent: newMouseDownEvent }); } - if (e.type === 'mouseup') { - leafletMap.flexberryMap.tools.getEnabled()._editTools.stopDrawing(); - this.set('prevEnabledTools', null); + if (e.type === 'mouseup') { + let identifyTool = leafletMap.flexberryMap.tools.getEnabled(); + let identifyEditTools = Ember.get(identifyTool, '_editTools'); + + if (!Ember.isNone(identifyEditTools)) { + identifyEditTools.stopDrawing(); + } + + this.set('prevEnabledTools', null); leafletMap.flexberryMap.tools.enable('drag'); } - - }else if (e.originalEvent.button === 1) { + + } else if (e.originalEvent.button === 1) { if (e.type === 'mousedown') { e.originalEvent.preventDefault(); let enabledTools = { diff --git a/addon/components/map-commands/export.js b/addon/components/map-commands/export.js index f640633d8..52983df37 100644 --- a/addon/components/map-commands/export.js +++ b/addon/components/map-commands/export.js @@ -233,11 +233,12 @@ let ExportMapCommandComponent = Ember.Component.extend({ e.closeDialog = true; this._hideExportDialog(); }); - }, + } }, /** Hides export dialog. + @method _hideExportDialog @private */ From 6d06d70c9b43850120d5cb27d3575132bad53e00 Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Fri, 5 Apr 2024 18:13:14 +0500 Subject: [PATCH 04/15] jscs fix 3 --- addon/components/flexberry-map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index f689d8cc3..b9d513576 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -520,7 +520,7 @@ let FlexberryMapComponent = Ember.Component.extend( leafletMap.mainMap = true; L.DomEvent.on(leafletMap, 'mousedown mouseup mousein mouseout', (e) => { if (e.originalEvent.button === 2) { - + if (!this.get('maptoolOptionsService.identifyOnRightClick')) { return; } @@ -539,7 +539,7 @@ let FlexberryMapComponent = Ember.Component.extend( return; } - // Инициируем нажатие ЛКМ + // Инициируем нажатие ЛКМ let newMouseDownEvent = new MouseEvent('mousedown'); identifyEditTools.onMousedown({ latlng: e.latlng, From eafc1c3c0bb67d421c9ab93d4014b5e47c4590dc Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Fri, 5 Apr 2024 18:20:33 +0500 Subject: [PATCH 05/15] jscs fix 4 --- addon/services/maptool-options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/services/maptool-options.js b/addon/services/maptool-options.js index ffb26216c..413cec759 100644 --- a/addon/services/maptool-options.js +++ b/addon/services/maptool-options.js @@ -1,7 +1,7 @@ import Ember from 'ember'; export default Ember.Service.extend({ - + /** Flag: indicates whether identification is performed when right-clicking on map. From 561e00e8cc2a9f74df729815c3660b92d07f8a39 Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Mon, 22 Apr 2024 20:36:14 +0500 Subject: [PATCH 06/15] calling the identification tool directly, bug fixes --- addon/components/flexberry-map.js | 92 ++++++++++++++++++++++--------- addon/map-tools/identify.js | 9 +++ 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index b9d513576..0e7833466 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -129,6 +129,24 @@ let FlexberryMapComponent = Ember.Component.extend( 'fadeAnimation', 'zoomAnimation', 'zoomAnimationThreshold', 'markerZoomAnimation' ], + /** + Map tool that should be enabled when right clicking + + @property defaultIdentifyTool + @type String + @default null + */ + identifyToolName: null, + + /** + Identification map tool options + + @property identifyToolProperties + @type Object + @default null + */ + identifyToolProperties: null, + /** List of leaflet map properties bindings. */ @@ -519,27 +537,26 @@ let FlexberryMapComponent = Ember.Component.extend( if (this.get('mainMap')) { leafletMap.mainMap = true; L.DomEvent.on(leafletMap, 'mousedown mouseup mousein mouseout', (e) => { + // Обработка ПКМ: Включение инструмента идентификации типа "Прямоугольник" + // При mouseDown включение, создание вершины, переключение в draggable-состояние для задания области идентификации + // При mouseUp идентификация, переключение инструмента if (e.originalEvent.button === 2) { - if (!this.get('maptoolOptionsService.identifyOnRightClick')) { return; } if (e.type === 'mousedown') { - this.sendAction('toggleSidebar', { - changed: true, - tabName: 'identify', - prevTab: '' + // Сохраняем предыдущий инструмент + this.set('prevEnabledTools', { + name: leafletMap.flexberryMap.tools.getEnabled().name, + mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties }); - - let identifyTool = leafletMap.flexberryMap.tools.getEnabled(); + + // Включаем инструмент идентификации + let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('identifyToolName'), this.get('identifyToolProperties')); let identifyEditTools = Ember.get(identifyTool, '_editTools'); - if (Ember.isNone(identifyEditTools)) { - return; - } - - // Инициируем нажатие ЛКМ + // Инициируем нажатие ЛКМ для создания стартовой точки и перехода в состояние "перетаскивание" инструмента let newMouseDownEvent = new MouseEvent('mousedown'); identifyEditTools.onMousedown({ latlng: e.latlng, @@ -548,31 +565,56 @@ let FlexberryMapComponent = Ember.Component.extend( } if (e.type === 'mouseup') { - let identifyTool = leafletMap.flexberryMap.tools.getEnabled(); - let identifyEditTools = Ember.get(identifyTool, '_editTools'); - - if (!Ember.isNone(identifyEditTools)) { - identifyEditTools.stopDrawing(); + let currentMapTool = leafletMap.flexberryMap.tools.getEnabled(); + + if (Ember.get(currentMapTool, 'name') === this.get('identifyToolName')) { + let identifyEditTools = Ember.get(currentMapTool, '_editTools'); + + if (!Ember.isNone(identifyEditTools)) { + identifyEditTools.stopDrawing(); + } } - + + if (!Ember.isNone(this.get('prevEnabledTools'))) { + leafletMap.flexberryMap.tools.enable(this.get('prevEnabledTools.name'), this.get('prevEnabledTools.mapToolProperties')); + } else { + leafletMap.flexberryMap.tools.enable('drag'); + } + this.set('prevEnabledTools', null); - leafletMap.flexberryMap.tools.enable('drag'); } - - } else if (e.originalEvent.button === 1) { + + return; + } + + // Обработка средней клавиши мыши: возможность перетаскивания карты из любого рабочего инструмента + // При mouseDown включение инструмента "рука" + // При mouseUp переключение обратно в рабочий инструмент + if (e.originalEvent.button === 1) { if (e.type === 'mousedown') { e.originalEvent.preventDefault(); - let enabledTools = { + + this.set('prevEnabledTools', { name: leafletMap.flexberryMap.tools.getEnabled().name, mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties - }; - this.set('prevEnabledTools', enabledTools); + }); + leafletMap.flexberryMap.tools.enable('drag'); } else { leafletMap.flexberryMap.tools.enable(this.get('prevEnabledTools.name'), this.get('prevEnabledTools.mapToolProperties')); this.set('prevEnabledTools', null); } - } else if (!Ember.isNone(this.get('prevEnabledTools'))) { + + return; + } + + // Обработка ЛКМ: перезагрузить рабочий инструмент + // Если во время работы инструмента что-то пошло не так (двойной клик, одновременный клик лкм+пкм, выход за границы рабочей области) + if (e.originalEvent.button === 0) { + if (Ember.isNone(this.get('prevEnabledTools'))) { + return; + } + leafletMap.flexberryMap.tools.enable(this.get('prevEnabledTools.name'), this.get('prevEnabledTools.mapToolProperties')); this.set('prevEnabledTools', null); } diff --git a/addon/map-tools/identify.js b/addon/map-tools/identify.js index 722196a04..7c1b9a2f1 100644 --- a/addon/map-tools/identify.js +++ b/addon/map-tools/identify.js @@ -404,6 +404,15 @@ export default BaseNonclickableMapTool.extend({ if (!Ember.isNone(editTools)) { editTools.off('editable:drawing:mousedown', this._drawingStart, this); editTools.off('editable:drawing:end', this._drawingDidEnd, this); + + if (editTools.drawing()) { + let feature = editTools._drawingEditor ? editTools._drawingEditor.feature : null; + if (feature) { + feature.disableEdit(); + feature.remove(); + } + } + editTools.stopDrawing(); } }, From 57af79858f123a3a8b8395e9d721109e602122e9 Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Mon, 22 Apr 2024 20:50:14 +0500 Subject: [PATCH 07/15] jscs fix --- addon/components/flexberry-map.js | 38 +++++++++++++++--------------- addon/mixins/geom-only-map-tool.js | 18 -------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index 0e7833466..fa9c2d072 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -135,16 +135,16 @@ let FlexberryMapComponent = Ember.Component.extend( @property defaultIdentifyTool @type String @default null - */ + */ identifyToolName: null, - + /** Identification map tool options @property identifyToolProperties @type Object @default null - */ + */ identifyToolProperties: null, /** @@ -539,7 +539,7 @@ let FlexberryMapComponent = Ember.Component.extend( L.DomEvent.on(leafletMap, 'mousedown mouseup mousein mouseout', (e) => { // Обработка ПКМ: Включение инструмента идентификации типа "Прямоугольник" // При mouseDown включение, создание вершины, переключение в draggable-состояние для задания области идентификации - // При mouseUp идентификация, переключение инструмента + // При mouseUp идентификация, переключение инструмента if (e.originalEvent.button === 2) { if (!this.get('maptoolOptionsService.identifyOnRightClick')) { return; @@ -547,11 +547,11 @@ let FlexberryMapComponent = Ember.Component.extend( if (e.type === 'mousedown') { // Сохраняем предыдущий инструмент - this.set('prevEnabledTools', { + this.set('prevEnabledTools', { name: leafletMap.flexberryMap.tools.getEnabled().name, mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties }); - + // Включаем инструмент идентификации let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('identifyToolName'), this.get('identifyToolProperties')); let identifyEditTools = Ember.get(identifyTool, '_editTools'); @@ -566,7 +566,7 @@ let FlexberryMapComponent = Ember.Component.extend( if (e.type === 'mouseup') { let currentMapTool = leafletMap.flexberryMap.tools.getEnabled(); - + if (Ember.get(currentMapTool, 'name') === this.get('identifyToolName')) { let identifyEditTools = Ember.get(currentMapTool, '_editTools'); @@ -574,47 +574,47 @@ let FlexberryMapComponent = Ember.Component.extend( identifyEditTools.stopDrawing(); } } - + if (!Ember.isNone(this.get('prevEnabledTools'))) { leafletMap.flexberryMap.tools.enable(this.get('prevEnabledTools.name'), this.get('prevEnabledTools.mapToolProperties')); } else { leafletMap.flexberryMap.tools.enable('drag'); } - + this.set('prevEnabledTools', null); } - + return; - } - + } + // Обработка средней клавиши мыши: возможность перетаскивания карты из любого рабочего инструмента // При mouseDown включение инструмента "рука" // При mouseUp переключение обратно в рабочий инструмент if (e.originalEvent.button === 1) { if (e.type === 'mousedown') { e.originalEvent.preventDefault(); - - this.set('prevEnabledTools', { + + this.set('prevEnabledTools', { name: leafletMap.flexberryMap.tools.getEnabled().name, mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties }); - + leafletMap.flexberryMap.tools.enable('drag'); } else { leafletMap.flexberryMap.tools.enable(this.get('prevEnabledTools.name'), this.get('prevEnabledTools.mapToolProperties')); this.set('prevEnabledTools', null); } - + return; - } - + } + // Обработка ЛКМ: перезагрузить рабочий инструмент // Если во время работы инструмента что-то пошло не так (двойной клик, одновременный клик лкм+пкм, выход за границы рабочей области) if (e.originalEvent.button === 0) { if (Ember.isNone(this.get('prevEnabledTools'))) { return; } - + leafletMap.flexberryMap.tools.enable(this.get('prevEnabledTools.name'), this.get('prevEnabledTools.mapToolProperties')); this.set('prevEnabledTools', null); } diff --git a/addon/mixins/geom-only-map-tool.js b/addon/mixins/geom-only-map-tool.js index aac41ad45..5ae8403bd 100644 --- a/addon/mixins/geom-only-map-tool.js +++ b/addon/mixins/geom-only-map-tool.js @@ -25,23 +25,5 @@ export default Ember.Mixin.create({ // а работаем в любом случае с workingPolygon leafletMap.fire('flexberry-map:geomChanged', { wkt: workingPolygon.toEWKT(L.CRS.EPSG4326) }); - }, - - _disableDraw() { - let editTools = this.get('_editTools'); - if (!Ember.isNone(editTools)) { - editTools.off('editable:drawing:mousedown', this._drawingStart, this); - editTools.off('editable:drawing:end', this._drawingDidEnd, this); - - if (editTools.drawing()) { - let feature = editTools._drawingEditor ? editTools._drawingEditor.feature : null; - if (feature) { - feature.disableEdit(); - feature.remove(); - } - } - - editTools.stopDrawing(); - } } }); From 4790434daea2a6b881b82c324e505e4359f8e15f Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Tue, 23 Apr 2024 13:52:15 +0500 Subject: [PATCH 08/15] defined special props for rightClickTool --- addon/components/flexberry-map.js | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index fa9c2d072..a3e3feac3 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -132,20 +132,27 @@ let FlexberryMapComponent = Ember.Component.extend( /** Map tool that should be enabled when right clicking - @property defaultIdentifyTool + @property rightClickToolName @type String @default null */ - identifyToolName: null, + rightClickToolName: null, /** Identification map tool options - @property identifyToolProperties + @property rightClickToolProperties @type Object @default null */ - identifyToolProperties: null, + rightClickToolProperties: null, + + /** + List of available tools for switching to identification mode using the right click and saving active state of working tool + @property rightClickAvailiblePrevMapTools + @type String [] + */ + rightClickAvailiblePrevMapTools: [], /** List of leaflet map properties bindings. @@ -546,14 +553,19 @@ let FlexberryMapComponent = Ember.Component.extend( } if (e.type === 'mousedown') { - // Сохраняем предыдущий инструмент - this.set('prevEnabledTools', { - name: leafletMap.flexberryMap.tools.getEnabled().name, - mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties - }); + let rightClickAvailiblePrevMapTools = this.get('rightClickAvailiblePrevMapTools'); + let savePrevEnabledTools = rightClickAvailiblePrevMapTools.includes(leafletMap.flexberryMap.tools.getEnabled().name); + + // Сохраняем предыдущий инструмент из списка "включаемых" инструментов + if (savePrevEnabledTools) { + this.set('prevEnabledTools', { + name: leafletMap.flexberryMap.tools.getEnabled().name, + mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties + }); + } // Включаем инструмент идентификации - let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('identifyToolName'), this.get('identifyToolProperties')); + let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('rightClickToolName'), this.get('rightClickToolProperties')); let identifyEditTools = Ember.get(identifyTool, '_editTools'); // Инициируем нажатие ЛКМ для создания стартовой точки и перехода в состояние "перетаскивание" инструмента @@ -567,7 +579,7 @@ let FlexberryMapComponent = Ember.Component.extend( if (e.type === 'mouseup') { let currentMapTool = leafletMap.flexberryMap.tools.getEnabled(); - if (Ember.get(currentMapTool, 'name') === this.get('identifyToolName')) { + if (Ember.get(currentMapTool, 'name') === this.get('rightClickToolName')) { let identifyEditTools = Ember.get(currentMapTool, '_editTools'); if (!Ember.isNone(identifyEditTools)) { From 3fabd9771c3aa5b459688448848727a56260fecf Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Tue, 23 Apr 2024 19:27:19 +0500 Subject: [PATCH 09/15] savePrevEnabledTool --- addon/components/flexberry-map.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index a3e3feac3..a4ebe27f1 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -552,12 +552,18 @@ let FlexberryMapComponent = Ember.Component.extend( return; } + // ПКМ обработчик карты пока умеет работать только с identify-visible-rectangle + // this.rightClickToolProperties должен содержать перечень слоев для идентификации + if (this.get('rightClickToolName') !== 'identify-visible-rectangle' || !this.get('rightClickToolProperties')) { + return; + } + if (e.type === 'mousedown') { let rightClickAvailiblePrevMapTools = this.get('rightClickAvailiblePrevMapTools'); - let savePrevEnabledTools = rightClickAvailiblePrevMapTools.includes(leafletMap.flexberryMap.tools.getEnabled().name); + let savePrevEnabledTool = rightClickAvailiblePrevMapTools.includes(leafletMap.flexberryMap.tools.getEnabled().name); // Сохраняем предыдущий инструмент из списка "включаемых" инструментов - if (savePrevEnabledTools) { + if (savePrevEnabledTool) { this.set('prevEnabledTools', { name: leafletMap.flexberryMap.tools.getEnabled().name, mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties From 76173351e86360e9324cf558f9184a5f424fd7df Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Wed, 24 Apr 2024 15:03:28 +0500 Subject: [PATCH 10/15] refactored --- addon/components/flexberry-map.js | 50 ++++++++++--------------------- addon/services/maptool-options.js | 32 +++++++++++++++++--- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index a4ebe27f1..682688dcd 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -129,31 +129,6 @@ let FlexberryMapComponent = Ember.Component.extend( 'fadeAnimation', 'zoomAnimation', 'zoomAnimationThreshold', 'markerZoomAnimation' ], - /** - Map tool that should be enabled when right clicking - - @property rightClickToolName - @type String - @default null - */ - rightClickToolName: null, - - /** - Identification map tool options - - @property rightClickToolProperties - @type Object - @default null - */ - rightClickToolProperties: null, - - /** - List of available tools for switching to identification mode using the right click and saving active state of working tool - @property rightClickAvailiblePrevMapTools - @type String [] - */ - rightClickAvailiblePrevMapTools: [], - /** List of leaflet map properties bindings. */ @@ -548,18 +523,12 @@ let FlexberryMapComponent = Ember.Component.extend( // При mouseDown включение, создание вершины, переключение в draggable-состояние для задания области идентификации // При mouseUp идентификация, переключение инструмента if (e.originalEvent.button === 2) { - if (!this.get('maptoolOptionsService.identifyOnRightClick')) { - return; - } - - // ПКМ обработчик карты пока умеет работать только с identify-visible-rectangle - // this.rightClickToolProperties должен содержать перечень слоев для идентификации - if (this.get('rightClickToolName') !== 'identify-visible-rectangle' || !this.get('rightClickToolProperties')) { + if (!this.get('maptoolOptionsService.isRightClickToolAvailable')) { return; } if (e.type === 'mousedown') { - let rightClickAvailiblePrevMapTools = this.get('rightClickAvailiblePrevMapTools'); + let rightClickAvailiblePrevMapTools = this.get('maptoolOptionsService.rightClickAvailiblePrevMapTools'); let savePrevEnabledTool = rightClickAvailiblePrevMapTools.includes(leafletMap.flexberryMap.tools.getEnabled().name); // Сохраняем предыдущий инструмент из списка "включаемых" инструментов @@ -568,12 +537,23 @@ let FlexberryMapComponent = Ember.Component.extend( name: leafletMap.flexberryMap.tools.getEnabled().name, mapToolProperties: leafletMap.flexberryMap.tools.getEnabled().mapToolProperties }); + } else { + this.set('prevEnabledTools', null); } + // ПКМ обработчик карты пока умеет работать только с identify-visible-rectangle + // this.rightClickToolProperties должен содержать перечень слоев для идентификации // Включаем инструмент идентификации - let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('rightClickToolName'), this.get('rightClickToolProperties')); + let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('maptoolOptionsService.rightClickToolName'), this.get('maptoolOptionsService.rightClickToolProperties')); let identifyEditTools = Ember.get(identifyTool, '_editTools'); + // Если _editTools не доступно + if (Ember.isNone(identifyEditTools)) { + console.error('The handler for right click map tool is not defined') + leafletMap.flexberryMap.tools.enable('drag'); + return; + } + // Инициируем нажатие ЛКМ для создания стартовой точки и перехода в состояние "перетаскивание" инструмента let newMouseDownEvent = new MouseEvent('mousedown'); identifyEditTools.onMousedown({ @@ -585,7 +565,7 @@ let FlexberryMapComponent = Ember.Component.extend( if (e.type === 'mouseup') { let currentMapTool = leafletMap.flexberryMap.tools.getEnabled(); - if (Ember.get(currentMapTool, 'name') === this.get('rightClickToolName')) { + if (Ember.get(currentMapTool, 'name') === this.get('maptoolOptionsService.rightClickToolName')) { let identifyEditTools = Ember.get(currentMapTool, '_editTools'); if (!Ember.isNone(identifyEditTools)) { diff --git a/addon/services/maptool-options.js b/addon/services/maptool-options.js index 413cec759..9efd735d6 100644 --- a/addon/services/maptool-options.js +++ b/addon/services/maptool-options.js @@ -1,13 +1,37 @@ import Ember from 'ember'; export default Ember.Service.extend({ - /** - Flag: indicates whether identification is performed when right-clicking on map. + Flag: indicates whether tool is performed when right-clicking on map. - @property identifyOnRightClick + @property isRightClickToolAvailable @type Bool @default false */ - identifyOnRightClick: false, + isRightClickToolAvailable: false, + + /** + Map tool that should be enabled when right clicking + + @property rightClickToolName + @type String + @default 'identify-visible-rectangle' + */ + rightClickToolName: 'identify-visible-rectangle', + + /** + Right click map tool options + + @property rightClickToolProperties + @type Object + @default null + */ + rightClickToolProperties: null, + + /** + List of available tools for switching to rightClickTool-mode and saving active state of working tool after + @property rightClickAvailiblePrevMapTools + @type String [] + */ + rightClickAvailiblePrevMapTools: ['drag', 'zoom-in', 'zoom-out'] }); From e79d37305f35e2c7298ad97b29fb4758e86712a2 Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Wed, 24 Apr 2024 15:12:27 +0500 Subject: [PATCH 11/15] jscs fix --- addon/components/flexberry-map.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index 682688dcd..1a840a427 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -544,16 +544,18 @@ let FlexberryMapComponent = Ember.Component.extend( // ПКМ обработчик карты пока умеет работать только с identify-visible-rectangle // this.rightClickToolProperties должен содержать перечень слоев для идентификации // Включаем инструмент идентификации - let identifyTool = leafletMap.flexberryMap.tools.enable(this.get('maptoolOptionsService.rightClickToolName'), this.get('maptoolOptionsService.rightClickToolProperties')); + let rightClickToolName = this.get('maptoolOptionsService.rightClickToolName'); + let rightClickToolProperties = this.get('maptoolOptionsService.rightClickToolProperties'); + let identifyTool = leafletMap.flexberryMap.tools.enable(rightClickToolName, rightClickToolProperties); let identifyEditTools = Ember.get(identifyTool, '_editTools'); // Если _editTools не доступно if (Ember.isNone(identifyEditTools)) { - console.error('The handler for right click map tool is not defined') + console.error('The handler for right click map tool is not defined'); leafletMap.flexberryMap.tools.enable('drag'); return; } - + // Инициируем нажатие ЛКМ для создания стартовой точки и перехода в состояние "перетаскивание" инструмента let newMouseDownEvent = new MouseEvent('mousedown'); identifyEditTools.onMousedown({ From 51d867a3818f40c127963509ab533b614f1be7fb Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Wed, 24 Apr 2024 15:18:07 +0500 Subject: [PATCH 12/15] jscs fix 2 --- addon/services/maptool-options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/services/maptool-options.js b/addon/services/maptool-options.js index 9efd735d6..34cf5653e 100644 --- a/addon/services/maptool-options.js +++ b/addon/services/maptool-options.js @@ -9,7 +9,7 @@ export default Ember.Service.extend({ @default false */ isRightClickToolAvailable: false, - + /** Map tool that should be enabled when right clicking From eb96de84271b43820403cd0f6ca6e9857f4f55ae Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Tue, 11 Jun 2024 12:38:39 +0500 Subject: [PATCH 13/15] fixed righclick identification with measure, identify tools --- addon/components/flexberry-map.js | 9 +++++++-- addon/map-tools/base.js | 10 ++++++++++ addon/map-tools/measure.js | 11 +++++++++++ addon/mixins/leaflet-map/map-tools.js | 4 ---- addon/services/maptool-options.js | 2 +- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/addon/components/flexberry-map.js b/addon/components/flexberry-map.js index 1a840a427..ca24e0f38 100644 --- a/addon/components/flexberry-map.js +++ b/addon/components/flexberry-map.js @@ -529,7 +529,9 @@ let FlexberryMapComponent = Ember.Component.extend( if (e.type === 'mousedown') { let rightClickAvailiblePrevMapTools = this.get('maptoolOptionsService.rightClickAvailiblePrevMapTools'); - let savePrevEnabledTool = rightClickAvailiblePrevMapTools.includes(leafletMap.flexberryMap.tools.getEnabled().name); + + let prevToolName = leafletMap.flexberryMap.tools.getEnabled().name; + let savePrevEnabledTool = rightClickAvailiblePrevMapTools.some(availiblePrevMapToolName => prevToolName.includes(availiblePrevMapToolName)); // Сохраняем предыдущий инструмент из списка "включаемых" инструментов if (savePrevEnabledTool) { @@ -541,6 +543,9 @@ let FlexberryMapComponent = Ember.Component.extend( this.set('prevEnabledTools', null); } + // Для переключения некоторых инструментов рисования требуется корректно прервать функциональность (вызвать необходимые обработчики, переключить флаги) + leafletMap.flexberryMap.tools.getEnabled().interrupt(e); + // ПКМ обработчик карты пока умеет работать только с identify-visible-rectangle // this.rightClickToolProperties должен содержать перечень слоев для идентификации // Включаем инструмент идентификации @@ -571,7 +576,7 @@ let FlexberryMapComponent = Ember.Component.extend( let identifyEditTools = Ember.get(currentMapTool, '_editTools'); if (!Ember.isNone(identifyEditTools)) { - identifyEditTools.stopDrawing(); + identifyEditTools.commitDrawing(e); } } diff --git a/addon/map-tools/base.js b/addon/map-tools/base.js index 299cd0d19..8d00b794b 100644 --- a/addon/map-tools/base.js +++ b/addon/map-tools/base.js @@ -101,6 +101,16 @@ export default Ember.Object.extend(Ember.Evented, } }, + /** + Safely Interrupts tool functionality. + + @method interrupt + @private + */ + interrupt(e) { + return + }, + /** Enables tool. diff --git a/addon/map-tools/measure.js b/addon/map-tools/measure.js index 7ec147bb5..a7d4e0eb4 100644 --- a/addon/map-tools/measure.js +++ b/addon/map-tools/measure.js @@ -95,6 +95,17 @@ export default BaseNonclickableMapTool.extend({ } }, + interrupt(e) { + this._super(...arguments); + let measureTools = this.get('_measureTools'); + + if (Ember.isNone(measureTools)) + return + + measureTools.editTools.onMousedown(e) + measureTools.editTools.onMouseup(e) + }, + /** Handles edit tools 'editable:drawing:end' event. diff --git a/addon/mixins/leaflet-map/map-tools.js b/addon/mixins/leaflet-map/map-tools.js index 62c1fb9b7..6c9ff6749 100644 --- a/addon/mixins/leaflet-map/map-tools.js +++ b/addon/mixins/leaflet-map/map-tools.js @@ -101,10 +101,6 @@ export default Ember.Mixin.create(LeafletMapVisibilityMixin, { mapTool: mapTool }); - if (mapTool === enabledMapTool) { - return enabledMapTool; - } - // Disable enabled map-tool. // It will also trigger 'flexberry-map:tools:disable' event on leaflet map. if (!Ember.isNone(enabledMapTool)) { diff --git a/addon/services/maptool-options.js b/addon/services/maptool-options.js index 34cf5653e..e7c10c03a 100644 --- a/addon/services/maptool-options.js +++ b/addon/services/maptool-options.js @@ -33,5 +33,5 @@ export default Ember.Service.extend({ @property rightClickAvailiblePrevMapTools @type String [] */ - rightClickAvailiblePrevMapTools: ['drag', 'zoom-in', 'zoom-out'] + rightClickAvailiblePrevMapTools: ['drag', 'zoom-in', 'zoom-out', 'identify', 'measure-coordinates', 'measure-distance'] }); From 7d4f7820e04fc2abb4fda7f3e7b29f420fd1a582 Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Tue, 11 Jun 2024 12:47:35 +0500 Subject: [PATCH 14/15] jscs fix --- addon/map-tools/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/map-tools/base.js b/addon/map-tools/base.js index 8d00b794b..e965fb17e 100644 --- a/addon/map-tools/base.js +++ b/addon/map-tools/base.js @@ -108,7 +108,7 @@ export default Ember.Object.extend(Ember.Evented, @private */ interrupt(e) { - return + return; }, /** From 5a12ab7278a7f2a0c392002dda7efc45bcf85f23 Mon Sep 17 00:00:00 2001 From: viatkinviatkin Date: Tue, 11 Jun 2024 12:54:29 +0500 Subject: [PATCH 15/15] jscs fix --- addon/map-tools/measure.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/addon/map-tools/measure.js b/addon/map-tools/measure.js index a7d4e0eb4..04f1782cb 100644 --- a/addon/map-tools/measure.js +++ b/addon/map-tools/measure.js @@ -99,11 +99,18 @@ export default BaseNonclickableMapTool.extend({ this._super(...arguments); let measureTools = this.get('_measureTools'); - if (Ember.isNone(measureTools)) - return + if (Ember.isNone(measureTools)) { + return; + } + + let measureEditTools = Ember.get(measureTools, 'editTools'); + + if (Ember.isNone(measureEditTools)) { + return; + } - measureTools.editTools.onMousedown(e) - measureTools.editTools.onMouseup(e) + measureEditTools.onMousedown(e); + measureEditTools.onMouseup(e); }, /**