diff --git a/packages/config/src/config/tile.set.output.ts b/packages/config/src/config/tile.set.output.ts index 719ad353e..1a8cc936f 100644 --- a/packages/config/src/config/tile.set.output.ts +++ b/packages/config/src/config/tile.set.output.ts @@ -17,5 +17,50 @@ export const DefaultColorRampOutput: ConfigTileSetRasterOutput = { title: 'Color ramp', name: 'color-ramp', pipeline: [{ type: 'color-ramp' }], - background: { r: 188, g: 222, b: 254, alpha: 1 }, + // Taken from 0 of DefaultColorRamp + background: { r: 167, g: 205, b: 228, alpha: 1 }, } as const; + +export const DefaultColorRamp = `-8764 0 0 0 255 +-4000 3 45 85 255 +-100 0 101 199 255 +-3 167 205 228 255 +0 167 205 228 255 +10 245 234 163 255 +20 236 232 157 255 +30 227 229 150 255 +40 218 227 144 255 +50 209 225 138 255 +75 174 215 112 255 +100 147 208 93 255 +150 69 179 53 255 +200 21 151 47 255 +250 18 130 63 255 +300 81 144 58 255 +350 132 158 47 255 +400 181 171 35 255 +450 233 181 17 255 +500 235 149 2 255 +550 209 97 2 255 +600 177 54 2 255 +700 148 20 1 255 +800 124 6 1 255 +900 117 21 4 255 +1000 113 30 6 255 +1100 109 39 9 255 +1200 106 45 12 255 +1300 117 64 30 255 +1400 133 88 60 255 +1500 149 113 93 255 +1600 162 144 135 255 +1700 173 173 172 255 +1800 190 190 190 255 +2000 197 196 197 255 +2200 203 203 203 255 +2400 207 206 207 255 +2800 210 209 210 255 +3200 214 212 214 255 +3600 217 215 217 255 +4000 220 219 220 255 +4400 224 222 224 255 +4800 227 225 227 255`; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 5445cb303..0b0554bdf 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -22,7 +22,7 @@ export { TileResizeKernel, TileSetType, } from './config/tile.set.js'; -export { DefaultColorRampOutput, DefaultTerrainRgbOutput } from './config/tile.set.output.js'; +export { DefaultColorRamp, DefaultColorRampOutput, DefaultTerrainRgbOutput } from './config/tile.set.output.js'; export { ConfigTileSetOutputParser } from './config/tile.set.pipeline.js'; export { ConfigVectorStyle, Layer, Sources, StyleJson } from './config/vector.style.js'; export { ConfigBundled, ConfigProviderMemory } from './memory/memory.config.js'; diff --git a/packages/tiler-sharp/package.json b/packages/tiler-sharp/package.json index 8c2a0e0d8..2c480bd8e 100644 --- a/packages/tiler-sharp/package.json +++ b/packages/tiler-sharp/package.json @@ -22,6 +22,7 @@ "test": "node --test" }, "dependencies": { + "@basemaps/config": "^7.0.0", "@basemaps/geo": "^7.0.0", "@basemaps/tiler": "^7.0.0", "@linzjs/metrics": "^7.0.0", diff --git a/packages/tiler-sharp/src/pipeline/pipeline.color.ramp.ts b/packages/tiler-sharp/src/pipeline/pipeline.color.ramp.ts index 5b42a8b49..9bcee3074 100644 --- a/packages/tiler-sharp/src/pipeline/pipeline.color.ramp.ts +++ b/packages/tiler-sharp/src/pipeline/pipeline.color.ramp.ts @@ -1,37 +1,32 @@ +import { DefaultColorRamp } from '@basemaps/config'; import { Tiff } from '@cogeotiff/core'; import { DecompressedInterleaved, Pipeline } from './decompressor.js'; export class ColorRamp { - noData: { v: number; color: [number, number, number, number] } = { v: NaN, color: [0, 0, 0, 0] }; ramps: { v: number; color: [number, number, number, number] }[] = []; - constructor(ramp: string, noDataValue: number) { - const ramps = ramp.split('\n'); + constructor(ramp: string) { + const ramps = ramp.trim().split('\n'); for (const ramp of ramps) { const parts = ramp.trim().split(' '); - if (parts[0] === 'nv') { - this.noData = { v: noDataValue, color: parts.slice(1).map(Number) as [number, number, number, number] }; - continue; - } const numbers = parts.map(Number); this.ramps.push({ v: numbers[0], color: numbers.slice(1) as [number, number, number, number] }); } } get(num: number): [number, number, number, number] { - if (num === this.noData.v) return this.noData.color; - const first = this.ramps[0]; - if (num < first.v) return first.color; + if (num <= first.v) return first.color; for (let i = 0; i < this.ramps.length - 1; i++) { const ramp = this.ramps[i]; - const rampNext = this.ramps[i + 1]; - if (num >= rampNext.v) continue; if (num < ramp.v) continue; if (ramp.v === num) return ramp.color; + const rampNext = this.ramps[i + 1]; + if (num >= rampNext.v) continue; + const range = rampNext.v - ramp.v; const offset = num - ramp.v; const scale = offset / range; @@ -47,23 +42,7 @@ export class ColorRamp { } } -// Stolen from https://github.com/andrewharvey/srtm-stylesheets/blob/master/stylesheets/color-ramps/srtm-Australia-color-ramp.gdaldem.txt -export const ramp = new ColorRamp( - `nv 0 0 0 0 --8764 0 0 0 255 --4000 3 45 85 255 --100 0 101 199 255 -0 192 224 255 255 -1 108 220 108 255 -55 50 180 50 255 -390 240 250 150 255 -835 190 185 135 255 -1114 180 128 107 255 -1392 235 220 220 255 -4000 215 244 244 255 -7000 255 255 255 255`, - -9999, -); +export const ramp = new ColorRamp(DefaultColorRamp); export const PipelineColorRamp: Pipeline = { type: 'color-ramp',