Skip to content

Commit

Permalink
Merge pull request #129 from Falke-Design/master
Browse files Browse the repository at this point in the history
Add options and methods to README
  • Loading branch information
DanielJDufour authored Jul 10, 2023
2 parents d6e2b0e + 2d48c0b commit ec3546b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ new GeoRasterLayer({ georaster }).addTo(map);
## The GeoRasterLayer Class
A custom class for rendering GeoTIFF's (including COG's) on a leaflet map. The layer extends L.GridLayer, see the [docs](https://leafletjs.com/reference-1.7.1.html#gridlayer) for inherited options and methods.
A custom class for rendering GeoTIFF's (including COG's) on a leaflet map. The layer extends L.GridLayer, see the [docs](https://leafletjs.com/reference.html#gridlayer) for inherited options and methods.
### Usage Example
Expand All @@ -61,6 +61,7 @@ Source Code: <https://github.com/GeoTIFF/georaster-layer-for-leaflet-example/blo
var parse_georaster = require("georaster");
var GeoRasterLayer = require("georaster-layer-for-leaflet");
// or: import GeoRasterLayer from "georaster-layer-for-leaflet";
// initalize leaflet map
var map = L.map('map').setView([0, 0], 5);
Expand All @@ -87,7 +88,7 @@ fetch(url_to_geotiff_file)
Optionally set the pixelValuesToColorFn function option to customize
how values for a pixel are translated to a color.
http://leafletjs.com/reference-1.2.0.html#gridlayer
https://leafletjs.com/reference.html#gridlayer
*/
var layer = new GeoRasterLayer({
georaster: georaster,
Expand All @@ -103,14 +104,46 @@ fetch(url_to_geotiff_file)
});
```
### Options for GeoRasterLayer
> The layer extends L.GridLayer, see the [docs](https://leafletjs.com/reference.html#gridlayer) for inherited options and methods.
| Option | Type | Default | Description |
|----------------------|-------------------------------------------------------------------|---------|------------------------------------------------------------------|
| georaster | GeoRaster | | Use `georaster` from georaster-library. `georaster` or `georasters` is required. |
| georasters | GeoRaster[] | | Use different `georasters` from georaster-library. `georaster` or `georasters` is required. |
| resolution | number | 32 | The resolution parameter is how many samples to take across and down from a dataset for each map tile. Typical tiles are 256 x 256 pixels (higher resolution are 512 x 512) which would be a optimal resolution of 256. It's not recommended to set the resolution higher then 512. |
| debugLevel | number | 0 | Available debug levels: 0 - 5 |
| pixelValuesToColorFn | (values: number[]) => string | null | Customize how values for a pixel are translated to a color. |
| bounds | LatLngBounds | null | https://leafletjs.com/reference.html#latlngbounds |
| proj4 | Function | | https://github.com/proj4js/proj4js |
| resampleMethod | string | nearest | bilinear \| nearest |
| mask | string \| Feature \| FeatureCollection \| Polygon \| MultiPolygon | null | You can hide all the pixels either inside or outside a given mask geometry. You can provide a JSON object as a mask geometry or a URL to a GeoJSON. |
| mask_srs | string \| number | "EPSG:4326" | Default mask srs is the EPSG:4326 projection used by GeoJSON |
| mask_strategy | string | outside | inside \| outside |
| updateWhenIdle | boolean | true | https://leafletjs.com/reference.html#gridlayer-updatewhenidle |
| updateWhenZooming | boolean | false | https://leafletjs.com/reference.html#gridlayer-updatewhenzooming |
| keepBuffer | number | 25 | https://leafletjs.com/reference.html#gridlayer-keepbuffer |
<!-- ## Options -->
<!-- todo: add a table of options for GeoRasterLayer -->
### Methods
| Method | Returns | Description |
| ------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| updateColors(pixelValuesToColorFn, options) | this | Causes the tiles to redraw without clearing them first. It uses the updated `pixelValuesToColorFn` function. You can set a debugLevel specific to this function by passing in an options object with a debugLevel property. For example, you can turn on the console debugs for this method by setting `debugLevel = 1` in the options (even if you created the layer with `debugLevel = 0`). |
| Method | Returns | Description |
|------------------------------------------------------------------|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| getBounds() | LatLngBounds | Returns the bounds of the layer |
| getMap() | Map | Returns the map which contains the layer |
| getMapCRS() | CRS | Returns map CRS if available else EPSG3857 |
| getColor(values: number[]) | string \| undefined | Returns the colors of the values |
| updateColors(pixelValuesToColorFn, options = { debugLevel: -1 }) | this | Causes the tiles to redraw without clearing them first. It uses the updated `pixelValuesToColorFn` function. You can set a debugLevel specific to this function by passing in an options object with a debugLevel property. For example, you can turn on the console debugs for this method by setting `debugLevel = 1` in the options (even if you created the layer with `debugLevel = 0`). |
| getTiles() | Tile[] | Returns tiles as array |
| getActiveTiles() | Tile[] | Returns active / visible tiles as array |
| isSupportedProjection() | boolean | Returns if the projection is supported |
| getProjectionString(projection: number) | string | Returns the projection string for example "EPSG:3857" |
| getProjector() | Projection | Returns the current projection |
## Advanced Capabilities
Expand Down
6 changes: 3 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export type PixelValuesToColorFn = (values: number[]) => string;

export type DebugLevel = 0 | 1 | 2 | 3 | 4 | 5;

export type ResampleMethod = "bilinear" | "near";
export type ResampleMethod = "bilinear" | "nearest";

export type SimplePoint = {
x: number;
y: number;
};

export type Mask = Feature | FeatureCollection | Polygon | MultiPolygon;
export type Mask = string | Feature | FeatureCollection | Polygon | MultiPolygon;

interface GeoRasterLayerOptions_CommonOptions extends GridLayerOptions {
resolution?: number;
Expand Down Expand Up @@ -77,7 +77,7 @@ export type GetValuesOptions = {
right?: number;
top?: number;
width: number;
resampleMethod?: string
resampleMethod?: ResampleMethod
};

export type GeoRasterValues = number[][][];
Expand Down

0 comments on commit ec3546b

Please sign in to comment.