Skip to content

Commit

Permalink
geosolutions-it#8536 Resolving measure plugin draw conflicts (geosolu…
Browse files Browse the repository at this point in the history
…tions-it#8678) (geosolutions-it#8704)

(cherry picked from commit e4bbfe7)
  • Loading branch information
alex-fko authored Oct 17, 2022
1 parent dd29877 commit 0cf2e05
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
11 changes: 11 additions & 0 deletions web/client/components/map/leaflet/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import assign from 'object-assign';
import L from 'leaflet';
import {
isNil,
slice
} from 'lodash';
import {
Expand Down Expand Up @@ -197,6 +198,11 @@ class MeasurementSupport extends React.Component {
feet: false
};

UNSAFE_componentWillMount() {
if (this.props.measurement?.geomType && (this.props.measurement?.lineMeasureEnabled || this.props.measurement?.areaMeasureEnabled || this.props.measurement?.bearingMeasureEnabled) && isNil(this.drawControl) && this.props.enabled) {
this.addDrawInteraction(this.props);
}
}

UNSAFE_componentWillReceiveProps(newProps) {
if ((newProps && newProps.uom && newProps.uom.length && newProps.uom.length.unit) !== (this.props && this.props.uom && this.props.uom.length && this.props.uom.length.unit) && this.drawControl) {
Expand All @@ -220,6 +226,11 @@ class MeasurementSupport extends React.Component {
this.removeDrawInteraction();
}
}

componentWillUnmount() {
this.removeDrawInteraction();
}

onDrawStart = () => {
this.props.map.off('click', this.restartDrawing, this);
this.removeArcLayer();
Expand Down
43 changes: 30 additions & 13 deletions web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import {round, get, isEqual, dropRight, last} from 'lodash';
import {round, get, isEqual, dropRight, last, isNil} from 'lodash';

import {
reprojectGeoJson,
Expand Down Expand Up @@ -83,6 +83,12 @@ export default class MeasurementSupport extends React.Component {
updateOnMouseMove: false
};

UNSAFE_componentWillMount() {
if (this.props.measurement.geomType && (this.props.measurement.lineMeasureEnabled || this.props.measurement.areaMeasureEnabled || this.props.measurement.bearingMeasureEnabled) && isNil(this.drawControl) && this.props.enabled) {
this.addDrawInteraction(this.props);
}
}

/**
* we assume that only valid features are passed to the draw tools
*/
Expand Down Expand Up @@ -112,24 +118,13 @@ export default class MeasurementSupport extends React.Component {
this.addDrawInteraction(newProps);
}
if (!newProps.measurement.geomType) {
this.removeDrawInteraction();
this.removeMeasureTooltips();
this.removeSegmentLengthOverlays();
this.textLabels = [];
this.segmentLengths = [];
this.props.map.removeLayer(this.measureLayer);
this.vector = null;
this.measureLayer = null;
this.cleanupMeasures(newProps);
if (newProps.measurement.features && newProps.measurement.features.length > 0) {
this.props.changeGeometry([]);
}
if (newProps.measurement.textLabels && newProps.measurement.textLabels.length > 0) {
this.props.setTextLabels([]);
}
if (this.source) {
this.source.clear();
this.source = null;
}
}
let oldFt = this.props.measurement.features;
let newFt = newProps.measurement.features;
Expand All @@ -144,6 +139,9 @@ export default class MeasurementSupport extends React.Component {
}
}

componentWillUnmount() {
this.cleanupMeasures();
}

getLength = (coords, props) => {
if (props.measurement.geomType === 'Bearing' && coords.length > 1) {
Expand All @@ -154,6 +152,7 @@ export default class MeasurementSupport extends React.Component {
return calculateDistance(reprojectedCoords, props.measurement.lengthFormula);
}


getArea = (polygon) => {
return this.calculateGeodesicArea(polygon.getLinearRing(0).getCoordinates());
}
Expand All @@ -162,6 +161,24 @@ export default class MeasurementSupport extends React.Component {
return null;
}

/**
* Remove draw interaction and reset measurement data
*/
cleanupMeasures = () => {
this.removeDrawInteraction();
this.removeMeasureTooltips();
this.removeSegmentLengthOverlays();
this.textLabels = [];
this.segmentLengths = [];
this.props.map.removeLayer(this.measureLayer);
this.vector = null;
this.measureLayer = null;
if (this.source) {
this.source.clear();
this.source = null;
}
};

/**
* Update the draw interaction when feature in edit
*/
Expand Down

0 comments on commit 0cf2e05

Please sign in to comment.