stuartmatthews / leaflet-geotiff

Leaflet plugin for displaying geoTIFF raster data
MIT License
174 stars 76 forks source link

Failed to execute 'addColorStop' on 'CanvasGradient': The provided value (2400) is outside the range (0.0, 1.0) #4

Closed s9eenk closed 6 years ago

s9eenk commented 7 years ago

A DOM Exception is raised while rendering the page . Tried to go through the plotty.js file, but don't know where to change the range.

Any help is appreciated . Thanks in advance.

stuartmatthews commented 7 years ago

Can you please post some example code? Does this error occur when you are creating a custom color scale?

Here is the reference for addColorStop which is throwing the error.

s9eenk commented 7 years ago

Hi Mathews, Exactly , this error occurs when creating a custom color scale. Here , is the code plotty.js "res": { colors: ["#C1CDD7","#63AF61","#B3E287","#F6EB1A","#F1A56A","#F46F16"], positions: [0,1367,2734,4100,5467] } map.html L.leafletGeotiff( url='qasz.tif', options={ band: 1, displayMin: 0, displayMax: 6000, name: 'Sample', colorScale: 'res' } ).addTo(mymap); Note: The pixel values ranges from 0 to 6000.

stuartmatthews commented 7 years ago

The positions array needs to be values from 0 to 1, as per the doc, and must have the same number of entries as the colors array, e.g. [0, 0.2, 0.4, 0.6, 0.8, 0.1]

s9eenk commented 7 years ago

Works !. Great . Thanks Matthews. :+1: I just forgot to put band as 0.