@@ -53,23 +53,52 @@ function buildRasterLayer(layer: LayerWithId, titiler_api_url: string): SourcePr
5353 throw new Error ( `Missing required 'url' parameter for raster layer ${ layer . id } ` ) ;
5454 }
5555
56- // Convert bidx string format to array
57- const bidxArray = bidx === BAND_TYPES . RGB ? [ 1 , 2 , 3 , 4 ] : [ 1 ] ;
56+ let tileUrl = ` ${ titiler_api_url } /cog/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?` ;
57+ let extra = '' ;
5858
59- // Add band indices to query parameters
60- bidxArray . forEach ( index => {
61- search . append ( 'bidx' , index . toString ( ) ) ;
62- } ) ;
59+ if ( bidx === BAND_TYPES . SINGLE ) {
60+ if ( ! l . legend ) {
61+ throw Error ( 'Legend should be provided for a single band raster!' ) ;
62+ }
63+ search . append ( 'bidx' , '1' ) ;
64+
65+ // Add rescale values if provided
66+ if ( rescale ?. length ) {
67+ rescale . forEach ( v => {
68+ if ( typeof v === 'string' && v . includes ( ',' ) ) {
69+ search . append ( 'rescale' , v ) ;
70+ } else {
71+ console . warn ( `Invalid rescale value format: ${ v } . Expected format: "min,max"` ) ;
72+ }
73+ } ) ;
74+ }
6375
64- // Add rescale values if provided
65- if ( rescale ?. length ) {
66- rescale . forEach ( v => {
67- if ( typeof v === 'string' && v . includes ( ',' ) ) {
68- search . append ( 'rescale' , v ) ;
76+ // Handle colormap configuration
77+ if ( l . legend . type === 'linear' ) {
78+ if ( l . legend . colormap_name ) {
79+ search . append ( 'colormap_name' , l . legend . colormap_name ) ;
6980 } else {
70- console . warn ( `Invalid rescale value format: ${ v } . Expected format: "min,max" ` ) ;
81+ console . warn ( `Linear legend missing colormap_name for layer ${ layer . id } ` ) ;
7182 }
72- } ) ;
83+ } else if ( l . legend . type === 'interval' ) {
84+ if ( l . legend . intervals ?. length ) {
85+ try {
86+ const cmap = l . legend . intervals . map ( interval => [
87+ [ interval . min , interval . max ] ,
88+ hexRgb ( interval . color , { format : 'array' } ) ,
89+ ] ) ;
90+ extra = `&colormap=${ JSON . stringify ( cmap ) } ` ;
91+ } catch ( error ) {
92+ console . error ( `Failed to process interval colormap for layer ${ layer . id } :` , error ) ;
93+ }
94+ } else {
95+ console . warn ( `Interval legend missing intervals for layer ${ layer . id } ` ) ;
96+ }
97+ }
98+ } else if ( bidx === BAND_TYPES . RGB ) {
99+ search . append ( 'bidx' , '1' ) ;
100+ search . append ( 'bidx' , '2' ) ;
101+ search . append ( 'bidx' , '3' ) ;
73102 }
74103
75104 // Add other titiler parameters
@@ -80,31 +109,7 @@ function buildRasterLayer(layer: LayerWithId, titiler_api_url: string): SourcePr
80109 }
81110 } ) ;
82111
83- // Handle colormap configuration
84- let colormap = '' ;
85- if ( l . legend . type === 'linear' ) {
86- if ( l . legend . colormap_name ) {
87- search . append ( 'colormap_name' , l . legend . colormap_name ) ;
88- } else {
89- console . warn ( `Linear legend missing colormap_name for layer ${ layer . id } ` ) ;
90- }
91- } else if ( l . legend . type === 'interval' ) {
92- if ( l . legend . intervals ?. length ) {
93- try {
94- const cmap = l . legend . intervals . map ( interval => [
95- [ interval . min , interval . max ] ,
96- hexRgb ( interval . color , { format : 'array' } ) ,
97- ] ) ;
98- colormap = `&colormap=${ JSON . stringify ( cmap ) } ` ;
99- } catch ( error ) {
100- console . error ( `Failed to process interval colormap for layer ${ layer . id } :` , error ) ;
101- }
102- } else {
103- console . warn ( `Interval legend missing intervals for layer ${ layer . id } ` ) ;
104- }
105- }
106-
107- const tileUrl = `${ titiler_api_url } /cog/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?${ search . toString ( ) } ${ colormap } ` ;
112+ tileUrl += `${ search . toString ( ) } ${ extra } ` ;
108113
109114 return {
110115 type : LAYER_TYPES . RASTER ,
0 commit comments