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
  • Loading branch information
FilipLeitner authored and jmacura committed Feb 7, 2024
1 parent 25fa263 commit 7b34fd4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
16 changes: 16 additions & 0 deletions projects/hslayers/src/common/layer-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -679,6 +680,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 @@ -36,6 +36,7 @@ import {
import {
getTitle,
setFromBaseComposition,
setIgnorePathZIndex,
setMetadata,
setSwipeSide,
} from '../../common/layer-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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {HsCompositionsMapService} from './compositions-map.service';
import {HsCompositionsMickaService} from './endpoints/compositions-micka.service';
import {HsCompositionsParserService} from './compositions-parser.service';
import {HsConfig} from '../../config.service';
import {HsCoreService} from '../core/core.service';
import {HsEndpoint} from '../../common/endpoints/endpoint.interface';
import {HsEventBusService} from '../core/event-bus.service';
import {HsLanguageService} from '../language/language.service';
Expand All @@ -36,7 +35,6 @@ export class HsCompositionsService {
constructor(
private http: HttpClient,
private hsMapService: HsMapService,
private hsCore: HsCoreService,
private hsCompositionsParserService: HsCompositionsParserService,
private hsConfig: HsConfig,
private hsUtilsService: HsUtilsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getActive,
getAttribution,
getFromBaseComposition,
getIgnorePathZIndex,
getShowInLayerManager,
getThumbnail,
getTitle,
Expand Down Expand Up @@ -182,7 +183,9 @@ export class HsLayerManagerComponent
.on('add', (e) => {
this.hsLayerManagerService.applyZIndex(
e.element as Layer<Source>,
true,
//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
Original file line number Diff line number Diff line change
Expand Up @@ -507,24 +507,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) {
//TODO: Need to describe how hsl_path works here
const hsl_path = `${curfolder.hsl_path}${curfolder.hsl_path !== '' ? '/' : ''}${parts[i]}`;
const coded_path = `${curfolder.coded_path}${curfolder.sub_folders.length}-`;
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 All @@ -543,7 +539,6 @@ export class HsLayerManagerService {

/**
* Remove layer from layer folder structure a clean empty folder
* @private
* @param lyr - Layer to remove from layer folder
*/
cleanFolders(lyr: Layer<Source>): void {
Expand Down

0 comments on commit 7b34fd4

Please sign in to comment.