@@ -50,10 +50,7 @@ import CodeMirror from "@uiw/react-codemirror";
5050import { json } from "@codemirror/lang-json" ;
5151import { Button } from "@mui/material" ;
5252
53- import {
54- evaluate_cmap ,
55- data as colormapData ,
56- } from "../external/js-colormaps.js" ;
53+ import { data as colormapData } from "../external/js-colormaps.js" ;
5754
5855import { calls } from "./calls" ;
5956import { parseTileMatrixSetCRS } from "./crsUtils" ;
@@ -270,6 +267,107 @@ const useStyles = makeStyles((theme) => ({
270267 } ,
271268} ) ) ;
272269
270+ const ColormapHelper = ( { colormapName } ) => {
271+ const c = useStyles ( ) ;
272+
273+ let colormap_html = null ;
274+ let colormap = colormapName ;
275+
276+ // js-colormaps data object only contains the non reversed color so we need to track if the color is reversed
277+ let reverse = false ;
278+
279+ // TiTiler colormap variables are all lower case so we need to format them correctly for js-colormaps
280+ if ( colormap . toLowerCase ( ) . endsWith ( "_r" ) ) {
281+ colormap = colormap . substring ( 0 , colormap . length - 2 ) ;
282+ reverse = true ;
283+ }
284+
285+ let index = Object . keys ( colormapData ) . findIndex ( ( v ) => {
286+ return v . toLowerCase ( ) === colormap . toLowerCase ( ) ;
287+ } ) ;
288+
289+ if ( index > - 1 ) {
290+ colormap = Object . keys ( colormapData ) [ index ] ;
291+ } else {
292+ console . warn ( `The colormap '${ colormap } ' does not exist` ) ;
293+ }
294+
295+ if ( colormap in colormapData ) {
296+ colormap_html = colormapData [ colormap ] . colors . map ( ( hex ) => {
297+ return (
298+ < div
299+ className = { c . colorDropdownArrayHex }
300+ style = { {
301+ background : `rgb(${ hex
302+ . map ( ( v ) => {
303+ return Math . floor ( v * 255 ) ;
304+ } )
305+ . join ( "," ) } )`,
306+ } }
307+ > </ div >
308+ ) ;
309+ } ) ;
310+
311+ if ( reverse === true ) {
312+ colormap_html . reverse ( ) ;
313+ }
314+ } else if ( colormap === "DEFAULT" ) {
315+ // Default color for velocity layer
316+ const defaultColors = [
317+ "rgb(36,104, 180)" ,
318+ "rgb(60,157, 194)" ,
319+ "rgb(128,205,193 )" ,
320+ "rgb(151,218,168 )" ,
321+ "rgb(198,231,181)" ,
322+ "rgb(238,247,217)" ,
323+ "rgb(255,238,159)" ,
324+ "rgb(252,217,125)" ,
325+ "rgb(255,182,100)" ,
326+ "rgb(252,150,75)" ,
327+ "rgb(250,112,52)" ,
328+ "rgb(245,64,32)" ,
329+ "rgb(237,45,28)" ,
330+ "rgb(220,24,32)" ,
331+ "rgb(180,0,35)" ,
332+ ] ;
333+
334+ colormap_html = defaultColors . map ( ( hex ) => {
335+ return (
336+ < div
337+ className = { c . colorDropdownArrayHex }
338+ style = { { background : `${ hex } ` } }
339+ > </ div >
340+ ) ;
341+ } ) ;
342+ }
343+ return colormap_html ;
344+ }
345+
346+ const DrawColormap = ( { src, colormapName } ) => {
347+ const [ error , setError ] = useState ( false ) ;
348+
349+ const handleError = ( ) => {
350+ setError ( true ) ;
351+ } ;
352+
353+ return (
354+ < >
355+ { error
356+ ? < ColormapHelper colormapName = { colormapName } />
357+ : < div style = { { width : "100%" } } >
358+ < img
359+ id = "titlerCogColormapImage"
360+ alt = ""
361+ style = { { height : "20px" , width : "100%" } }
362+ src = { src }
363+ onError = { handleError }
364+ />
365+ </ div >
366+ }
367+ </ >
368+ ) ;
369+ } ;
370+
273371const getComponent = (
274372 com ,
275373 configuration ,
@@ -1139,95 +1237,20 @@ const getComponent = (
11391237 : window . mmgisglobal . ROOT_PATH || "" ;
11401238 if ( domain . length > 0 && ! domain . endsWith ( "/" ) ) domain += "/" ;
11411239
1142- let colormap_html ;
1240+ let source = "" ;
11431241 if ( window . mmgisglobal . WITH_TITILER === "true" ) {
11441242 // Get colors from TiTiler if it is available
1145- colormap_html = (
1146- < div style = { { width : "100%" } } >
1147- < img
1148- id = "titlerCogColormapImage"
1149- style = { { height : "20px" , width : "100%" } }
1150- src = { `${ domain } titiler/colorMaps/${ dropdown_value . toLowerCase ( ) } ?format=png` }
1151- />
1152- </ div >
1153- ) ;
1154- } else {
1155- let colormap = dropdown_value ;
1156- // js-colormaps data object only contains the non reversed color so we need to track if the color is reversed
1157- let reverse = false ;
1158-
1159- // TiTiler colormap variables are all lower case so we need to format them correctly for js-colormaps
1160- if ( colormap . toLowerCase ( ) . endsWith ( "_r" ) ) {
1161- colormap = colormap . substring ( 0 , colormap . length - 2 ) ;
1162- reverse = true ;
1163- }
1164-
1165- let index = Object . keys ( colormapData ) . findIndex ( ( v ) => {
1166- return v . toLowerCase ( ) === colormap . toLowerCase ( ) ;
1167- } ) ;
1168-
1169- if ( index > - 1 ) {
1170- colormap = Object . keys ( colormapData ) [ index ] ;
1171- } else {
1172- console . warn ( `The colormap '${ colormap } ' does not exist` ) ;
1173- }
1174-
1175- if ( colormap in colormapData ) {
1176- colormap_html = colormapData [ colormap ] . colors . map ( ( hex ) => {
1177- return (
1178- < div
1179- className = { c . colorDropdownArrayHex }
1180- style = { {
1181- background : `rgb(${ hex
1182- . map ( ( v ) => {
1183- return Math . floor ( v * 255 ) ;
1184- } )
1185- . join ( "," ) } )`,
1186- } }
1187- > </ div >
1188- ) ;
1189- } ) ;
1190-
1191- if ( reverse === true ) {
1192- colormap_html . reverse ( ) ;
1193- }
1194- } else if ( colormap === "DEFAULT" ) {
1195- // Default color for velocity layer
1196- const defaultColors = [
1197- "rgb(36,104, 180)" ,
1198- "rgb(60,157, 194)" ,
1199- "rgb(128,205,193 )" ,
1200- "rgb(151,218,168 )" ,
1201- "rgb(198,231,181)" ,
1202- "rgb(238,247,217)" ,
1203- "rgb(255,238,159)" ,
1204- "rgb(252,217,125)" ,
1205- "rgb(255,182,100)" ,
1206- "rgb(252,150,75)" ,
1207- "rgb(250,112,52)" ,
1208- "rgb(245,64,32)" ,
1209- "rgb(237,45,28)" ,
1210- "rgb(220,24,32)" ,
1211- "rgb(180,0,35)" ,
1212- ] ;
1213-
1214- colormap_html = defaultColors . map ( ( hex ) => {
1215- return (
1216- < div
1217- className = { c . colorDropdownArrayHex }
1218- style = { { background : `${ hex } ` } }
1219- > </ div >
1220- ) ;
1221- } ) ;
1222- }
1243+ source = `${ domain } titiler/colorMaps/${ dropdown_value . toLowerCase ( ) } ?format=png`
12231244 }
12241245
12251246 return (
12261247 < div >
12271248 { inlineHelp ? (
12281249 < >
12291250 { inner }
1230- < div className = { c . textArrayHexes } > { colormap_html || null } </ div >
1251+ < div className = { c . textArrayHexes } >
1252+ < DrawColormap src = { source } colormapName = { dropdown_value } />
1253+ </ div >
12311254 < Typography className = { c . subtitle2 } >
12321255 { com . description || "" }
12331256 </ Typography >
0 commit comments