Skip to content

Commit

Permalink
Add resolution based on zoom levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design committed Jul 9, 2023
1 parent d6e2b0e commit d14e450
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
34 changes: 27 additions & 7 deletions src/georaster-layer-for-leaflet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
// pad xmax and ymin of container to tolerate ceil() and floor() in snap()
container: inSimpleCRS
? [
extentOfLayer.xmin,
extentOfLayer.ymin - 0.25 * pixelHeight,
extentOfLayer.xmax + 0.25 * pixelWidth,
extentOfLayer.ymax
]
extentOfLayer.xmin,
extentOfLayer.ymin - 0.25 * pixelHeight,
extentOfLayer.xmax + 0.25 * pixelWidth,
extentOfLayer.ymax
]
: [xmin, ymin - 0.25 * pixelHeight, xmax + 0.25 * pixelWidth, ymax],
debug: debugLevel >= 2,
origin: inSimpleCRS ? [extentOfLayer.xmin, extentOfLayer.ymax] : [xmin, ymax],
Expand All @@ -441,8 +441,28 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
const recropTileProj = inSimpleCRS ? recropTileOrig : recropTileOrig.reproj(code);
const recropTile = recropTileProj.crop(extentOfTileInMapCRS);
if (recropTile !== null) {
maxSamplesAcross = Math.ceil(resolution * (recropTile.width / extentOfTileInMapCRS.width));
maxSamplesDown = Math.ceil(resolution * (recropTile.height / extentOfTileInMapCRS.height));
let resolutionValue;

if (typeof resolution === "object") {
const zoomLevels = Object.keys(resolution);
const mapZoom = this.getMap().getZoom();

for (const key in zoomLevels) {
if (Object.prototype.hasOwnProperty.call(zoomLevels, key)) {
const zoomLvl = zoomLevels[key];
if (zoomLvl <= mapZoom) {
resolutionValue = resolution[zoomLvl];
} else {
break;
}
}
}
} else {
resolutionValue = resolution;
}

maxSamplesAcross = Math.ceil(resolutionValue * (recropTile.width / extentOfTileInMapCRS.width));
maxSamplesDown = Math.ceil(resolutionValue * (recropTile.height / extentOfTileInMapCRS.height));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type SimplePoint = {
export type Mask = Feature | FeatureCollection | Polygon | MultiPolygon;

interface GeoRasterLayerOptions_CommonOptions extends GridLayerOptions {
resolution?: number;
resolution?: number | { [key: number]: number };
debugLevel?: DebugLevel;
pixelValuesToColorFn?: PixelValuesToColorFn;
bounds?: LatLngBounds;
Expand Down

0 comments on commit d14e450

Please sign in to comment.