leaflet-geotiff-2
A LeafletJS plugin for displaying geoTIFF raster data. Data can drawn as colored rasters or directon arrows. The layer can be clipped using a polygon.
Version 1 Notice
As of version 1, leaflet-geotiff-2
is now under CSIRO's Open Source Software Licence Agreement, which is a variation of the BSD / MIT License.
There are no other plans for changes to licensing, and the project will remain open source.
Instructions
1. Load modules
Dependencies must be loaded:
import "leaflet-geotiff-2";
import "leaflet-geotiff-2/dist/leaflet-geotiff-rgb";
import "leaflet-geotiff-2/dist/leaflet-geotiff-vector-arrows";
import "leaflet-geotiff-2/dist/leaflet-geotiff-plotty";
2. Add a geoTIFF layer
Parameters:
const url =
"https://stuartmatthews.github.io/leaflet-geotiff/tif/wind_speed.tif";
const options = {
renderer: null,
useWorker: false,
bounds: [],
band: 0,
image: 0,
clip: undefined,
pane: "overlayPane",
onError: null,
sourceFunction: GeoTIFF.fromUrl,
arrayBuffer: null,
noDataValue: undefined,
noDataKey: undefined,
blockSize: 65536,
opacity: 1,
clearBeforeMove: false,
};
var layer = L.leafletGeotiff(url, options).addTo(map);
Methods - L.leafletGeotiff
method | params | description |
---|
getBounds | | get leaflet LatLngBounds of the layer |
getMinMax | | get min max values in data (ignores noDataValue if defined) |
getValueAtLatLng | (lat: {Number}, lng: {Number} ) | get raster value at a point* |
Renderer - Plotty
Useful for single-band raster data.
const options = {
displayMin: 0,
displayMax: 1,
applyDisplayRange: true,
clampLow: true,
clampHigh: true,
colorScale: "viridis",
};
const renderer = L.LeafletGeotiff.plotty(options);
Methods - leafletGeotiff.plotty
method | params | description |
---|
setColorScale | (colorScale: {String} ) | set layer color scale |
setDisplayRange | (min: {Number}, max: {Number} ) | set layer display range |
setClamps | (clampLow: {Boolean}, clampLow: {Boolean} ) | set layer clamp options |
getColourbarDataUrl | (paletteName: {String} ) | get a data URI for a color palette (e.g. to display colorbar). |
getColorbarOptions | | get list of available color palettes |
New color scales can be created using plotty's addColorScale
method.
Renderer - RGB
Useful for multi-band raster data (e.g. true color).
RGB renderer options must currently be added by extending L.leafletGeotiff
options.
const renderer = L.LeafletGeotiff.rgb();
const options = {
rBand: 0,
gBand: 1,
bBand: 2,
alphaBand: 0,
transpValue: 0,
renderer: renderer,
};
var layer = L.leafletGeotiff(url, options).addTo(map);
Renderer - Vector Arrows
For plotting velocity (i.e. quiver plot)
const options = {
arrowSize: 20,
};
const renderer = L.LeafletGeotiff.vectorArrows(options);
Advanced usage options
- Custom renderer can be implemented by extending
L.LeafletGeotiffRenderer
.
Build
npm install
npm run build
What about the original leaflet-geotiff?
This repo is an attempt to pull together a bunch of community-driven improvements that
have been made in various forks of leaflet-geotiff
over the years but have failed to
make it back into the leaflet-geotiff
npm package, and to provide a place for active development for new features.
License
CSIRO Open Source Software Licence Agreement (variation of the BSD / MIT License)