Skip to content

Commit

Permalink
fix: Preserve composition layer order - in terms of zindex
Browse files Browse the repository at this point in the history
fixes #4679
  • Loading branch information
FilipLeitner authored and jmacura committed Jun 20, 2024
1 parent a9740af commit fe96ab1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
16 changes: 16 additions & 0 deletions projects/hslayers/common/extensions/layer-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const GREYSCALE = 'greyscale';
const HS_LAYMAN_SYNCHRONIZING = 'hsLaymanSynchronizing';
const HS_QML = 'qml';
const HS_SLD = 'sld';
const IGNORE_PATH_ZINDEX = 'ignorePathZIndex';
const INFO_FORMAT = 'info_format';
const INLINE_LEGEND = 'inlineLegend';
const LAYMAN_LAYER_DESCRIPTOR = 'laymanLayerDescriptor';
Expand Down Expand Up @@ -622,6 +623,21 @@ export function setSwipeSide(
layer.set(SWIPE_SIDE, side);
}

/**
* When set to true, prevents z-index to be set based on highest value of layer in
* the same layer (which is default). Used for layers from compositions (basic, permalik)
*/
export function setIgnorePathZIndex(
layer: Layer<Source>,
ignorePathZIndex: boolean,
) {
layer.set(IGNORE_PATH_ZINDEX, ignorePathZIndex);
}

export function getIgnorePathZIndex(layer: Layer<Source>) {
return layer.get(IGNORE_PATH_ZINDEX);
}

export const HsLayerExt = {
getAccessRights,
setAccessRights,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import {
getTitle,
setFromBaseComposition,
setIgnorePathZIndex,
setMetadata,
setSwipeSide,
} from 'hslayers-ng/common/extensions';
Expand Down Expand Up @@ -767,6 +768,7 @@ export class HsCompositionsParserService {
resultLayer = await resultLayer; //createWMTSLayer returns Promise which needs to be resolved first
setMetadata(resultLayer, lyr_def.metadata);
setSwipeSide(resultLayer, lyr_def.swipeSide);
setIgnorePathZIndex(resultLayer, true);
}
return resultLayer;
}
Expand Down
28 changes: 15 additions & 13 deletions projects/hslayers/shared/layer-manager/layer-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getFromBaseComposition,
getFromComposition,
getGreyscale,
getIgnorePathZIndex,
getLegends,
getName,
getPath,
Expand Down Expand Up @@ -196,7 +197,12 @@ export class HsLayerManagerService {
*/
private setupMapEventHandlers(map: Map) {
const onLayerAddition = map.getLayers().on('add', (e) => {
this.applyZIndex(e.element as Layer<Source>, true);
this.applyZIndex(
e.element as Layer<Source>,
//z-index of composition layers should be the same as order of layers in composition.
//ignoring fodler structure
!getIgnorePathZIndex(e.element as Layer<Source>),
);
if (getShowInLayerManager(e.element) == false) {
return;
}
Expand Down Expand Up @@ -449,24 +455,20 @@ export class HsLayerManagerService {
let curfolder = this.data.folders;
const zIndex = lyr.getZIndex();
for (let i = 0; i < parts.length; i++) {
let found = null;
for (const folder of curfolder.sub_folders) {
if (folder.name == parts[i]) {
found = folder;
}
}
if (found === null) {
const found = curfolder.sub_folders.find(
(folder) => folder.name === parts[i],
);
if (!found) {
const hsl_path = `${curfolder.hsl_path}${curfolder.hsl_path !== '' ? '/' : ''}${parts[i]}`;
const coded_path = `${curfolder.coded_path}${curfolder.sub_folders.length}-`;
//TODO: Need to describe how hsl_path works here
const new_folder = {
sub_folders: [],
indent: i,
layers: [],
name: parts[i],
hsl_path:
curfolder.hsl_path +
(curfolder.hsl_path != '' ? '/' : '') +
parts[i],
coded_path: curfolder.coded_path + curfolder.sub_folders.length + '-',
hsl_path,
coded_path,
visible: true,
zIndex: zIndex,
};
Expand Down

0 comments on commit fe96ab1

Please sign in to comment.