Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
thiloSchlemmer committed Jan 22, 2025
1 parent 84a1d9f commit beedad6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/modules/olMap/handler/draw/OlDrawHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down
11 changes: 9 additions & 2 deletions src/modules/olMap/handler/measure/OlMeasurementHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 });
}
}

Expand Down

0 comments on commit beedad6

Please sign in to comment.