Skip to content

Commit

Permalink
add method to recursively fetch parent layers in ArcGIS Mapservice gr…
Browse files Browse the repository at this point in the history
…oups
  • Loading branch information
sixlighthouses committed Sep 7, 2023
1 parent b14835b commit 8fa0835
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/Models/Catalog/Esri/ArcGisMapServerCatalogGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/ReactViews/DataCatalog/DataCatalogGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class DataCatalogGroup extends React.Component {
render() {
const group = this.props.group;
const { t } = this.props;

return (
<CatalogGroup
text={this.getNameOrPrettyUrl()}
Expand Down

0 comments on commit 8fa0835

Please sign in to comment.