Select to view content in your preferred language

colorRamps.byName("Blue 6") doesn’t work with rasterstretchrenderer

347
2
Jump to solution
03-11-2024 07:05 AM
Nicolas_
Occasional Contributor

Hello,

I have setup the following renderer for my raster layer. It works very well:

 

let rendererRaster = new RasterStretchRenderer({
    statistics: [[0, 100, 0, 0]],
    stretchType: "min-max",
    colorRamp: new MultipartColorRamp({
        colorRamps: [
            { algorithm: "cie-lab", fromColor: new Color([255, 255, 217, 255]), toColor: new Color([199, 233, 180, 255]) },
            { algorithm: "cie-lab", fromColor: new Color([199, 233, 180, 255]), toColor: new Color([127, 205, 187, 255]) },
            { algorithm: "cie-lab", fromColor: new Color([127, 205, 187, 255]), toColor: new Color([65, 182, 196, 255]) },
            { algorithm: "cie-lab", fromColor: new Color([65, 182, 196, 255]), toColor: new Color([29, 145, 192, 255]) },
            { algorithm: "cie-lab", fromColor: new Color([29, 145, 192, 255]), toColor: new Color([34, 94, 168, 255]) },
            { algorithm: "cie-lab", fromColor: new Color([34, 94, 168, 255]), toColor: new Color([37, 52, 148, 255]) },
            { algorithm: "cie-lab", fromColor: new Color([37, 52, 148, 255]), toColor: new Color([8, 29, 88, 2555]) },
        ]
    })
});

 

 

But now I would like to use the preset colorramps that you show here: https://developers.arcgis.com/javascript/latest/visualization/symbols-color-ramps/esri-color-ramps/#... 

So I try doing the following, but It doesn't work (the raster is shown as black and white):

 

let rendererRaster = new RasterStretchRenderer({
    statistics: [[0, 100, 0, 0]],
    stretchType: "min-max",
    colorRamp: colorRamps.byName("Blue 6")
});

 

 How can I use the preset coloramps?

0 Kudos
1 Solution

Accepted Solutions
Nicolas_
Occasional Contributor

Following the example you provided, I changed my code to:

 

let rendererRaster = new RasterStretchRenderer({
    statistics: [[40, 145, 0, 0]],
    stretchType: "min-max",
    colorRamp: colorRamps.createColorRamp(colorRamps.byName("Precipitation"))
});

 

This work. Do note that Typescript is expecting ".colors" after "byName". This is wrong and I had to add //ts-ignore above the line.

I see that the named colorramps are limited to about 50 ramps compared to 512 ramps on the website. Is this a bug? For exemple, the ramp "Blue 6" doesn't seems to work in my code.

Edit: For my last question, I see that the ramps in "@arcgis/core/smartMapping/raster/support/colorRamps" are not the same as "@arcgis/core/smartMapping/symbology/support/colorRamps". Thats why "Blue 6" doesn't exist for rasters.

View solution in original post

0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

The smartMapping colorRamps return array of colors so you'd have to pass the colors to the fromColors to toColors. At 4.29, we introduced esri/smartMapping/raster/support/colorRamps and they are used to create colorRamps for raster renderers. This sample shows how to use it: https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-imagery-renderer

 

0 Kudos
Nicolas_
Occasional Contributor

Following the example you provided, I changed my code to:

 

let rendererRaster = new RasterStretchRenderer({
    statistics: [[40, 145, 0, 0]],
    stretchType: "min-max",
    colorRamp: colorRamps.createColorRamp(colorRamps.byName("Precipitation"))
});

 

This work. Do note that Typescript is expecting ".colors" after "byName". This is wrong and I had to add //ts-ignore above the line.

I see that the named colorramps are limited to about 50 ramps compared to 512 ramps on the website. Is this a bug? For exemple, the ramp "Blue 6" doesn't seems to work in my code.

Edit: For my last question, I see that the ramps in "@arcgis/core/smartMapping/raster/support/colorRamps" are not the same as "@arcgis/core/smartMapping/symbology/support/colorRamps". Thats why "Blue 6" doesn't exist for rasters.

0 Kudos