Skip to content

Commit e51a3b9

Browse files
Merge pull request #130 from Falke-Design/feat/resolutionZoomLevel
Add resolution based on zoom levels
2 parents ec3546b + d14e450 commit e51a3b9

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/georaster-layer-for-leaflet.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,11 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
413413
// pad xmax and ymin of container to tolerate ceil() and floor() in snap()
414414
container: inSimpleCRS
415415
? [
416-
extentOfLayer.xmin,
417-
extentOfLayer.ymin - 0.25 * pixelHeight,
418-
extentOfLayer.xmax + 0.25 * pixelWidth,
419-
extentOfLayer.ymax
420-
]
416+
extentOfLayer.xmin,
417+
extentOfLayer.ymin - 0.25 * pixelHeight,
418+
extentOfLayer.xmax + 0.25 * pixelWidth,
419+
extentOfLayer.ymax
420+
]
421421
: [xmin, ymin - 0.25 * pixelHeight, xmax + 0.25 * pixelWidth, ymax],
422422
debug: debugLevel >= 2,
423423
origin: inSimpleCRS ? [extentOfLayer.xmin, extentOfLayer.ymax] : [xmin, ymax],
@@ -441,8 +441,28 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
441441
const recropTileProj = inSimpleCRS ? recropTileOrig : recropTileOrig.reproj(code);
442442
const recropTile = recropTileProj.crop(extentOfTileInMapCRS);
443443
if (recropTile !== null) {
444-
maxSamplesAcross = Math.ceil(resolution * (recropTile.width / extentOfTileInMapCRS.width));
445-
maxSamplesDown = Math.ceil(resolution * (recropTile.height / extentOfTileInMapCRS.height));
444+
let resolutionValue;
445+
446+
if (typeof resolution === "object") {
447+
const zoomLevels = Object.keys(resolution);
448+
const mapZoom = this.getMap().getZoom();
449+
450+
for (const key in zoomLevels) {
451+
if (Object.prototype.hasOwnProperty.call(zoomLevels, key)) {
452+
const zoomLvl = zoomLevels[key];
453+
if (zoomLvl <= mapZoom) {
454+
resolutionValue = resolution[zoomLvl];
455+
} else {
456+
break;
457+
}
458+
}
459+
}
460+
} else {
461+
resolutionValue = resolution;
462+
}
463+
464+
maxSamplesAcross = Math.ceil(resolutionValue * (recropTile.width / extentOfTileInMapCRS.width));
465+
maxSamplesDown = Math.ceil(resolutionValue * (recropTile.height / extentOfTileInMapCRS.height));
446466
}
447467
}
448468

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type SimplePoint = {
1818
export type Mask = string | Feature | FeatureCollection | Polygon | MultiPolygon;
1919

2020
interface GeoRasterLayerOptions_CommonOptions extends GridLayerOptions {
21-
resolution?: number;
21+
resolution?: number | { [key: number]: number };
2222
debugLevel?: DebugLevel;
2323
pixelValuesToColorFn?: PixelValuesToColorFn;
2424
bounds?: LatLngBounds;

0 commit comments

Comments
 (0)