Open FrancescoFilippi opened 4 years ago
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()
https://github.com/stuartmatthews/leaflet-geotiff/blob/be529e0a658bf4f4cdbc528bb7b440dd77f65895/leaflet-geotiff-plotty.js#L25
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,
}
)
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.