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
303 stars 58 forks source link

Allow transparency without a Mask via pixelValuesToColorFn #145

Closed jfoclpf closed 7 months ago

jfoclpf commented 7 months ago

First of all PROPS for you guys for developing this GREAT AND FREE tool, thanks a lot

Is your feature request related to a problem? I have this elevation map with lots of zeros mapped to white, it would be nice to have transparency for values under zero, for example

image

Describe the solution you'd like

Allowing transparency without the need for an external GeoJSON mask via pixelValuesToColorFn

      var layer = new GeoRasterLayer({
          georaster: georaster,
          opacity: 0.7,
          pixelValuesToColorFn: values => values[0] < 0 ? 'transparent' : '#ffffff',
          resolution: 64 // optional parameter for adjusting display resolution
      });

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Use an external GeoJSON file for the mask

Additional context Working example I just made using your tool: https://stackoverflow.com/a/78298578/1243247

Again, thanks a lot for the great tool

jfoclpf commented 7 months ago

Found it :) null was the trick, perhaps docs should be more clear

      const layer = new GeoRasterLayer({
        georaster: georaster,
        opacity: 0.7,
        pixelValuesToColorFn: vals => Math.round(vals[0]) < 1 ? null : '#ffffff',
        resolution: 512 // optional parameter for adjusting display resolution
      }).addTo(map)

again, congrats for the great work @DanielJDufour

DanielJDufour commented 7 months ago

@jfoclpf , would you be open to submitting a PR, adding this example to https://github.com/GeoTIFF/georaster-layer-for-leaflet-example

?

jfoclpf commented 7 months ago

@jfoclpf , would you be open to submitting a PR, adding this example to https://github.com/GeoTIFF/georaster-layer-for-leaflet-example

?

sure, I will do it ASAP

jfoclpf commented 7 months ago

@DanielJDufour I already submitted 3 PRs as you requested, tell me what you think