GeoTIFF / georaster-layer-for-leaflet

Display GeoTIFFs and soon other types of raster on your Leaflet Map
https://geotiff.github.io/georaster-layer-for-leaflet-example/
Apache License 2.0
306 stars 58 forks source link

How specify pixelValuesToColorFn in external file #80

Closed rumski20 closed 3 years ago

rumski20 commented 3 years ago

Hello, thank you for this awesome library!! This issue may due to the fact that I am a bit of a novice with JavaScript. However, I am attempting to define the function I set to pixelValuesToColorFn from an external file. The problem I am encountering is that I can't seem to send any additional arguments (such as the georaster) to the pixelValuesToColorFn function.

For example,

    let colorFn = this._continuousColor

    this.geoRasterLayer = new GeoRasterLayer({
      debugLevel: 1,
      georaster: georaster,
      pixelValuesToColorFn: colorFn(georaster)
    })

......................

  _continuousColor(pixelValues, georaster) {
  // georaster is undefined

Any ideas on how I can define the pixelValuesToColorFn function elsewhere and send it arguments?

Thank you!!

rumski20 commented 3 years ago

Looking a little harder 👀 I found this example: https://github.com/GeoTIFF/georaster-layer-for-leaflet/blob/8716f51e32b02f45cecaf97bfe870b2eb54bd427/tests/dynamic_threshold_ndvi_no_options.html#L80-L82

This worked and solved my problem. Thank you. Not sure if others struggle with this issue (maybe it's a common JS pattern), but you might want to throw a link to it in the documentation.

DanielJDufour commented 3 years ago

Thank you for the write up @rumski20 . This really helps people new to the library :-). I'll try to improve the documentation. It's a common question you had.