From beedad6dc593548cb037b410ce5dfb4f59dafa12 Mon Sep 17 00:00:00 2001 From: "Schlemmer, Thilo (LDBV)" <2117317+thiloSchlemmer@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:32:55 +0100 Subject: [PATCH] clean code --- src/modules/olMap/handler/draw/OlDrawHandler.js | 17 +++++++++++++---- .../handler/measure/OlMeasurementHandler.js | 11 +++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/modules/olMap/handler/draw/OlDrawHandler.js b/src/modules/olMap/handler/draw/OlDrawHandler.js index a79ab39389..41f6bbb737 100644 --- a/src/modules/olMap/handler/draw/OlDrawHandler.js +++ b/src/modules/olMap/handler/draw/OlDrawHandler.js @@ -72,6 +72,13 @@ const defaultStyleOption = { text: null // used by Text, Symbol }; +const defaultDrawStats = { + coordinate: null, + azimuth: null, + length: null, + area: null +}; + /** * Handler for draw-interaction with the map * @@ -259,7 +266,6 @@ export class OlDrawHandler extends OlLayerHandler { const ids = features.map((f) => f.getId()); this._setSelection(ids); } - this._updateStatistics(); this._updateDrawState(coordinate, pixel, dragging); }; @@ -538,7 +544,7 @@ export class OlDrawHandler extends OlLayerHandler { this._draw.abortDrawing(); this._modify.setActive(false); setSelection([]); - setStatistic({ length: 0, area: 0 }); + setStatistic(defaultDrawStats); this._helpTooltip.deactivate(); const currentType = this._storeService.getStore().getState().draw.type; this._init(currentType); @@ -552,7 +558,7 @@ export class OlDrawHandler extends OlLayerHandler { this._draw.abortDrawing(); this._modify.setActive(false); setSelection([]); - setStatistic({ length: 0, area: 0 }); + setStatistic(defaultDrawStats); this._helpTooltip.deactivate(); setType(null); } @@ -647,11 +653,14 @@ export class OlDrawHandler extends OlLayerHandler { } this._modify.setActive(true); this._setSelected(feature); + if (feature) { + feature.on('change', () => this._updateStatistics()); + } } _setStatistics(feature) { const stats = getStats(feature.getGeometry()); - setStatistic({ length: stats.length, area: stats.area }); + setStatistic({ ...defaultDrawStats, length: stats.length, area: stats.area }); } _getStyleOption() { diff --git a/src/modules/olMap/handler/measure/OlMeasurementHandler.js b/src/modules/olMap/handler/measure/OlMeasurementHandler.js index 186db706af..54a8446977 100644 --- a/src/modules/olMap/handler/measure/OlMeasurementHandler.js +++ b/src/modules/olMap/handler/measure/OlMeasurementHandler.js @@ -45,6 +45,13 @@ import { GEODESIC_CALCULATION_STATUS, GEODESIC_FEATURE_PROPERTY, GeodesicGeometr import { setData } from '../../../../store/fileStorage/fileStorage.action'; import { createDefaultLayerProperties } from '../../../../store/layers/layers.reducer'; +const defaultMeasurementStats = { + coordinate: null, + azimuth: null, + length: null, + area: null +}; + /** * Handler for measurement-interaction with the map. * @@ -582,9 +589,9 @@ export class OlMeasurementHandler extends OlLayerHandler { // (snapping from pointer-position to first point) and must be corrected into a valid LineString const measureGeometry = this._createMeasureGeometry(feature); const nonAreaStats = getStats(measureGeometry); - setStatistic({ length: nonAreaStats.length, area: stats.area }); + setStatistic({ ...defaultMeasurementStats, length: nonAreaStats.length, area: stats.area }); } else { - setStatistic({ length: stats.length, area: stats.area }); + setStatistic({ ...defaultMeasurementStats, length: stats.length, area: stats.area }); } }