Skip to content

Commit

Permalink
Add MeasurementSupport updateOnMouseMove property
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Dec 13, 2016
1 parent 520e815 commit a3a2f5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 13 additions & 3 deletions web/client/components/map/leaflet/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ const MeasurementSupport = React.createClass({
projection: React.PropTypes.string,
measurement: React.PropTypes.object,
changeMeasurementState: React.PropTypes.func,
messages: React.PropTypes.object
messages: React.PropTypes.object,
updateOnMouseMove: React.PropTypes.bool
},
contextTypes: {
messages: React.PropTypes.object
},
getDefaultProps() {
return {
updateOnMouseMove: false
};
},
componentWillReceiveProps(newProps) {
var drawingStrings = this.props.messages || (this.context.messages) ? this.context.messages.drawLocal : false;
if (drawingStrings) {
Expand Down Expand Up @@ -126,7 +132,9 @@ const MeasurementSupport = React.createClass({
this.props.map.on('draw:created', this.onDraw.created, this);
this.props.map.on('draw:drawstart', this.onDraw.drawStart, this);
this.props.map.on('click', this.mapClickHandler, this);
this.props.map.on('mousemove', this.updateMeasurementResults, this);
if (this.props.updateOnMouseMove) {
this.props.map.on('mousemove', this.updateMeasurementResults, this);
}

if (newProps.measurement.geomType === 'Point') {
this.drawControl = new L.Draw.Marker(this.props.map, {
Expand Down Expand Up @@ -167,7 +175,9 @@ const MeasurementSupport = React.createClass({
this.props.map.off('draw:created', this.onDraw.created, this);
this.props.map.off('draw:drawstart', this.onDraw.drawStart, this);
this.props.map.off('click', this.mapClickHandler, this);
this.props.map.off('mousemove', this.updateMeasurementResults, this);
if (this.props.updateOnMouseMove) {
this.props.map.off('mousemove', this.updateMeasurementResults, this);
}
}
}
});
Expand Down
16 changes: 13 additions & 3 deletions web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const MeasurementSupport = React.createClass({
map: React.PropTypes.object,
projection: React.PropTypes.string,
measurement: React.PropTypes.object,
changeMeasurementState: React.PropTypes.func
changeMeasurementState: React.PropTypes.func,
updateOnMouseMove: React.PropTypes.bool
},
getDefaultProps() {
return {
updateOnMouseMove: false
};
},
componentWillReceiveProps(newProps) {

Expand Down Expand Up @@ -100,8 +106,10 @@ const MeasurementSupport = React.createClass({
})
});

this.props.map.on('pointermove', this.updateMeasurementResults, this);
this.props.map.on('click', this.updateMeasurementResults, this);
if (this.props.updateOnMouseMove) {
this.props.map.on('pointermove', this.updateMeasurementResults, this);
}

draw.on('drawstart', function(evt) {
// preserv the sketch feature of the draw controller
Expand All @@ -122,7 +130,9 @@ const MeasurementSupport = React.createClass({
this.props.map.removeLayer(this.measureLayer);
this.sketchFeature = null;
this.props.map.un('click', this.updateMeasurementResults, this);
this.props.map.un('pointermove', this.updateMeasurementResults, this);
if (this.props.updateOnMouseMove) {
this.props.map.un('pointermove', this.updateMeasurementResults, this);
}
}
},
updateMeasurementResults() {
Expand Down

0 comments on commit a3a2f5c

Please sign in to comment.