Skip to content

Commit fba93a9

Browse files
authored
Merge pull request #576 from xcube-dev/clarasb-xxx-levels_rgb_mode
Fix DatasetZLevel in RGB mode
2 parents d3043ea + 84f0b11 commit fba93a9

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Fixed time series legend entry to show the dataset title associated with
66
the time series. (#574)
77

8+
* Show dataset level in the zoom level info box also if no dataset variable is being
9+
displayed (when in RGB-only mode). (#576)
10+
811
## Changes in version 1.7.1
912

1013
### Fixes

src/components/Viewer/Viewer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,14 @@ export default function Viewer({
397397
setDatasetZLevel(datasetZLevel);
398398
}
399399
}
400-
}, [map, variableLayer, setDatasetZLevel]);
400+
}, [
401+
map,
402+
variableLayer,
403+
variable2Layer,
404+
rgbLayer,
405+
rgb2Layer,
406+
setDatasetZLevel,
407+
]);
401408

402409
return (
403410
<ErrorBoundary>

src/components/ol/util.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { default as OlMap } from "ol/Map";
88
import { default as OlLayer } from "ol/layer/Layer";
9+
import OlTileLayer from "ol/layer/Tile";
910

1011
export function findMapLayer(map: OlMap, layerId: string): OlLayer | null {
1112
const layerGroup = map.getLayers();
@@ -17,3 +18,13 @@ export function findMapLayer(map: OlMap, layerId: string): OlLayer | null {
1718
}
1819
return null;
1920
}
21+
22+
export function findDatasetMapLayer(map: OlMap): OlLayer | null {
23+
// Find the first active dataset tile layer named "variable", "rgb",
24+
// "variable2", "rgb2" (in that order)
25+
const layer = (["variable", "rgb", "variable2", "rgb2"] as const)
26+
.map((name) => findMapLayer(map, name))
27+
.find((layer) => layer instanceof OlTileLayer);
28+
29+
return layer as OlLayer;
30+
}

src/model/dataset.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import OlTileLayer from "ol/layer/Tile";
88
import { default as OlMap } from "ol/Map";
99
import { default as OlView } from "ol/View";
1010

11-
import { findMapLayer } from "@/components/ol/util";
11+
import { findDatasetMapLayer } from "@/components/ol/util";
1212
import { GEOGRAPHIC_CRS, WEB_MERCATOR_CRS } from "@/model/proj";
1313
import { type UserVariable } from "@/model/userVariable";
1414
import { type JsonPrimitive } from "@/util/json";
@@ -145,14 +145,15 @@ export function getDatasetTimeRange(dataset: Dataset): TimeRange | null {
145145
return [coordinates[0], coordinates[coordinates.length - 1]];
146146
}
147147

148-
// this returns the level of the current OLTileLayer of the selected variable
148+
// Returns the level of the current OLTileLayer of the selected variable
149149
export const getDatasetZLevel = (
150150
view: OlView,
151151
map: OlMap | undefined,
152152
): number | undefined => {
153153
if (map) {
154154
const resolution = view.getResolution();
155-
const layer = findMapLayer(map, "variable");
155+
156+
const layer = findDatasetMapLayer(map);
156157
if (layer instanceof OlTileLayer) {
157158
const source = layer.getSource();
158159
const tileGrid = source.getTileGrid();

0 commit comments

Comments
 (0)