Interactive interface for browsing global, full-resolution satellite imagery
hide download options when no measurements, on mobile
Jason Kentf5c80f1f95e2
diff --git a/web/css/measure.css b/web/css/measure.cssindex 1f767e1e8..c33da4549 100644--- a/web/css/measure.css+++ b/web/css/measure.css@@ -26,6 +26,11 @@}}}+ .measure-download {+ border-top: 1px solid #666;+ margin-top: 4px;+ padding-top: 8px;+ }}@media (max-width: 740px) {@@ -39,7 +44,7 @@}.measure-unit-toggle {- border-bottom: 1px solid rgba(255, 255, 255, 0.25);+ border-bottom: 1px solid #666;padding: 6px 5px 6px 27px;& .custom-control-input:checked ~ .custom-control-label::before {border-color: #fff;diff --git a/web/js/components/map/ol-measure-tool.js b/web/js/components/map/ol-measure-tool.jsindex ae7f6ef57..d2911314c 100644--- a/web/js/components/map/ol-measure-tool.js+++ b/web/js/components/map/ol-measure-tool.js@@ -20,6 +20,7 @@ import {} from 'ol/style';import {toggleMeasureActive as toggleMeasureActiveAction,+ updateMeasurements as updateMeasurementsAction,} from '../../modules/measure/actions';import {transformLineStringArc,@@ -57,11 +58,11 @@ function OlMeasureTool (props) {let twoFingerTouchListener;const {- map, olMap, crs, unitOfMeasure, toggleMeasureActive,+ map, olMap, crs, bbox, unitOfMeasure, toggleMeasureActive, updateMeasurements,} = props;- const dlShapeFiles = () => downloadShapefiles(allMeasurements[crs]);- const dlGeoJSON = () => downloadGeoJSON(allMeasurements[crs]);+ const dlShapeFiles = () => downloadShapefiles(allMeasurements[crs], bbox);+ const dlGeoJSON = () => downloadGeoJSON(allMeasurements[crs], bbox);useEffect(() => {if (map && map.rendered) {@@ -155,6 +156,7 @@ function OlMeasureTool (props) {sources[crs].removeFeature(feature);olMap.removeOverlay(overlay);delete allMeasurements[crs][feature.ol_uid];+ updateMeasurements(allMeasurements);};ReactDOM.render((@@ -199,6 +201,7 @@ function OlMeasureTool (props) {feature,overlay: tooltipOverlay,};+ updateMeasurements(allMeasurements);terminateDraw();renderTooltip(feature, tooltipOverlay);};@@ -276,6 +279,7 @@ function OlMeasureTool (props) {);allMeasurements[crs] = {};+ updateMeasurements(allMeasurements);terminateDraw();olMap.removeOverlay(tooltipOverlay);if (vectorLayers[crs]) {@@ -299,6 +303,9 @@ const mapDispatchToProps = (dispatch) => ({toggleMeasureActive: (isActive) => {dispatch(toggleMeasureActiveAction(isActive));},+ updateMeasurements: (measurements) => {+ dispatch(updateMeasurementsAction(measurements));+ },});const mapStateToProps = (state) => {@@ -308,10 +315,12 @@ const mapStateToProps = (state) => {measure,} = state;const { unitOfMeasure } = measure;+ const { crs, maxExtent } = proj.selected;return {map,olMap: map.ui.selected,- crs: proj.selected.crs,+ crs,+ bbox: maxExtent,unitOfMeasure,};};diff --git a/web/js/components/measure-tool/measure-menu.js b/web/js/components/measure-tool/measure-menu.jsindex 7a8e2dd80..d540a5ae0 100644--- a/web/js/components/measure-tool/measure-menu.js+++ b/web/js/components/measure-tool/measure-menu.js@@ -7,6 +7,21 @@ import { onToggle } from '../../modules/modal/actions';import IconList from '../util/list';import { changeUnits } from '../../modules/measure/actions';+const DOWNLOAD_GEOJSON = {+ text: 'Download as GeoJSON',+ iconClass: 'ui-icon icon-large',+ iconName: 'faDownload',+ id: 'download-geojson-button',+ key: 'measure-download-geojson',+ className: 'measure-download',+};+const DOWNLOAD_SHAPEFILE = {+ text: 'Download as Shapefiles',+ iconClass: 'ui-icon icon-large',+ iconName: 'faDownload',+ id: 'download-shapefiles-button',+ key: 'measure-download-shapefile',+};const OPTIONS_ARRAY = [{text: 'Measure distance',@@ -22,20 +37,6 @@ const OPTIONS_ARRAY = [id: 'measure-area-button',key: 'measure-area',},- {- text: 'Download as Shapefiles',- iconClass: 'ui-icon icon-large',- iconName: 'faDownload',- id: 'download-shapefiles-button',- key: 'measure-download-shapefile',- },- {- text: 'Download as GeoJSON',- iconClass: 'ui-icon icon-large',- iconName: 'faDownload',- id: 'download-geojson-button',- key: 'measure-download-geojson',- },{text: 'Remove Measurements',iconClass: 'ui-icon icon-large',@@ -43,6 +44,8 @@ const OPTIONS_ARRAY = [id: 'clear-measurements-button',key: 'measure-clear',},+ DOWNLOAD_GEOJSON,+ DOWNLOAD_SHAPEFILE,];class MeasureMenu extends Component {@@ -76,8 +79,12 @@ class MeasureMenu extends Component {}render() {- const { isTouchDevice, units } = this.props;+ const {+ isTouchDevice, unitOfMeasure, measurementsInProj, isMobile,+ } = this.props;const listSize = isTouchDevice ? 'medium' : 'small';+ DOWNLOAD_SHAPEFILE.hidden = !measurementsInProj || isMobile;+ DOWNLOAD_GEOJSON.hidden = !measurementsInProj || isMobile;return (<><Form>@@ -87,10 +94,10 @@ class MeasureMenu extends Component {className="custom-control-input"type="checkbox"onChange={this.unitToggle}- defaultChecked={units === 'mi'}+ defaultChecked={unitOfMeasure === 'mi'}/><label className="custom-control-label" htmlFor="unit-toggle">- {units}+ {unitOfMeasure}</label></div></Form>@@ -104,14 +111,24 @@ class MeasureMenu extends Component {}}-const mapStateToProps = (state, ownProps) => ({- isTouchDevice: state.modal.customProps.touchDevice,- map: state.map,- units: state.measure.unitOfMeasure,-});+const mapStateToProps = (state, ownProps) => {+ const {+ modal, map, measure, proj, browser,+ } = state;+ const { unitOfMeasure, allMeasurements } = measure;+ const { crs } = proj.selected;+ const measurementsInProj = !!Object.keys(allMeasurements[crs]).length;+ return {+ isMobile: browser.lessThan.medium,+ isTouchDevice: modal.customProps.touchDevice,+ map,+ unitOfMeasure,+ measurementsInProj,+ };+};const mapDispatchToProps = (dispatch, ownProps) => ({- onToggleUnits: (units) => {- dispatch(changeUnits(units));+ onToggleUnits: (unitOfMeasure) => {+ dispatch(changeUnits(unitOfMeasure));},onCloseModal: (eventName) => {dispatch(onToggle());@@ -124,9 +141,11 @@ export default connect()(MeasureMenu);MeasureMenu.propTypes = {+ isMobile: PropTypes.bool,isTouchDevice: PropTypes.bool,map: PropTypes.object,+ measurementsInProj: PropTypes.bool,onCloseModal: PropTypes.func,onToggleUnits: PropTypes.func,- units: PropTypes.string,+ unitOfMeasure: PropTypes.string,};diff --git a/web/js/components/measure-tool/util.js b/web/js/components/measure-tool/util.jsindex d0bf23662..013605023 100644--- a/web/js/components/measure-tool/util.js+++ b/web/js/components/measure-tool/util.js@@ -124,47 +124,40 @@ export function getGeographicLibDistance(line) {return totalDistance;}-function getFeatureJSON(measurements) {+// TODO - area measurments as geoJSON don't work+function getFeatureJSON(measurements, bbox) {return {type: 'FeatureCollection',features: Object.values(measurements).map(({ feature, overlay }) => {- const geometry = feature.getGeometry();- const type = geometry.getType();- const [coordinates] = type === 'Polygon'- ? geometry.getCoordinates()- : [geometry.getCoordinates()];+ const type = feature.getGeometry().getType();+ const coordinates = feature.getGeometry().getCoordinates();return {type: 'Feature',- geometry: {- type,- coordinates,- },+ geometry: { type, coordinates },properties: {- name: overlay.element.innerText,+ size: overlay.element.innerText,},};}),};}-export function downloadShapefiles(measurements) {- // (optional) set names for feature types and zipped folder+export function downloadShapefiles(measurements, bbox) {+ // Set names for feature types and zipped folderconst options = {folder: 'worldviewMeasurements',types: {polygon: 'areaMeasurements',- line: 'distanceMeasurements',+ polyline: 'distanceMeasurements',},};- shpWrite.download(getFeatureJSON(measurements), options);+ shpWrite.download(getFeatureJSON(measurements, bbox), options);}-export function downloadGeoJSON(measurements) {- const name = 'worldviewMeasurements.json';- const data = JSON.stringify(getFeatureJSON(measurements), undefined, 2);- const blob = new Blob([data], {- type: 'application/json',- name,- });- FileSaver.saveAs(blob, name);+export function downloadGeoJSON(measurements, bbox) {+ const data = JSON.stringify(getFeatureJSON(measurements, bbox), undefined, 2);+ const fileName = 'worldviewMeasurements.json';+ const fileType = 'application/geo+json';+ const blob = new Blob([data], { fileType, fileName });+ FileSaver.saveAs(blob, fileName);}diff --git a/web/js/components/util/list.js b/web/js/components/util/list.jsindex 89a3ab630..fc9a9c4cf 100644--- a/web/js/components/util/list.js+++ b/web/js/components/util/list.js@@ -55,36 +55,34 @@ export default function List(props) {return (<ListGroup className={listClass}>{list.map((item) => {- const { iconName } = item;- const { iconClass } = item;- const isActive = item.key && active ? item.key === active : false;- const isDisabled = item.key && disabled ? item.key === disabled : false;- const { badge } = item;- const className = item.className ? item.className : '';- const tagType = item.href ? 'a' : 'button';- return (+ const {+ id, iconName, iconClass, className, hidden, key, href, badge, text,+ } = item;+ const isActive = key && active ? key === active : false;+ const isDisabled = key && disabled ? key === disabled : false;+ const itemClass = className || '';+ const tagType = href ? 'a' : 'button';+ const propsOnClick = onClick+ ? () => onClick(key || id)+ : null;+ const onClickFn = item.onClick ? item.onClick : propsOnClick;+++ return !hidden && (<ListGroupItem- key={item.key || item.id || ''}+ key={key || id || ''}tag={tagType}active={isActive}- id={item.id || ''}- className={`${className} ${size}-item`}- href={item.href ? item.href : undefined}- target={item.href ? '_blank' : undefined}- onClick={- item.onClick- ? item.onClick- : onClick- ? () => {- onClick(item.key || item.id);- }- : null- }+ id={id || ''}+ className={`${itemClass} ${size}-item`}+ href={href || undefined}+ target={href ? '_blank' : undefined}+ onClick={onClickFn}disabled={isDisabled}>{iconName ? <FontAwesomeIcon icon={listIcons[iconName]} className={iconClass} fixedWidth /> : ''}- {item.text || ''}- {badge ? <Badge pill>{item.badge}</Badge> : ''}+ {text || ''}+ {badge ? <Badge pill>{badge}</Badge> : ''}</ListGroupItem>);})}diff --git a/web/js/modules/measure/actions.js b/web/js/modules/measure/actions.jsindex ebb629f97..ea89b3a91 100644--- a/web/js/modules/measure/actions.js+++ b/web/js/modules/measure/actions.js@@ -1,4 +1,8 @@-import { CHANGE_UNITS, TOGGLE_MEASURE_ACTIVE } from './constants';+import {+ CHANGE_UNITS,+ UPDATE_MEASUREMENTS,+ TOGGLE_MEASURE_ACTIVE,+} from './constants';export function changeUnits(units) {return {@@ -12,3 +16,10 @@ export function toggleMeasureActive(isActive) {value: isActive,};}++export function updateMeasurements(allMeasurements) {+ return {+ type: UPDATE_MEASUREMENTS,+ value: allMeasurements,+ };+}diff --git a/web/js/modules/measure/constants.js b/web/js/modules/measure/constants.jsindex a859f9bee..d3d86a58a 100644--- a/web/js/modules/measure/constants.js+++ b/web/js/modules/measure/constants.js@@ -1,2 +1,3 @@export const CHANGE_UNITS = 'MEASURE/CHANGE_UNITS';export const TOGGLE_MEASURE_ACTIVE = 'MEASURE/TOGGLE_MEASURE_ACTIVE';+export const UPDATE_MEASUREMENTS = 'MEASURE/UPDATE_MEASUREMENTS';diff --git a/web/js/modules/measure/reducers.js b/web/js/modules/measure/reducers.jsindex 694afa65a..fede72479 100644--- a/web/js/modules/measure/reducers.js+++ b/web/js/modules/measure/reducers.js@@ -1,21 +1,40 @@-import { assign as lodashAssign } from 'lodash';-import { CHANGE_UNITS, TOGGLE_MEASURE_ACTIVE } from './constants';+import {+ CHANGE_UNITS,+ UPDATE_MEASUREMENTS,+ TOGGLE_MEASURE_ACTIVE,+} from './constants';const defaultState = {isActive: false,unitOfMeasure: 'km',+ allMeasurements: {+ 'EPSG:3413': {},+ 'EPSG:4326': {},+ 'EPSG:3031': {},+ },};export default function measureReducer(state = defaultState, action) {switch (action.type) {case CHANGE_UNITS:- return lodashAssign({}, state, {+ return {+ ...state,unitOfMeasure: action.value,- });+ };case TOGGLE_MEASURE_ACTIVE:- return lodashAssign({}, state, {+ return {+ ...state,isActive: action.value,- });+ };+ case UPDATE_MEASUREMENTS:+ return {+ ...state,+ allMeasurements: {+ 'EPSG:3413': action.value['EPSG:3413'],+ 'EPSG:4326': action.value['EPSG:4326'],+ 'EPSG:3031': action.value['EPSG:3031'],+ },+ };default:return state;}