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

Add debugLevel check for some console.logs #22

Closed CarlQLange closed 5 years ago

CarlQLange commented 5 years ago

Nothing else to it :)

CarlQLange commented 5 years ago

Unrelated to this PR, I have written a React-Leaflet component for this library. Would you like me to contribute it directly here? It's only a wrapper around the library, but it would still want to be kept up-to-date with new options etc. I'm also happy to create a repo for it myself in case you don't want to support it. Thanks for such a useful library.

DanielJDufour commented 5 years ago

Awesome! I would recommend keeping it separate from this library, but I'd love to contribute to it and help keep it up to date!

CarlQLange commented 5 years ago

OK, will do, I'll give you a shout when I put it up!

zvikarp commented 5 years ago

@CarlQLange that is exactly what I'm looking for! Is it live yet?

CarlQLange commented 5 years ago

Here are a few lines that'll do it for you!

import { GridLayer, withLeaflet, GridLayerProps } from "react-leaflet";
import chroma from "chroma-js";
import GeoRasterLayerRaw from "georaster-layer-for-leaflet";

class GeoRasterLayer extends GridLayer<
    GridLayerProps & { georaster: any; resolution?: number; transparency?: number; scale?: string; domain?: number[] }
> {
    createLeafletElement(props) {
        let domain = this.props.domain || [0, 0.0001];
        let scale = chroma.scale(this.props.scale || "Viridis").domain(domain);

        let { noDataValue } = this.props.georaster;

        return new GeoRasterLayerRaw({
            debugLevel: 0,
            georaster: this.props.georaster,
            opacity: this.props.transparency,
            resolution: this.props.resolution,
            keepBuffer: 25,
            pixelValuesToColorFn: values => {
                if (values.every(value => value === noDataValue || value <= 0 || value > 1)) {
                    return scale(domain[1]);
                } else {
                    return scale(values[0]);
                }
            }
        });
    }
}

export default withLeaflet(GeoRasterLayer);