Closed CarlQLange closed 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.
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!
OK, will do, I'll give you a shout when I put it up!
@CarlQLange that is exactly what I'm looking for! Is it live yet?
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);
Nothing else to it :)