|
1 | 1 | import { calls } from "./calls"; |
| 2 | +import { data as colormapData } from '../external/js-colormaps.js' |
2 | 3 |
|
3 | 4 | const injectablesDefaults = { |
4 | 5 | TILE_MATRIX_SETS: ["WebMercatorQuad"], |
5 | 6 | COLORMAP_NAMES: ["viridis"], |
| 7 | + VELOCITY_COLORMAP_NAMES: ["RDYLBU_R"], |
6 | 8 | }; |
7 | 9 | // Initialize with reasonable defaults |
8 | 10 | const injectables = { |
9 | 11 | TILE_MATRIX_SETS: injectablesDefaults["TILE_MATRIX_SETS"], |
10 | 12 | COLORMAP_NAMES: injectablesDefaults["COLORMAP_NAMES"], |
| 13 | + VELOCITY_COLORMAP_NAMES: injectablesDefaults["VELOCITY_COLORMAP_NAMES"], |
11 | 14 | }; |
12 | 15 |
|
13 | 16 | export const getInjectables = () => { |
14 | 17 | getTileMatrixSets(); |
15 | | - getColormapNames(); |
| 18 | + getColormapNames("COLORMAP_NAMES"); |
| 19 | + getColormapNames("VELOCITY_COLORMAP_NAMES"); |
16 | 20 | }; |
17 | 21 |
|
18 | 22 | export const inject = (configJson) => { |
@@ -66,43 +70,61 @@ function getTileMatrixSets() { |
66 | 70 | } |
67 | 71 | } |
68 | 72 |
|
69 | | -function getColormapNames() { |
70 | | - const injectableName = "COLORMAP_NAMES"; |
| 73 | +function getColormapNames(injectableName) { |
71 | 74 | if (window.mmgisglobal.WITH_TITILER === "true") { |
72 | 75 | calls.api( |
73 | 76 | "titiler_colormapNames", |
74 | 77 | null, |
75 | 78 | (res) => { |
| 79 | + // Get the intersection of colormaps from js-colormaps and TiTiler |
| 80 | + const js_colormaps = Object.keys(colormapData).map((color => color.toLowerCase())); |
| 81 | + let colormaps = res.colorMaps; |
| 82 | + colormaps = colormaps.filter((color) => { |
| 83 | + if (js_colormaps.includes(color.toLowerCase())) { |
| 84 | + return color; |
| 85 | + } |
| 86 | + |
| 87 | + // js-colormaps only includes the non reversed names so check for the reverse |
| 88 | + if (color.endsWith("_r") && js_colormaps.includes(color.substr(0, color.length - 2))) { |
| 89 | + return color; |
| 90 | + } |
| 91 | + }); |
| 92 | + |
| 93 | + // Sort |
| 94 | + colormaps.sort(); |
| 95 | + |
76 | 96 | // ... new Set removes duplicates |
77 | 97 | injectables[injectableName] = [ |
78 | 98 | ...new Set( |
79 | | - injectablesDefaults["COLORMAP_NAMES"].concat(res.colorMaps) |
| 99 | + injectablesDefaults[injectableName].concat(colormaps) |
80 | 100 | ), |
81 | 101 | ]; |
82 | 102 | }, |
83 | 103 | (res) => { |
84 | 104 | console.warn(`Failed to query for ${injectableName}. Using defaults.`); |
85 | | - injectables[injectableName] = [ |
86 | | - "gist_earth", |
87 | | - "gist_earth_r", |
88 | | - "gist_gray", |
89 | | - "gist_gray_r", |
90 | | - "gist_heat", |
91 | | - "gist_heat_r", |
92 | | - "gist_ncar", |
93 | | - "gist_ncar_r", |
94 | | - "gist_rainbow", |
95 | | - "gist_rainbow_r", |
96 | | - "gist_stern", |
97 | | - "gist_stern_r", |
98 | | - "gist_yarg", |
99 | | - "gist_yarg_r", |
100 | | - "terrain", |
101 | | - "terrain_r", |
102 | | - "viridis", |
103 | | - "viridis_r", |
104 | | - ]; |
| 105 | + injectables[injectableName] = Object.keys(colormapData); |
105 | 106 | } |
106 | 107 | ); |
| 108 | + } else { |
| 109 | + // Get colormaps from js-colormaps and the inversed colors |
| 110 | + const js_colormaps = Object.keys(colormapData).map((color => color.toLowerCase())); |
| 111 | + let colormaps = []; |
| 112 | + js_colormaps.forEach((color) => { |
| 113 | + colormaps.push(color); |
| 114 | + // js-colormaps only includes the non reversed names so add the reverse |
| 115 | + if (!color.endsWith("_r")) { |
| 116 | + colormaps.push(`${color}_r`); |
| 117 | + } |
| 118 | + }); |
| 119 | + |
| 120 | + // Sort |
| 121 | + colormaps.sort(); |
| 122 | + |
| 123 | + // ... new Set removes duplicates |
| 124 | + injectables[injectableName] = [ |
| 125 | + ...new Set( |
| 126 | + injectablesDefaults[injectableName].concat(colormaps) |
| 127 | + ), |
| 128 | + ]; |
107 | 129 | } |
108 | 130 | } |
0 commit comments