Skip to content

Commit 7000739

Browse files
committed
Fix zoom and add test
1 parent e51a3b9 commit 7000739

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/georaster-layer-for-leaflet.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,11 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
445445

446446
if (typeof resolution === "object") {
447447
const zoomLevels = Object.keys(resolution);
448-
const mapZoom = this.getMap().getZoom();
449448

450449
for (const key in zoomLevels) {
451450
if (Object.prototype.hasOwnProperty.call(zoomLevels, key)) {
452451
const zoomLvl = zoomLevels[key];
453-
if (zoomLvl <= mapZoom) {
452+
if (zoomLvl <= zoom) {
454453
resolutionValue = resolution[zoomLvl];
455454
} else {
456455
break;

tests/resolution-zoom.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1" />
5+
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
6+
<style>
7+
#map {
8+
bottom: 0;
9+
left: 0;
10+
position: absolute;
11+
right: 0;
12+
top: 0;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<div id="map"></div>
18+
<script src="https://unpkg.com/browse/whatwg-fetch@3.2.0/dist/fetch.umd.js"></script>
19+
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
20+
<script src="https://unpkg.com/georaster"></script>
21+
<script src="../dist/georaster-layer-for-leaflet.min.js"></script>
22+
<script>
23+
// initalize leaflet map
24+
var map = L.map("map").setView([0, 0], 5);
25+
26+
// add OpenStreetMap basemap
27+
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
28+
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
29+
}).addTo(map);
30+
31+
var url_to_geotiff_file = "https://geotiff.github.io/georaster-layer-for-leaflet-example/example_4326.tif";
32+
33+
fetch(url_to_geotiff_file)
34+
.then(function (response) {
35+
return response.arrayBuffer();
36+
})
37+
.then(function (arrayBuffer) {
38+
parseGeoraster(arrayBuffer).then(function (georaster) {
39+
console.log("georaster:", georaster);
40+
var layer = new GeoRasterLayer({
41+
georaster: georaster,
42+
resolution: {
43+
0: 2, // Zoom level 0 or higher: resolution 2
44+
16: 512 // Zoom level 16 or higher: resolution 512
45+
}
46+
});
47+
layer.addTo(map);
48+
map.fitBounds(layer.getBounds());
49+
});
50+
});
51+
</script>
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)