Skip to content

Commit b79f05c

Browse files
committed
Use TiTiler colormaps when appropriate
1 parent 4743a24 commit b79f05c

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

configure/src/core/Maker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,10 @@ const getComponent = (
728728
if (domain.length > 0 && !domain.endsWith("/")) domain += "/";
729729

730730
let colormap_html
731-
if (window.mmgisglobal.WITH_TITILER !== "true") {
731+
if (window.mmgisglobal.WITH_TITILER === "true") {
732732
// Get colors from TiTiler if it is available
733733
colormap_html = (
734-
<div>
734+
<div style={{width: "100%"}}>
735735
<img id="titlerCogColormapImage" style={{height: "20px", width: "100%"}} src={`${domain}titiler/colorMaps/${dropdown_value.toLowerCase()}?format=png`} />
736736
</div>
737737
)

src/essence/Tools/Layers/LayersTool.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ var LayersTool = {
262262
if (L_.layers.layer[layer.name] === null) return
263263
if (!layer.url.startsWith('stac-collection:') && layer.type !== 'image' && layer.type !== 'velocity') return
264264
if (layer.cogTransform !== true && (layer.url.startsWith('stac-collection:') || layer.type === 'image')) return
265+
if (layer.type === 'image' && (L_.layers.layer[layer.name].hasOwnProperty('georasters') && L_.layers.layer[layer.name].georasters[0].numberOfRasters !== 1)) return
265266

266267
const dynamicLegendConf = []
267268
const imgElement = document.getElementById(`titlerCogColormapImage_${L_.asLayerUUID(layerName)}`)
@@ -290,7 +291,7 @@ var LayersTool = {
290291
}
291292

292293
let color
293-
if (layer.type === 'tile') {
294+
if (imgElement && layer.type === 'tile') {
294295
const c = context.getImageData(
295296
parseInt((255 / 9) * i),
296297
0,
@@ -605,6 +606,34 @@ function interfaceWithMMGIS(fromInit) {
605606
typeof node[i].url === 'string' &&
606607
node[i].url.split(':')[0] === 'stac-collection'
607608
) {
609+
if (window.mmgisglobal.WITH_TITILER === "true") {
610+
// prettier-ignore
611+
additionalSettings = [
612+
`<img id="titlerCogColormapImage_${node[i].name}" src="${window.location.origin}${(
613+
window.location.pathname || ''
614+
).replace(/\/$/g, '')}/titiler/colorMaps/${node[i].cogColormap}?format=png"></img>`,
615+
].join('\n')
616+
} else {
617+
let { colormap, reverse } = LayersTool.findJSColormap(node[i], node[i].cogColormap)
618+
619+
additionalSettings = (colormapData[colormap].colors).map(
620+
(hex) => {
621+
let rgb = hex.map(v => {return Math.floor(v * 255)}).join(',')
622+
return `<div style="background: rgb(${rgb}); width: 20px; height: 100%; margin: 0px; flex-grow: 1;"></div>`;
623+
}
624+
)
625+
626+
if (reverse === true) {
627+
additionalSettings.reverse()
628+
}
629+
630+
additionalSettings = [
631+
'<div id="titlerCogColormapCSS">',
632+
additionalSettings.join('\n'),
633+
'</div>',
634+
].join('\n')
635+
}
636+
608637
// prettier-ignore
609638
additionalSettings = [
610639
'<div class="layerSettingsTitle">',
@@ -641,9 +670,7 @@ function interfaceWithMMGIS(fromInit) {
641670
'<div class="tileCogColor">',
642671
`<li class="tileCogColormap">`,
643672
`<div class="tileCogColormapMap">`,
644-
`<img id="titlerCogColormapImage_${node[i].name}" src="${window.location.origin}${(
645-
window.location.pathname || ''
646-
).replace(/\/$/g, '')}/titiler/colorMaps/${node[i].cogColormap}?format=png"></img>`,
673+
additionalSettings,
647674
`<ul id="tileCogColormapMapLines"></ul>`,
648675
`</div>`,
649676
'</li>',

0 commit comments

Comments
 (0)