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

Fixed #1472 handled multiple markers/points when bearing is activated #1536

Merged
merged 4 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions web/client/components/map/leaflet/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const React = require('react');
const assign = require('object-assign');
var L = require('leaflet');
const {slice} = require('lodash');
var CoordinatesUtils = require('../../../utils/CoordinatesUtils');

require('leaflet-draw');
Expand Down Expand Up @@ -53,7 +54,7 @@ const MeasurementSupport = React.createClass({
this.lastLayer = evt.layer;

if (this.props.measurement.geomType === 'Point') {
let pos = this.drawControl._marker.getLatLng();
let pos = this.drawControl._markers.getLatLng();
let point = {x: pos.lng, y: pos.lat, srs: 'EPSG:4326'};
let newMeasureState = assign({}, this.props.measurement, {point: point});
this.props.changeMeasurementState(newMeasureState);
Expand Down Expand Up @@ -95,10 +96,6 @@ const MeasurementSupport = React.createClass({
coords2 = [currentLatLng.lng, currentLatLng.lat];
} else if (bearingMarkers.length === 2) {
coords2 = [bearingMarkers[1].getLatLng().lng, bearingMarkers[1].getLatLng().lat];
// restrict line drawing to 2 vertices
this.drawControl._finishShape();
this.drawControl.disable();
this.drawing = false;
}
// calculate the azimuth as base for bearing information
bearing = CoordinatesUtils.calculateAzimuth(coords1, coords2, this.props.projection);
Expand All @@ -121,9 +118,30 @@ const MeasurementSupport = React.createClass({
this.props.map.removeLayer(this.lastLayer);
this.drawControl.enable();
this.drawing = true;

} else {
this.updateMeasurementResults();
let bearingMarkers = this.drawControl._markers || [];
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify :

if (bearingMarkers.length >= 2 && this.props.measurement.geomType === 'Bearing') {
     this.drawControl._markers = slice(this.drawControl._markers, 0, 2);
     this.drawControl._poly._latlngs = slice(this.drawControl._poly._latlngs, 0, 2);
     this.drawControl._poly._originalPoints = slice(this.drawControl._poly._originalPoints, 0, 2);
     this.updateMeasurementResults();
     this.drawControl._finishShape();
     this.drawControl.disable();
} else {
     updateMeasurementResults()
}


if (bearingMarkers.length <= 2 ) {
this.updateMeasurementResults();
}
if (bearingMarkers.length === 2 && this.props.measurement.geomType === 'Bearing') {
this.drawControl._finishShape();
this.drawControl.disable();
this.drawing = false;
}
if (bearingMarkers.length > 2) {
if (this.props.measurement.geomType === 'Bearing') {
this.drawControl._markers = slice(this.drawControl._markers, 0, 2);
this.drawControl._poly._latlngs = slice(this.drawControl._poly._latlngs, 0, 2);
this.drawControl._poly._originalPoints = slice(this.drawControl._poly._originalPoints, 0, 2);
this.updateMeasurementResults();
this.drawControl._finishShape();
this.drawControl.disable();
this.drawing = false;
} else {
this.updateMeasurementResults();
}
}
}
},
addDrawInteraction: function(newProps) {
Expand Down
4 changes: 2 additions & 2 deletions web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ const MeasurementSupport = React.createClass({
if (this.props.measurement.geomType === 'Bearing' &&
sketchCoords.length > 1) {
// calculate the azimuth as base for bearing information
bearing = CoordinatesUtils.calculateAzimuth(
sketchCoords[0], sketchCoords[1], this.props.projection);
bearing = CoordinatesUtils.calculateAzimuth(sketchCoords[0], sketchCoords[1], this.props.projection);
if (sketchCoords.length > 2) {
this.drawInteraction.sketchCoords_ = [sketchCoords[0], sketchCoords[1], sketchCoords[0]];
this.drawInteraction.finishDrawing();
}
}
Expand Down