stuartmatthews / leaflet-geotiff

Leaflet plugin for displaying geoTIFF raster data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use the addColorScale function?

FrancescoFilippi opened this issue · comments

How am i supposed to add a custom color scale using plotty's addColorScale function? README says this can be done, but I can't figure out how.
A more comprehensive example would be great.

How am i supposed to add a custom color scale using plotty's addColorScale function? README says this can be done, but I can't figure out how.
A more comprehensive example would be great.

Were you able to figure this out?

@prashanthkul Sorta, I added a custom color scale into the initialize function, just before setOptions()

L.setOptions(this, options);

Something like

initialize: function(options) {
    if (typeof (plotty) === 'undefined') {
	throw new Error("plotty not defined");
    }
    this.name = "Plotty";

    ==> plotty.addColorScale('custom_name', ["#FFFFFF", "#FF0000", ....], [0 , .... , 1]);
    
    L.setOptions(this, options);
        this._preLoadColorScale();
    }

Then you are able to reference the custom scale into the LeafletGeotiff() options, just like any other built-in color scale

const options = {
    band: ...,
    name: ...,
    opacity: ...,
    renderer: new plotty.Plotty({
       colorScale: 'custom_name'
    })
};
this.geotiffLayer = new geotiff.LeafletGeotiff(url, options);

Still don't know if there's a better solution, but it works.

Here is what I did, which seems to be working fine:

import * as plotty from 'plotty'

plotty.addColorScale('myscale', ['#00ff00', '#0000ff', '#ff0000'], [0, 0.5, 1])
const renderer = L.LeafletGeotiff.plotty({
  colorScale: 'myscale',
})

const instance = L.leafletGeotiff(
  'your-url.tif',
  {
    renderer: renderer,
  }
)