From 8fa0835287fb667cb2785232a6e4b27d4d3d5e01 Mon Sep 17 00:00:00 2001 From: sixlighthouses Date: Thu, 7 Sep 2023 10:18:46 +1000 Subject: [PATCH] add method to recursively fetch parent layers in ArcGIS Mapservice groups --- .../Esri/ArcGisMapServerCatalogGroup.ts | 22 ++++++++++++++++++- .../DataCatalog/DataCatalogGroup.jsx | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Models/Catalog/Esri/ArcGisMapServerCatalogGroup.ts b/lib/Models/Catalog/Esri/ArcGisMapServerCatalogGroup.ts index f6fa4feb4ef..167101e9b14 100644 --- a/lib/Models/Catalog/Esri/ArcGisMapServerCatalogGroup.ts +++ b/lib/Models/Catalog/Esri/ArcGisMapServerCatalogGroup.ts @@ -49,6 +49,18 @@ export class MapServerStratum extends LoadableStratum( ) as this; } + findParentLayers(layerId: number): number[] { + const parentLayerIds: number[] = []; + const layer = this.layers.find((l) => l.id === layerId); + if (layer !== undefined) { + parentLayerIds.push(layer.id); + if (layer.parentLayerId !== -1) { + parentLayerIds.push(...this.findParentLayers(layer.parentLayerId)); + } + } + return parentLayerIds; + } + @computed get name() { if ( this._mapServer.documentInfo && @@ -190,11 +202,12 @@ export class MapServerStratum extends LoadableStratum( } const id = this._catalogGroup.uniqueId; //if parent layer is not -1 then this is sublayer so we define its ID like that - const layerId = + let layerId = id + "/" + (layer.parentLayerId !== -1 ? layer.parentLayerId + "/" : "") + layer.id; + let model: ArcGisMapServerCatalogItem | ArcGisMapServerCatalogGroup; // Treat layer as a group if it has type "Group Layer" - or has subLayers @@ -220,7 +233,14 @@ export class MapServerStratum extends LoadableStratum( ArcGisMapServerCatalogItem, layerId ); + if (existingModel === undefined) { + const parentLayers = this.findParentLayers(layer.id); + + if (parentLayers.length > 0) { + layerId = id + "/" + parentLayers.reverse().join("/"); + } + model = new ArcGisMapServerCatalogItem( layerId, this._catalogGroup.terria diff --git a/lib/ReactViews/DataCatalog/DataCatalogGroup.jsx b/lib/ReactViews/DataCatalog/DataCatalogGroup.jsx index 71deee9d1b6..99b77f8b2fa 100644 --- a/lib/ReactViews/DataCatalog/DataCatalogGroup.jsx +++ b/lib/ReactViews/DataCatalog/DataCatalogGroup.jsx @@ -101,6 +101,7 @@ class DataCatalogGroup extends React.Component { render() { const group = this.props.group; const { t } = this.props; + return (