Skip to content

Commit

Permalink
Revert "#8536 Resolving measure plugin draw conflicts (#8678) (#8704)" (
Browse files Browse the repository at this point in the history
#8713)

This reverts commit 0cf2e05.
  • Loading branch information
alex-fko authored Oct 19, 2022
1 parent 731298e commit 15c0793
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
11 changes: 0 additions & 11 deletions web/client/components/map/leaflet/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import assign from 'object-assign';
import L from 'leaflet';
import {
isNil,
slice
} from 'lodash';
import {
Expand Down Expand Up @@ -198,11 +197,6 @@ 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 @@ -226,11 +220,6 @@ 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: 13 additions & 30 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, isNil} from 'lodash';
import {round, get, isEqual, dropRight, last} from 'lodash';

import {
reprojectGeoJson,
Expand Down Expand Up @@ -83,12 +83,6 @@ 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 @@ -118,13 +112,24 @@ export default class MeasurementSupport extends React.Component {
this.addDrawInteraction(newProps);
}
if (!newProps.measurement.geomType) {
this.cleanupMeasures(newProps);
this.removeDrawInteraction();
this.removeMeasureTooltips();
this.removeSegmentLengthOverlays();
this.textLabels = [];
this.segmentLengths = [];
this.props.map.removeLayer(this.measureLayer);
this.vector = null;
this.measureLayer = null;
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 @@ -139,9 +144,6 @@ export default class MeasurementSupport extends React.Component {
}
}

componentWillUnmount() {
this.cleanupMeasures();
}

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


getArea = (polygon) => {
return this.calculateGeodesicArea(polygon.getLinearRing(0).getCoordinates());
}
Expand All @@ -161,24 +162,6 @@ 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 15c0793

Please sign in to comment.