Interactive interface for browsing global, full-resolution satellite imagery
2103 move shared code for generating snapshot download url into image download utils
Jason Kentc9aa8bd61b7d
diff --git a/web/js/components/image-download/panel.js b/web/js/components/image-download/panel.jsindex 51ba537dd..8cabb8284 100644--- a/web/js/components/image-download/panel.js+++ b/web/js/components/image-download/panel.js@@ -2,10 +2,7 @@ import React from 'react';import {imageSizeValid,getDimensions,- imageUtilGetLayers,- imageUtilGetLayerOpacities,- imageUtilGetLayerWrap,- bboxWMS13+ getDownloadUrl} from '../../modules/image-download/util';import SelectionList from '../util/selector';@@ -46,36 +43,22 @@ export default class ImageResSelection extends React.Component {};}- onDownload(imgWidth, imgHeight) {- const { getLayers, url, lonlats, crs, projection, date } = this.props;+ onDownload(width, height) {+ const { getLayers, url, lonlats, projection, date } = this.props;const { fileType, isWorldfile, resolution } = this.state;const time = new Date(date.getTime());- if (!this.props.hasSubdailyLayers) {- time.setUTCHours(0, 0, 0, 0);- }+const layerList = getLayers();- const layerWraps = imageUtilGetLayerWrap(layerList);- const layers = imageUtilGetLayers(layerList, projection.id);- const opacities = imageUtilGetLayerOpacities(layerList);- const params = [- 'REQUEST=GetSnapshot',- `TIME=${util.toISOStringSeconds(time)}`,- `BBOX=${bboxWMS13(lonlats, crs)}`,- `CRS=${crs}`,- `LAYERS=${layers.join(',')}`,- `WRAP=${layerWraps.join(',')}`,- `FORMAT=${fileType}`,- `WIDTH=${imgWidth}`,- `HEIGHT=${imgHeight}`- ];+ const dlURL = getDownloadUrl(+ url,+ projection,+ layerList,+ lonlats,+ { width, height },+ time,+ isWorldfile+ );- if (opacities.length > 0) {- params.push(`OPACITIES=${opacities.join(',')}`);- }- if (isWorldfile === 'true') {- params.push('WORLDFILE=true');- }- const dlURL = url + '?' + params.join('&') + `&ts=${Date.now()}`;if (url) {util.metrics('lc=' + encodeURIComponent(dlURL));window.open(dlURL, '_blank');@@ -85,7 +68,7 @@ export default class ImageResSelection extends React.Component {googleTagManager.pushEvent({event: 'image_download',layers: {- activeCount: layers.length+ activeCount: layerList.length},image: {resolution: RESOLUTION_KEY[resolution],diff --git a/web/js/modules/animation/selectors.js b/web/js/modules/animation/selectors.jsindex 834b55f8c..b10ad0957 100644--- a/web/js/modules/animation/selectors.js+++ b/web/js/modules/animation/selectors.js@@ -2,10 +2,7 @@ import { each as lodashEach } from 'lodash';import util from '../../util/util';import {imageUtilGetCoordsFromPixelValues,- imageUtilGetLayerOpacities,- imageUtilGetLayerWrap,- bboxWMS13,- imageUtilGetLayers+ getDownloadUrl} from '../image-download/util';import { getLayers } from '../layers/selectors';import { timeScaleFromNumberKey } from '../date/constants';@@ -38,20 +35,12 @@ export function getImageArray(let j = 0;let src;let strDate;- const lonlats = imageUtilGetCoordsFromPixelValues(boundaries, map.ui.selected);- let layersArray;- let layerWraps;- let opacities;- const crs = proj.selected.crs;- const imgFormat = 'image/jpeg';- let products = getProducts(layers[activeString], fromDate, state);+ let products;const useDelta = customSelected && customDelta ? customDelta : delta;const useInterval = customSelected ? customInterval : interval;const increment = customSelected? timeScaleFromNumberKey[customInterval]: timeScaleFromNumberKey[interval];- const height = dimensions.height;- const width = dimensions.width;while (current <= toDate) {j++;@@ -62,26 +51,8 @@ export function getImageArray(}products = getProducts(layers[activeString], current, state);- layersArray = imageUtilGetLayers(products, proj.id);- layerWraps = imageUtilGetLayerWrap(products);- opacities = imageUtilGetLayerOpacities(products);-- const params = [- 'REQUEST=GetSnapshot',- `TIME=${util.toISOStringSeconds(current)}`,- `BBOX=${bboxWMS13(lonlats, crs)}`,- `CRS=${crs}`,- `LAYERS=${layersArray.join(',')}`,- `WRAP=${layerWraps.join(',')}`,- `FORMAT=${imgFormat}`,- `WIDTH=${width}`,- `HEIGHT=${height}`- ];- if (opacities.length > 0) {- params.push(`OPACITIES=${opacities.join(',')}`);- }-- const dlURL = url + '?' + params.join('&') + `&ts=${Date.now()}`;+ const lonlats = imageUtilGetCoordsFromPixelValues(boundaries, map.ui.selected);+ const dlURL = getDownloadUrl(url, proj, products, lonlats, dimensions, current);src = util.format(dlURL, strDate);a.push({diff --git a/web/js/modules/image-download/util.js b/web/js/modules/image-download/util.jsindex 2febac812..121e43e82 100644--- a/web/js/modules/image-download/util.js+++ b/web/js/modules/image-download/util.js@@ -1,8 +1,43 @@import lodashEach from 'lodash/each';+import util from '../../util/util';const GEO_ESTIMATION_CONSTANT = 256.0;const POLAR_ESTIMATION_CONSTANT = 0.002197265625;+export function getDownloadUrl(url, proj, layers, lonlats, dimensions, dateTime, isWorldfile) {+ const { crs } = proj.selected;+ const layersArray = imageUtilGetLayers(layers, proj.id);+ const layerWraps = imageUtilGetLayerWrap(layers);+ const opacities = imageUtilGetLayerOpacities(layers);+ const imgFormat = 'image/jpeg';+ const { height, width } = dimensions;++ // TODO get real value+ const hasSubdailyLayers = false;+ if (!hasSubdailyLayers) {+ dateTime.setUTCHours(0, 0, 0, 0);+ }++ const params = [+ 'REQUEST=GetSnapshot',+ `TIME=${util.toISOStringSeconds(dateTime)}`,+ `BBOX=${bboxWMS13(lonlats, crs)}`,+ `CRS=${crs}`,+ `LAYERS=${layersArray.join(',')}`,+ `WRAP=${layerWraps.join(',')}`,+ `FORMAT=${imgFormat}`,+ `WIDTH=${width}`,+ `HEIGHT=${height}`+ ];+ if (opacities.length > 0) {+ params.push(`OPACITIES=${opacities.join(',')}`);+ }+ if (isWorldfile === 'true') {+ params.push('WORLDFILE=true');+ }+ return url + '?' + params.join('&') + `&ts=${Date.now()}`;+}+/** Estimate appropriate Resolution based on zoom* This is only run if user has not already selected