Skip to content

Commit

Permalink
#605 Transform 32bit COGs (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman authored Dec 24, 2024
1 parent cf2a8b1 commit 9e60c25
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 26 deletions.
6 changes: 5 additions & 1 deletion configure/src/core/Maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,11 @@ const getComponent = (
}}
>
{com.options.map((o) => {
return <MenuItem value={o}>{o.toUpperCase()}</MenuItem>;
return (
<MenuItem value={o}>
{typeof o === "string" ? o.toUpperCase() : o}
</MenuItem>
);
})}
</Select>
</FormControl>
Expand Down
4 changes: 4 additions & 0 deletions configure/src/core/calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ const c = {
type: "GET",
url: "titiler/tileMatrixSets",
},
titiler_colormapNames: {
type: "GET",
url: "titiler/colorMaps",
},
};

function api(call, data, success, error) {
Expand Down
44 changes: 44 additions & 0 deletions configure/src/core/injectables.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { calls } from "./calls";

const injectablesDefaults = {
TILE_MATRIX_SETS: ["WebMercatorQuad"],
COLORMAP_NAMES: ["viridis"],
};
// Initialize with reasonable defaults
const injectables = {
TILE_MATRIX_SETS: injectablesDefaults["TILE_MATRIX_SETS"],
COLORMAP_NAMES: injectablesDefaults["COLORMAP_NAMES"],
};

export const getInjectables = () => {
getTileMatrixSets();
getColormapNames();
};

export const inject = (configJson) => {
Expand Down Expand Up @@ -62,3 +65,44 @@ function getTileMatrixSets() {
);
}
}

function getColormapNames() {
const injectableName = "COLORMAP_NAMES";
if (window.mmgisglobal.WITH_TITILER === "true") {
calls.api(
"titiler_colormapNames",
null,
(res) => {
// ... new Set removes duplicates
injectables[injectableName] = [
...new Set(
injectablesDefaults["COLORMAP_NAMES"].concat(res.colorMaps)
),
];
},
(res) => {
console.warn(`Failed to query for ${injectableName}. Using defaults.`);
injectables[injectableName] = [
"gist_earth",
"gist_earth_r",
"gist_gray",
"gist_gray_r",
"gist_heat",
"gist_heat_r",
"gist_ncar",
"gist_ncar_r",
"gist_rainbow",
"gist_rainbow_r",
"gist_stern",
"gist_stern_r",
"gist_yarg",
"gist_yarg_r",
"terrain",
"terrain_r",
"viridis",
"viridis_r",
];
}
);
}
}
71 changes: 53 additions & 18 deletions configure/src/metaconfigs/layer-tile-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@
]
},
{
"components": [
{
"field": "minZoom",
"name": "Minimum Zoom",
"description": "The lowest (smallest number) zoom level of the tile set.\nNote: This field can be automatically populate with 'Populate from XML'. 'Populate from XML' uses looks for a tilemapresource.xml in the tileset directory specified by the URL field.",
"type": "number",
"min": 0,
"step": 1,
"width": 3
},
{
"field": "maxNativeZoom",
"name": "Maximum Native Zoom",
"description": "The highest (largest number) zoom level of the tile set.\nNote: This field can be automatically populate with 'Populate from XML'. 'Populate from XML' uses looks for a tilemapresource.xml in the tileset directory specified by the URL field.",
"type": "number",
"min": 0,
"step": 1,
"width": 2
},
{
"field": "maxZoom",
"name": "Maximum Zoom",
"description": "The highest (largest number) zoom level to see in MMGIS. This value is at least as high as Maximum Native Zoom. This allows zooms level higher than that of the tileset. Instead of rendering new tile image, it scales them in instead.",
"type": "number",
"min": 0,
"step": 1,
"width": 3
}
]
},
{
"name": "Cloud-Optimized GeoTiffs (COG)",
"components": [
{
"field": "throughTileServer",
Expand All @@ -106,31 +138,34 @@
{
"components": [
{
"field": "minZoom",
"name": "Minimum Zoom",
"description": "The lowest (smallest number) zoom level of the tile set.\nNote: This field can be automatically populate with 'Populate from XML'. 'Populate from XML' uses looks for a tilemapresource.xml in the tileset directory specified by the URL field.",
"type": "number",
"min": 0,
"step": 1,
"width": 3
"field": "cogTransform",
"name": "Transform COG",
"description": "Enable rescaling and coloring 32-bit COGs on the fly.",
"type": "switch",
"width": 3,
"defaultChecked": false
},
{
"field": "maxNativeZoom",
"name": "Maximum Native Zoom",
"description": "The highest (largest number) zoom level of the tile set.\nNote: This field can be automatically populate with 'Populate from XML'. 'Populate from XML' uses looks for a tilemapresource.xml in the tileset directory specified by the URL field.",
"field": "cogMin",
"name": "Minimum Pixel Data Value",
"description": "If using TiTiler, STAC and 32-bit COGs, the default minimum value for which to rescale.",
"type": "number",
"min": 0,
"step": 1,
"width": 2
"width": 3
},
{
"field": "maxZoom",
"name": "Maximum Zoom",
"description": "The highest (largest number) zoom level to see in MMGIS. This value is at least as high as Maximum Native Zoom. This allows zooms level higher than that of the tileset. Instead of rendering new tile image, it scales them in instead.",
"field": "cogMax",
"name": "Maximum Pixel Data Value",
"description": "If using TiTiler, STAC and 32-bit COGs, the default maximum value for which to rescale.",
"type": "number",
"min": 0,
"step": 1,
"width": 3
},
{
"field": "cogColormap",
"name": "Colormap",
"description": "",
"type": "dropdown",
"width": 3,
"options": "{{COLORMAP_NAMES}}"
}
]
},
Expand Down
27 changes: 24 additions & 3 deletions src/essence/Basics/Layers_/leaflet-tilelayer-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var colorFilterExtension = {

if (this.options.splitColonType === 'stac-collection') {
let datetime

if (this.options.endtime != null) {
if (this.options.starttime != null) {
datetime = `${this.options.starttime}/${this.options.endtime}`
Expand All @@ -38,6 +37,22 @@ var colorFilterExtension = {
url += `${
url.indexOf('?') === -1 ? '?' : '&'
}exitwhenfull=false&skipcovered=false`
if (this.options.cogMin != null && this.options.cogMax != null) {
url += `${url.indexOf('?') === -1 ? '?' : '&'}rescale=[${
this.options.currentCogMin != null
? this.options.currentCogMin
: this.options.cogMin
},${
this.options.currentCogMax != null
? this.options.currentCogMax
: this.options.cogMax
}]`
if (this.options.cogColormap != null) {
url += `${
url.indexOf('?') === -1 ? '?' : '&'
}colormap_name=${this.options.cogColormap}`
}
}
}

url = url
Expand Down Expand Up @@ -161,7 +176,13 @@ var colorFilterExtension = {
}
img.src = url
},
refresh: function (newUrl) {
refresh: function (newUrl, force, updateOptions) {
if (updateOptions) {
Object.keys(updateOptions).forEach((o) => {
this.options[o] = updateOptions[o]
})
}

if (newUrl) this._url = newUrl
if (this._map == null) return
for (let key in this._tiles) {
Expand All @@ -170,7 +191,7 @@ var colorFilterExtension = {
const oldsrc = tile.el.src
const newsrc = this.getTileUrl(tile.coords)

if (oldsrc != newsrc) {
if (oldsrc != newsrc || force) {
//L.DomEvent.off(tile, 'load', this._tileOnLoad); ... this doesnt work!
this._refreshTileUrl(tile, newsrc)
}
Expand Down
5 changes: 5 additions & 0 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ async function makeTileLayer(layerObj) {
typeof layerObj.time === 'undefined'
? null
: layerObj.time.customTimes,
cogMin: layerObj.cogMin,
currentCogMin: layerObj.currentCogMin,
cogMax: layerObj.cogMax,
currentCogMax: layerObj.currentCogMax,
cogColormap: layerObj.cogColormap,
variables: layerObj.variables || {},
})

Expand Down
32 changes: 29 additions & 3 deletions src/essence/Tools/Layers/LayersTool.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,28 @@
top: -9px;
}

#layersTool .tileCogColormap > div {
position: relative;
margin-top: 2px;
}
#layersTool .tileCogColormap > div > div:first-child {
position: absolute;
left: 0;
mix-blend-mode: difference;
}
#layersTool .tileCogColormap > div > div:nth-child(2) {
position: absolute;
right: 5px;
letter-spacing: 1px;
text-transform: capitalize;
mix-blend-mode: difference;
}
#layersTool .tileCogColormap img {
width: 325px;
height: 28px;
margin-left: -12px;
}

#layersTool #layersToolList > li.download_on,
#layersTool #layersToolList > li.gears_on {
height: auto;
Expand All @@ -305,6 +327,7 @@

#layersTool .reload,
#layersTool .reset,
#layersTool .resetCog,
#layersTool .layerDownload,
#layersTool .gears,
#layersTool .locate,
Expand Down Expand Up @@ -333,13 +356,16 @@
#layersTool .LayersToolInfo:hover {
background: var(--color-k);
}
#layersTool .reset:hover {
#layersTool .reset:hover,
#layersTool .resetCog:hover {
color: white;
}
#layersTool .reset {
#layersTool .reset,
#layersTool .resetCog {
display: none;
}
#layersTool #layersToolList > li.gears_on .reset {
#layersTool #layersToolList > li.gears_on .reset,
#layersTool #layersToolList > li.gears_on .resetCog {
display: block;
}

Expand Down
Loading

0 comments on commit 9e60c25

Please sign in to comment.