diff --git a/web/client/components/map/leaflet/MeasurementSupport.jsx b/web/client/components/map/leaflet/MeasurementSupport.jsx index b555cfa29d..08ef87c8d5 100644 --- a/web/client/components/map/leaflet/MeasurementSupport.jsx +++ b/web/client/components/map/leaflet/MeasurementSupport.jsx @@ -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'); @@ -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); @@ -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); @@ -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) { diff --git a/web/client/components/map/openlayers/MeasurementSupport.jsx b/web/client/components/map/openlayers/MeasurementSupport.jsx index 8a63948aa3..f6dcc75f8f 100644 --- a/web/client/components/map/openlayers/MeasurementSupport.jsx +++ b/web/client/components/map/openlayers/MeasurementSupport.jsx @@ -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(); } }