Skip to content

Commit

Permalink
add unit test for sortByDisplayOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
arnevogt committed Dec 19, 2024
1 parent 664ff1d commit 2f69470
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/packages/map/model/LayerCollectionImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,45 @@ it("it should return all operational layers including children", async () => {
expect(topLevelOperationalLayers.length).toBe(1); //group
});

it("it should return all layers including children ordered by display order (asc)", async () => {
const olBase = new TileLayer({
source: new OSM()
});
const base = new SimpleLayerImpl({
id: "base",
title: "baselayer",
olLayer: olBase,
isBaseLayer: true
});

const olLayer = new TileLayer({
source: new OSM()
});
const child = new SimpleLayerImpl({
id: "member",
title: "group member",
olLayer: olLayer
});
const group = new GroupLayer({
id: "group",
title: "group test",
layers: [child]
});

model = await create("foo", {
layers: [base, group]
});

const allLayers = model.layers.getAllLayers({
includeChildLayers: true,
sortByDisplayOrder: true
});
expect(allLayers.length).toBe(3);
expect(allLayers[0]).toBe(base);
expect(allLayers[1]).toBe(child);
expect(allLayers[2]).toBe(group);
});

function getLayerProps(layer: Layer) {
return {
title: layer.title,
Expand Down
3 changes: 1 addition & 2 deletions src/packages/map/model/LayerCollectionImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ function getZIndexForAnyLayer(layer: AnyLayer): number {
}
}


//if layer has no zIndex, find nearest parent with zIndex
let parent = layer.parent;
while (parent) {
Expand All @@ -364,7 +363,7 @@ function getZIndexForAnyLayer(layer: AnyLayer): number {
return parentLayerZIndex;
}
parent = parent.parent;
}else{
} else {
parent = parent.parentLayer; //no need to traverse nested sublayers -> directly jump to parent layer of sublayer
}
}
Expand Down

0 comments on commit 2f69470

Please sign in to comment.