-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back power_901_annual_meterology data, add arc imageserver type
- Loading branch information
1 parent
125741c
commit 7c6640c
Showing
4 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
app/scripts/components/common/mapbox/layers/arc-imageserver.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import React, { useEffect, useMemo } from 'react'; | ||
import qs from 'qs'; | ||
import { RasterSource, RasterLayer } from 'mapbox-gl'; | ||
|
||
import { useMapStyle } from './styles'; | ||
import { useArcImageServer } from '$components/common/map/style-generators/hooks'; | ||
|
||
import { userTzDate2utcString } from '$utils/date'; | ||
import { ActionStatus } from '$utils/status'; | ||
|
||
export interface MapLayerArcImageServerProps { | ||
id: string; | ||
stacCol: string; | ||
date?: Date; | ||
sourceParams?: Record<string, any>; | ||
stacApiEndpoint?: string; | ||
tileApiEndpoint?: string; | ||
zoomExtent?: number[]; | ||
onStatusChange?: (result: { status: ActionStatus; id: string }) => void; | ||
isHidden?: boolean; | ||
idSuffix?: string; | ||
} | ||
|
||
interface ArcPaintLayerProps { | ||
id: string; | ||
date?: Date; | ||
sourceParams?: Record<string, any>; | ||
tileApiEndpoint?: string; | ||
zoomExtent?: number[]; | ||
isHidden?: boolean; | ||
idSuffix?: string; | ||
wmsUrl: string; | ||
} | ||
|
||
export function ArcPaintLayer(props: ArcPaintLayerProps) { | ||
const { | ||
id, | ||
tileApiEndpoint, | ||
date, | ||
sourceParams, | ||
zoomExtent, | ||
isHidden, | ||
wmsUrl, | ||
idSuffix = '' | ||
} = props; | ||
|
||
const { updateStyle } = useMapStyle(); | ||
|
||
const [minZoom] = zoomExtent ?? [0, 20]; | ||
|
||
const generatorId = 'arc-timeseries' + idSuffix; | ||
|
||
// Generate Mapbox GL layers and sources for raster timeseries | ||
// | ||
const haveSourceParamsChanged = useMemo( | ||
() => JSON.stringify(sourceParams), | ||
[sourceParams] | ||
); | ||
|
||
useEffect( | ||
() => { | ||
if (!wmsUrl) return; | ||
//https://arcgis.asdc.larc.nasa.gov/server/services/POWER/power_901_annual_meterology_utc/ImageServer/WMSServer | ||
// ?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&LAYERS=PS&DIM_StdTime=1981-12-31T00:00:00Z" | ||
|
||
// TODO: investigate For some reason the request being made is 6 hours ahead? Something to do with UTC <-> local conversion? | ||
const tileParams = qs.stringify({ | ||
format: 'image/png', | ||
service: "WMS", | ||
version: "1.1.1", | ||
request: "GetMap", | ||
srs: "EPSG:3857", | ||
transparent: "true", // TODO: get from sourceparams maybe | ||
width: "256", | ||
height: "256", | ||
DIM_StdTime: userTzDate2utcString(date), // TODO: better date conversion | ||
...sourceParams | ||
}); | ||
|
||
const arcSource: RasterSource = { | ||
type: 'raster', | ||
tiles: [`${wmsUrl}?${tileParams}&bbox={bbox-epsg-3857}`] | ||
}; | ||
|
||
const arcLayer: RasterLayer = { | ||
id: id, | ||
type: 'raster', | ||
source: id, | ||
layout: { | ||
visibility: isHidden ? 'none' : 'visible' | ||
}, | ||
paint: { | ||
'raster-opacity': Number(!isHidden), | ||
'raster-opacity-transition': { | ||
duration: 320 | ||
} | ||
}, | ||
minzoom: minZoom, | ||
metadata: { | ||
layerOrderPosition: 'raster' | ||
} | ||
}; | ||
|
||
const sources = { | ||
[id]: arcSource | ||
}; | ||
const layers = [arcLayer]; | ||
|
||
updateStyle({ | ||
generatorId, | ||
sources, | ||
layers | ||
}); | ||
}, | ||
// sourceParams not included, but using a stringified version of it to detect changes (haveSourceParamsChanged) | ||
[ | ||
updateStyle, | ||
id, | ||
date, | ||
wmsUrl, | ||
minZoom, | ||
haveSourceParamsChanged, | ||
isHidden, | ||
generatorId, | ||
tileApiEndpoint | ||
] | ||
); | ||
|
||
// | ||
// Cleanup layers on unmount. | ||
// | ||
useEffect(() => { | ||
return () => { | ||
updateStyle({ | ||
generatorId, | ||
sources: {}, | ||
layers: [] | ||
}); | ||
}; | ||
}, [updateStyle, generatorId]); | ||
|
||
return null; | ||
} | ||
|
||
export function MapLayerArcImageServer(props:MapLayerArcImageServerProps) { | ||
const { | ||
id, | ||
stacCol, | ||
stacApiEndpoint, | ||
date, | ||
onStatusChange, | ||
} = props; | ||
|
||
const stacApiEndpointToUse = stacApiEndpoint?? process.env.API_STAC_ENDPOINT; | ||
const wmsUrl = useArcImageServer({id, stacCol, stacApiEndpointToUse, date, onStatusChange}); | ||
return <ArcPaintLayer {...props} wmsUrl={wmsUrl} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
--- | ||
id: power_901_annual_meterology_utc | ||
name: 'POWER meteorology' | ||
featured: true | ||
description: "Meteorology" | ||
media: | ||
src: ::file ./no2--dataset-cover.jpg | ||
alt: Power plant shooting steam at the sky. | ||
author: | ||
name: Mick Truyts | ||
url: https://unsplash.com/photos/x6WQeNYJC1w | ||
taxonomy: | ||
- name: Topics | ||
values: | ||
- Air Quality | ||
layers: | ||
- id: cdd10 | ||
stacApiEndpoint: https://hh76k5rqdh.execute-api.us-west-2.amazonaws.com/dev | ||
tileApiEndpoint: https://hh76k5rqdh.execute-api.us-west-2.amazonaws.com/dev | ||
stacCol: POWER/power_901_annual_meterology_utc | ||
name: Cooling Degree Days Above 10 C | ||
type: arc-imageserver | ||
description: | ||
"Test" | ||
zoomExtent: | ||
- 0 | ||
- 20 | ||
sourceParams: | ||
layers: CDD10 | ||
compare: | ||
datasetId: power_901_annual_meterology_utc | ||
layerId: power_901_annual_meterology_utc_DISPH | ||
mapLabel: | | ||
::js ({ dateFns, datetime, compareDatetime }) => { | ||
return `${dateFns.format(datetime, 'LLL yyyy')} VS ${dateFns.format(compareDatetime, 'LLL yyyy')}`; | ||
} | ||
legend: | ||
unit: | ||
label: degree-day | ||
type: gradient | ||
min: 0 | ||
max: 8972.0625 | ||
stops: | ||
- "#4575b4" | ||
- "#91bfdb" | ||
- "#e0f3f8" | ||
- "#ffffbf" | ||
- "#fee090" | ||
- "#fc8d59" | ||
- "#d73027" | ||
# analysis: | ||
# exclude: true | ||
- id: cdd18_3 | ||
stacApiEndpoint: https://hh76k5rqdh.execute-api.us-west-2.amazonaws.com/dev | ||
tileApiEndpoint: https://hh76k5rqdh.execute-api.us-west-2.amazonaws.com/dev | ||
stacCol: POWER/power_901_annual_meterology_utc | ||
name: Cooling Degree Days Above 18.3 C | ||
type: arc | ||
description: | ||
"Lorem Ipsum" | ||
zoomExtent: | ||
- 0 | ||
- 20 | ||
sourceParams: | ||
layers: CDD18_3 | ||
# TODO: get this from `/legend` endpoint? ex - https://arcgis.asdc.larc.nasa.gov/server/rest/services/POWER/power_901_annual_meterology_utc/ImageServer/legend | ||
compare: | ||
datasetId: power_901_annual_meterology_utc | ||
layerId: cdd10 | ||
mapLabel: | | ||
::js ({ dateFns, datetime, compareDatetime }) => { | ||
return `${dateFns.format(datetime, 'LLL yyyy')} VS ${dateFns.format(compareDatetime, 'LLL yyyy')}`; | ||
} | ||
legend: | ||
unit: | ||
label: degree-day | ||
type: gradient | ||
min: 0 | ||
max: 8972.0625 | ||
stops: | ||
- "#4575b4" | ||
- "#91bfdb" | ||
- "#e0f3f8" | ||
- "#ffffbf" | ||
- "#fee090" | ||
- "#fc8d59" | ||
- "#d73027" | ||
# analysis: | ||
# exclude: true | ||
- id: power_901_annual_meterology_utc_DISPH | ||
stacApiEndpoint: https://hh76k5rqdh.execute-api.us-west-2.amazonaws.com/dev | ||
tileApiEndpoint: https://hh76k5rqdh.execute-api.us-west-2.amazonaws.com/dev | ||
stacCol: POWER/power_901_annual_meterology_utc | ||
name: Zero Plane Displacement Height | ||
type: arc | ||
description: | ||
"Lorem Ipsum" | ||
zoomExtent: | ||
- 0 | ||
- 20 | ||
sourceParams: | ||
layers: DISPH | ||
compare: | ||
datasetId: power_901_annual_meterology_utc | ||
layerId: power_901_annual_meterology_utc_DISPH | ||
mapLabel: | | ||
::js ({ dateFns, datetime, compareDatetime }) => { | ||
return `${dateFns.format(datetime, 'LLL yyyy')} VS ${dateFns.format(compareDatetime, 'LLL yyyy')}`; | ||
} | ||
legend: | ||
unit: | ||
label: m | ||
type: gradient | ||
min: 0 | ||
max: 8972.0625 | ||
stops: | ||
- "#4575b4" | ||
- "#91bfdb" | ||
- "#e0f3f8" | ||
- "#ffffbf" | ||
- "#fee090" | ||
- "#fc8d59" | ||
- "#d73027" | ||
# analysis: | ||
# exclude: true | ||
--- |