Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WV-3161 GHGC Layer #5199

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/default/common/config/wv.json/layerOrder.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"layerOrder": [
"GHGC_Net_Primary_Produnction",
"GHGC_Heterotrophic_Respiration",
"GHGC_Net_Ecosystem_Exchange",
"GHGC_Fire_Emissions",
"GHGC_Wood_Fuel_Emissions",
"HLS_S30_Nadir_BRDF_Adjusted_Reflectance",
"HLS_L30_Nadir_BRDF_Adjusted_Reflectance",
"HLS_Customizable_Landsat",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"layers": {
"GHGC_Fire_Emissions": {
"id": "GHGC_Fire_Emissions",
"layerName": "fire",
"title": "Fire Emissions",
"subtitle": "U.S. Greenhouse Gas Center",
"description": "ghgc/Fire_Emissions",
"tags": "ghgc fire",
"group": "overlays",
"layergroup": "Reference",
"format": "image/png",
"type": "titiler",
"disableSnapshot": true,
"wrapX": true,
"colormapName": "purd",
"rescale": "0,0.3",
"period": "monthly",
"projections": {
"geographic": {
"source": "GHGC:geographic"
}
},
"startDate": "2003-01-01T00:00:00Z",
"endDate": "2017-12-31T23:59:59Z"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"layers": {
"GHGC_Heterotrophic_Respiration": {
"id": "GHGC_Heterotrophic_Respiration",
"layerName": "rh",
"title": "Heterotrophic Respiration",
"subtitle": "U.S. Greenhouse Gas Center",
"description": "ghgc/Heterotrophic_Respiration",
"tags": "ghgc rh",
"group": "overlays",
"layergroup": "Reference",
"format": "image/png",
"type": "titiler",
"disableSnapshot": true,
"wrapX": true,
"colormapName": "purd",
"rescale": "0,0.3",
"period": "monthly",
"projections": {
"geographic": {
"source": "GHGC:geographic"
}
},
"startDate": "2003-01-01T00:00:00Z",
"endDate": "2017-12-31T23:59:59Z"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"layers": {
"GHGC_Net_Ecosystem_Exchange": {
"id": "GHGC_Net_Ecosystem_Exchange",
"layerName": "nee",
"title": "Net Ecosystem Exchange",
"subtitle": "U.S. Greenhouse Gas Center",
"description": "ghgc/Net_Ecosystem_Exchange",
"tags": "ghgc nee",
"group": "overlays",
"layergroup": "Reference",
"format": "image/png",
"type": "titiler",
"disableSnapshot": true,
"wrapX": true,
"colormapName": "coolwarm",
"rescale": "-0.1,0.1",
"period": "monthly",
"projections": {
"geographic": {
"source": "GHGC:geographic"
}
},
"startDate": "2003-01-01T00:00:00Z",
"endDate": "2017-12-31T23:59:59Z"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"layers": {
"GHGC_Net_Primary_Produnction": {
"id": "GHGC_Net_Primary_Produnction",
"layerName": "npp",
"title": "Net Primary Production",
"subtitle": "U.S. Greenhouse Gas Center",
"description": "ghgc/Net_Primary_Produnction",
"tags": "ghgc npp",
"group": "overlays",
"layergroup": "Reference",
"format": "image/png",
"type": "titiler",
"disableSnapshot": true,
"wrapX": true,
"colormapName": "purd",
"rescale": "0,0.3",
"period": "monthly",
"projections": {
"geographic": {
"source": "GHGC:geographic"
}
},
"startDate": "2003-01-01T00:00:00Z",
"endDate": "2017-12-31T23:59:59Z"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"layers": {
"GHGC_Wood_Fuel_Emissions": {
"id": "GHGC_Wood_Fuel_Emissions",
"layerName": "fuel",
"title": "Wood Fuel Emissions",
"subtitle": "U.S. Greenhouse Gas Center",
"description": "ghgc/Wood_Fuel_Emissions",
"tags": "ghgc fuel",
"group": "overlays",
"layergroup": "Reference",
"format": "image/png",
"type": "titiler",
"disableSnapshot": true,
"wrapX": true,
"colormapName": "bupu",
"rescale": "0,0.03",
"period": "monthly",
"projections": {
"geographic": {
"source": "GHGC:geographic"
}
},
"startDate": "2003-01-01T00:00:00Z",
"endDate": "2017-12-31T23:59:59Z"
}
}
}
3 changes: 3 additions & 0 deletions config/default/release/config/wv.json/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"FIRMS:xyz": {
"url": "https://firms.modaps.eosdis.nasa.gov/layers"
},
"GHGC:geographic": {
"url": "https://ghg.center/api/raster/mosaic"
},
"DDV": {
"url": "https://kv9drwgv6l.execute-api.us-west-2.amazonaws.com/",
"matrixSets": {
Expand Down
6 changes: 6 additions & 0 deletions web/images/layers/previews/geographic/GHGC_Fire_Emissions.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 91 additions & 18 deletions web/js/map/layerbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export default function mapLayerBuilder(config, cache, store) {
* @param {*} attributes
* @param {*} wrapLayer
*/
const getLayer = (createLayerFunc, def, options, attributes, wrapLayer) => {
const getLayer = async (createLayerFunc, def, options, attributes, wrapLayer) => {
const state = store.getState();
const layer = createLayerFunc(def, options, null, state, attributes);
const layer = await createLayerFunc(def, options, null, state, attributes);
layer.wv = attributes;
if (!wrapLayer) {
return layer;
}
const layerNext = createLayerFunc(def, options, 1, state, attributes);
const layerPrior = createLayerFunc(def, options, -1, state, attributes);
const layerNext = await createLayerFunc(def, options, 1, state, attributes);
const layerPrior = await createLayerFunc(def, options, -1, state, attributes);

layerPrior.wv = attributes;
layerNext.wv = attributes;
Expand Down Expand Up @@ -593,7 +593,7 @@ export default function mapLayerBuilder(config, cache, store) {
return layer;
};

const registerSearch = async (def, options, state) => {
const registerSearchDDV = async (def, options, state) => {
const { date } = state;
let requestDate;
if (options.group === 'activeB') {
Expand Down Expand Up @@ -679,16 +679,13 @@ export default function mapLayerBuilder(config, cache, store) {
return name;
};

const createTitilerLayer = async (def, options, day, state) => {
const { proj: { selected }, date } = state;
const { maxExtent, crs } = selected;
const { r, g, b } = def.bandCombo;

const buildDdvTileUrlFunction = async (def, options, state) => {
const source = config.sources[def.source];
const { r, g, b } = def.bandCombo;

const searchID = await registerSearch(def, options, state);
const searchID = await registerSearchDDV(def, options, state);

const tileUrlFunction = (tileCoord) => {
return (tileCoord) => {
const z = tileCoord[0] - 1;
const x = tileCoord[1];
const y = tileCoord[2];
Expand All @@ -703,9 +700,85 @@ export default function mapLayerBuilder(config, cache, store) {

const urlParams = `mosaic/tiles/${searchID}/WGS1984Quad/${z}/${x}/${y}@1x?post_process=swir&${params.filter((p) => !p.split('=').includes('undefined')).join('&')}`;

return source.url + urlParams;
return `${source.url}${urlParams}`;
};
};

const registerSearchGHGC = async (def, options, state) => {
const { date } = state;
let requestDate;
if (options.group === 'activeB') {
requestDate = date.selectedB;
} else {
requestDate = date.selected;
}

const formattedDate = util.toISOStringSeconds(requestDate).slice(0, 10);
const BASE_URL = 'https://ghg.center/api/raster';
const temporalRange = [`${formattedDate}T00:00:00Z`, `${formattedDate}T23:59:59Z`];

const collectionsFilter = {
op: 'eq',
args: [{ property: 'collection' }, 'casagfed-carbonflux-monthgrid-v3'],
};

const temporalFilter = {
op: 't_intersects',
args: [{ property: 'datetime' }, { interval: temporalRange }],
};

const searchBody = {
'filter-lang': 'cql2-json',
filter: {
op: 'and',
args: [
collectionsFilter,
temporalFilter,
],
},
};

const registerResponse = await fetch(`${BASE_URL}/mosaic/register`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(searchBody),
});
const registerResponseJSON = await registerResponse.json();

const tilesHref = registerResponseJSON.links?.find((link) => link.rel === 'tilejson').href;

const tilejsonResponse = await fetch(`${tilesHref}?assets=${def.layerName}&colormap_name=${def.colormapName}&rescale=${encodeURI(def.rescale)}`);
const tilejsonResponseJSON = await tilejsonResponse.json();

const { name } = tilejsonResponseJSON;

return name;
};

const buildGhgcTileUrlFunction = async (def, options, state) => {
const source = config.sources[def.source];

const searchID = await registerSearchGHGC(def, options, state);

return (tileCoord) => {
const z = tileCoord[0] - 1;
const x = tileCoord[1];
const y = tileCoord[2];

const urlParams = `${searchID}/tiles/WGS1984Quad/${z}/${x}/${y}?assets=${def.layerName}&colormap_name=${def.colormapName}&rescale=${encodeURI(def.rescale)}`;

return `${source.url}/${urlParams}`;
};
};

const createTitilerLayer = async (def, options, day, state) => {
const { proj: { selected }, date } = state;
const { maxExtent, crs } = selected;

const tileUrlFunction = def.source === 'DDV' ? await buildDdvTileUrlFunction(def, options, state) : await buildGhgcTileUrlFunction(def, options, state);

const xyzSourceOptions = {
crossOrigin: 'anonymous',
projection: get(crs),
Expand All @@ -720,7 +793,7 @@ export default function mapLayerBuilder(config, cache, store) {
const layer = new OlLayerTile({
source: xyzSource,
className,
minZoom: def.minZoom,
minZoom: def.minZoom || 0,
extent: maxExtent,
});

Expand Down Expand Up @@ -816,19 +889,19 @@ export default function mapLayerBuilder(config, cache, store) {
if (!isGranule) {
switch (def.type) {
case 'wmts':
layer = getLayer(createLayerWMTS, def, options, attributes, wrapLayer);
layer = await getLayer(createLayerWMTS, def, options, attributes, wrapLayer);
break;
case 'vector':
layer = getLayer(createLayerVector, def, options, attributes, wrapLayer);
layer = await getLayer(createLayerVector, def, options, attributes, wrapLayer);
break;
case 'wms':
layer = getLayer(createLayerWMS, def, options, attributes, wrapLayer);
layer = await getLayer(createLayerWMS, def, options, attributes, wrapLayer);
break;
case 'titiler':
layer = await getLayer(createTitilerLayer, def, options, attributes, wrapLayer);
break;
case 'xyz':
layer = getLayer(createXYZLayer, def, options, attributes, wrapLayer);
layer = await getLayer(createXYZLayer, def, options, attributes, wrapLayer);
break;
default:
throw new Error(`Unknown layer type: ${type}`);
Expand Down
Loading