Skip to content

Commit

Permalink
Fixed #1472 handled multiple markers/points when bearing is activated (
Browse files Browse the repository at this point in the history
…#1536)

* handled multiple markers/points when bearing is activated
* improved quality of code
* removed useless code
  • Loading branch information
MV88 authored and offtherailz committed Mar 13, 2017
1 parent ce7a809 commit d89c512
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
21 changes: 14 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,19 @@ const MeasurementSupport = React.createClass({
this.props.map.removeLayer(this.lastLayer);
this.drawControl.enable();
this.drawing = true;

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

if (this.props.measurement.geomType === 'Bearing' && bearingMarkers.length >= 2) {
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 {
this.updateMeasurementResults();
}
}
},
addDrawInteraction: function(newProps) {
Expand Down
8 changes: 4 additions & 4 deletions web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ const MeasurementSupport = React.createClass({
let bearing = 0;
let sketchCoords = this.sketchFeature.getGeometry().getCoordinates();

if (this.props.measurement.geomType === 'Bearing' &&
sketchCoords.length > 1) {
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.sketchFeature.getGeometry().setCoordinates(this.drawInteraction.sketchCoords_);
this.drawInteraction.finishDrawing();
}
}
Expand Down

0 comments on commit d89c512

Please sign in to comment.