Skip to content

Commit

Permalink
hydrate bandCombo from url param
Browse files Browse the repository at this point in the history
  • Loading branch information
PatchesMaps committed Aug 11, 2023
1 parent d9a4436 commit da5bc83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const landsatPresets = [
assets: ['B05', 'B03'],
expression: '(B03-B05)/(B03+B05)',
rescale: '-1,1',
colormap_name: 'gnbu',
colormap_name: 'ocean',
img: 'HLS_NDWI_Landsat.jpg',
},
{
Expand Down Expand Up @@ -142,7 +142,7 @@ const sentinelPresets = [
assets: ['B08', 'B03'],
expression: '(B03-B08)/(B03+B08)',
rescale: '0,1',
colormap_name: 'gnbu',
colormap_name: 'ocean',
asset_as_band: true,
img: 'HLS_NDWI_Sentinel.jpg',
},
Expand Down
11 changes: 7 additions & 4 deletions web/js/modules/layers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,10 @@ export function serializeLayers(layers, state, groupName) {
});
}
if (def.bandCombo) {
const { r, g, b } = def.bandCombo;
const bands = `${r};${g};${b}`;
const bandComboString = JSON.stringify(def.bandCombo).replaceAll('(', '<').replaceAll(')', '>');
item.attributes.push({
id: 'bands',
value: bands,
id: 'bandCombo',
value: encodeURIComponent(bandComboString),
});
}
if (def.palette && (def.custom || def.min || def.max || def.squash || def.disabled)) {
Expand Down Expand Up @@ -1182,13 +1181,17 @@ const createLayerArrayFromState = function(layers, config) {
console.warn(`No such layer: ${layerDef.id}`);
return;
}
const bandComboString = decodeURIComponent(layerDef.attributes.find((attr) => attr.id === 'bandCombo')?.value).replaceAll('>', ')').replaceAll('<', '(');
const bandCombo = bandComboString !== 'undefined' ? JSON.parse(bandComboString) : null;
layerArray = addLayer(
layerDef.id,
getLayerSpec(layerDef.attributes),
layerArray,
config.layers,
null,
projection,
null,
bandCombo,
);
});
return layerArray;
Expand Down

0 comments on commit da5bc83

Please sign in to comment.