Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3601 measure updates #3602

Closed
wants to merge 12 commits into from

Conversation

MV88
Copy link
Contributor

@MV88 MV88 commented Mar 7, 2019

Description

  • a coordinate editor has been added
  • UI has been updated
  • add support for geodesic lines using a MultiPoint geometry
  • It is possible to show the coordinate editor by setting showCoordinateEditor to true (default is false)
  • It is possible to show the "add as annotation" button in the toolbar by showAddAsAnnotation to true (default is false)
  • you can draw or use the coordinate editor not both
    @example
{
  "name":"Measure",
  "cfg": {
    "defaultOptions" : {
      "showAddAsAnnotation": true,
      "showCoordinateEditor": true
    }
  }
}

Issues

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x", remove the others)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)
you can only draw a measure with the map

What is the new behavior?
You can use a coordinate editor in the measure tool. It updates the measures as the coordinates are changing

Does this PR introduce a breaking change? (check one with "x", remove the other)

  • Yes
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@MV88 MV88 self-assigned this Mar 7, 2019
@MV88 MV88 requested a review from offtherailz March 7, 2019 09:45
@MV88 MV88 changed the title 102 measure updates Fix #3601 measure updates Mar 7, 2019
@coveralls
Copy link

coveralls commented Mar 7, 2019

Coverage Status

Coverage decreased (-0.04%) to 79.189% when pulling e9542cf on MV88:102_measure_updates into a7acb8e on geosolutions-it:c125_annotations.

@ghost ghost assigned offtherailz Mar 7, 2019
@@ -204,7 +205,13 @@ class MeasurementSupport extends React.Component {
const uomOptions = this.uomAreaOptions(newProps);
this.drawControl.setOptions({...uomOptions, uom: newProps.uom});
}
if (newProps.measurement.geomType && newProps.measurement.geomType !== this.props.measurement.geomType) {
if (newProps.measurement.geomType && newProps.measurement.geomType !== this.props.measurement.geomType ||
/* check also when a default is set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too much clear...
what does it means? What's a default?

This checks if geomType exists and existed before, then if at least one of the measure types is enabled, and if enabled is switching from false to true.

It looks like you're triggering addDrawInteraction when the user enable the measure,ensuring that geomType exists and measurement type is set. Not clear why you check the old geomType existence.
Can you be more clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default i meant that when you setup that for example "Bearing" must be selected and active when the Measure tool is opened

In the second condition we can remove the the check for this.props.measurement.geomType

web/client/components/map/openlayers/DrawSupport.jsx Outdated Show resolved Hide resolved
replaceFeatures = (features) => {
this.source = new ol.source.Vector();
features.forEach((geoJSON) => {
let geometry = reprojectGeoJson(geoJSON, "EPSG:4326", this.props.map.getView().getProjection().getCode()).geometry;
let geoJSONFT = geoJSON;
if (geoJSONFT.geometry.type === "Polygon" && geoJSONFT.geometry.coordinates[0].length >= 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why >= 3?. Please comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polygons must have 4 coords to be drawn correctly in ol (the first equal to the last)

isPolygon = (feature) => {
return feature.geometry.type === "Polygon";
}
updateFeatures = (props) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this method

this.measureTooltip.setPosition(this.tooltipCoord);
props.map.addOverlay(this.measureTooltip);
}
this.updateMeasurementResults(props, this.source.getFeatures()[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Istead of adding an argument to updateMeasurementResults, could you simply do something like)

this.sketchFeature = this.source.getFeatures()[0];
this.updateMeasurementResult(props)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I need to know that the update has been made via UI (changing of feature geometry) because then i'll update the state props and then this flag (updatebyUI) it is checked via willReceiveProps in order to avoid endless loop

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong.

I see the second argument of updateMeasurementResults is used only here and that argument, called olFeatureUpdateByUI, is used, inside the function definition, only to do this:

let olFeatureToUse = this.sketchFeature;
        if (!this.sketchFeature) {
            return;
        }
        if (olFeatureUpdateByUI) {
            olFeatureToUse = olFeatureUpdateByUI;
            this.sketchFeature = olFeatureUpdateByUI;
        }

This means that olFeatureByUI, that is this.source.getFeatures()[0] is assigned to this.sketchFeature, if present, and used for nothing else. olFeatureToUse is always this.sketchFeature, so the 2 variables can be removed.

The only corner case is when this.source.getFeatures()[0] != null and this.sketchFeature = null. You can solve this corner case outside the function, without complicating the logic or adding non-sense arguments to the function.

@MV88 MV88 requested review from offtherailz and removed request for offtherailz March 8, 2019 16:37
@MV88
Copy link
Contributor Author

MV88 commented Mar 11, 2019

closed because of conflict

@MV88 MV88 closed this Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants