Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

fix rhumb distance measurement for different projections. add tooltip for great circle toggle. clean up styles for great circle toggle

Jason Kent48dbf2171317
diff --git a/web/css/measure.css b/web/css/measure.css
index f9f34ffd9..4b7cc5146 100644
--- a/web/css/measure.css
+++ b/web/css/measure.css
@@ -9,10 +9,19 @@
right: 10px;
bottom: 151px;
& .modal-body {
- padding: 0;
- }
- & .form-check-label {
- margin-left: 24px;
+ padding: 5px 0 0;
+ & div {
+ padding: 0 5px 8px 10px;
+ & .form-check-label {
+ margin-left: 24px;
+ }
+ & i {
+ margin-left: 5px;
+ }
+ & .form-check-input {
+ margin: 0 0 0 -20px;
+ }
+ }
}
}
diff --git a/web/js/components/measure-tool/measure-menu.js b/web/js/components/measure-tool/measure-menu.js
index c5f24ad87..f637d3c4d 100644
--- a/web/js/components/measure-tool/measure-menu.js
+++ b/web/js/components/measure-tool/measure-menu.js
@@ -1,10 +1,10 @@
-import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
+import React, { Component } from 'react';
import { onToggle } from '../../modules/modal/actions';
import IconList from '../util/list';
import { changeUnits, useGreatCircle } from '../../modules/measure/actions';
-import { FormGroup, Label, Input } from 'reactstrap';
+import { Form, FormGroup, Label, Input, Tooltip } from 'reactstrap';
import AlertUtil from '../util/alert';
// import googleTagManager from 'googleTagManager';
@@ -33,9 +33,11 @@ class MeasureMenu extends Component {
constructor(props) {
super(props);
this.state = {
+ tooltipOpen: false,
units: props.units,
useGreatCircleMeasurements: props.useGreatCircleMeasurements
};
+ this.tooltipToggle = this.tooltipToggle.bind(this);
}
triggerEvent(eventName) {
@@ -55,6 +57,12 @@ class MeasureMenu extends Component {
this.props.onToggleUseGreatCircle(checked);
}
+ tooltipToggle() {
+ this.setState({
+ tooltipOpen: !this.state.tooltipOpen
+ });
+ }
+
render() {
const { clickType } = this.props;
const isMobile = clickType === 'touchstart';
@@ -68,28 +76,38 @@ class MeasureMenu extends Component {
message='Tap to add a point. Double tap to complete.'
/>}
- <FormGroup check>
- <Label check>
- <Input
- id="great-circle-toggle"
+ <Form>
+ <FormGroup check>
+ <Label check>
+ <Input
+ id="great-circle-toggle"
+ type="checkbox"
+ onChange={this.useGreatCircle.bind(this)}
+ defaultChecked={this.state.useGreatCircleMeasurements}
+ />
+ {' '} Use Great circle <i id="great-circle-info" className="fas fa-info-circle"></i>
+ </Label>
+ <Tooltip
+ placement="top"
+ isOpen={this.state.tooltipOpen}
+ target="great-circle-info"
+ toggle={this.tooltipToggle}>
+ If enabled, lines will be drawn as great circle arcs which represent
+ the shortest real world distance between two points.
+ </Tooltip>
+ </FormGroup>
+ <div className="measure-unit-toggle custom-control custom-switch">
+ <label htmlFor="unit-toggle">km</label>
+ <input
+ id="unit-toggle"
+ className="custom-control-input"
type="checkbox"
- onChange={this.useGreatCircle.bind(this)}
- defaultChecked={this.state.useGreatCircleMeasurements}
- />
- {' '} Great circle? <i className="fas fa-info-circle"></i>
- </Label>
- </FormGroup>
+ onChange={this.unitToggle.bind(this)}
+ defaultChecked={this.state.units === 'mi'}/>
+ <label className="custom-control-label" htmlFor="unit-toggle">mi</label>
+ </div>
+ </Form>
- <div className="measure-unit-toggle custom-control custom-switch">
- <label htmlFor="unit-toggle">km</label>
- <input
- id="unit-toggle"
- className="custom-control-input"
- type="checkbox"
- onChange={this.unitToggle.bind(this)}
- defaultChecked={this.state.units === 'mi'}/>
- <label className="custom-control-label" htmlFor="unit-toggle">mi</label>
- </div>
<IconList
list={OPTIONS_ARRAY}
onClick={this.triggerEvent.bind(this)}
@@ -132,6 +150,7 @@ MeasureMenu.propTypes = {
onCloseModal: PropTypes.func,
onToggleUnits: PropTypes.func,
onToggleUseGreatCircle: PropTypes.func,
+
units: PropTypes.string,
useGreatCircleMeasurements: PropTypes.bool
};
diff --git a/web/js/map/measure/util.js b/web/js/map/measure/util.js
index c0f2b305a..117c13bf4 100644
--- a/web/js/map/measure/util.js
+++ b/web/js/map/measure/util.js
@@ -69,7 +69,7 @@ export function transformPolygonArc (geom, projection) {
export function getFormattedLength(line, projection, unitOfMeasure, useGreatCircle) {
const metricLength = useGreatCircle
? OlSphereGetLength(line, { projection })
- : getRhumbLineDistance(line);
+ : getRhumbLineDistance(line, projection);
if (unitOfMeasure === 'km') {
return metricLength > 100
@@ -110,9 +110,13 @@ export function getFormattedArea(polygon, projection, unitOfMeasure, useGreatCir
/**
*
*/
-export function getRhumbLineDistance(lineString) {
- const p1 = TurfPoint(lineString.getFirstCoordinate());
- const p2 = TurfPoint(lineString.getLastCoordinate());
+export function getRhumbLineDistance(lineString, projection) {
+ let transformedLine = lineString;
+ if (projection !== referenceProjection) {
+ transformedLine = lineString.clone().transform(projection, referenceProjection);
+ }
+ const p1 = TurfPoint(transformedLine.getFirstCoordinate());
+ const p2 = TurfPoint(transformedLine.getLastCoordinate());
return TurfRhumbDistance(p1, p2) * metersPerKilometer;
};