Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dig multiples levels in getCapabilities service #141

Merged
merged 2 commits into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Directive, Self, OnInit, OnDestroy,
HostListener } from '@angular/core';
import {
Directive, Self, OnInit, OnDestroy,
HostListener
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

import { MapService } from '../../map';
Expand Down Expand Up @@ -35,18 +37,18 @@ export class CatalogLayersListBindingDirective implements OnInit, OnDestroy {

this.dataSourceService
.createAsyncDataSource(dataSourceContext as AnyDataSourceContext)
.subscribe(dataSource => {
.subscribe(dataSource => {
const layerInstance = this.layerService.createLayer(dataSource, layerContext);
map.addLayer(layerInstance);
});
}

constructor(@Self() component: CatalogLayersListComponent,
private catalogService: CatalogService,
private mapService: MapService,
private dataSourceService: DataSourceService,
private layerService: LayerService,
private capabilitiesService: CapabilitiesService) {
private catalogService: CatalogService,
private mapService: MapService,
private dataSourceService: DataSourceService,
private layerService: LayerService,
private capabilitiesService: CapabilitiesService) {
this.component = component;
}

Expand All @@ -59,6 +61,66 @@ export class CatalogLayersListBindingDirective implements OnInit, OnDestroy {
this.selectedCatalog$$.unsubscribe();
}

/**
* Dig in the layerList for each layer definition
@param catalog: object of config.json parameter
@param layerList: object of current level of layers
@param groupsLayers: object of group of layers to show in the app
*/
includeRecursiveLayer(catalog, layerList, groupsLayers) {
let currentRegFilter;
let boolRegFilter = true;
let objGroupLayers;
// Dig all levels until last level (layer object are not defined on last level)
for (const group of layerList.Layer) {
if (group.queryable === false && typeof group.Layer !== 'undefined') {
// recursive, check next level
this.includeRecursiveLayer(catalog, group, groupsLayers);
} else {
// Define object of group layer
objGroupLayers = {
title: layerList.Title,
// Add only layers with regFilter condition respected
layers: layerList.Layer.reduce((arrLayer, layer) => {
boolRegFilter = true;
// Check for regex validation on layer's name
if (typeof catalog.regFilters !== 'undefined') {
// Test layer.Name for each regex define in config.json
for (const regFilter of catalog.regFilters) {
boolRegFilter = false;
currentRegFilter = new RegExp(regFilter);
boolRegFilter = currentRegFilter.test(layer.Name);
// If regex is respected, stop the for loop
if (boolRegFilter === true) {
break;
}
}
}
// If layer regex is okay (or not define), add the layer to the group
if (boolRegFilter === true) {
arrLayer.push({
title: layer.Title,
type: 'wms',
url: catalog.url,
params: {
layers: layer.Name
}
});
}
return arrLayer;
}, [])
};
/* If object contain layers (when regFilters is define, the condition
in Layer.map can define group with no layer) */
if (objGroupLayers.layers.length !== 0) {
groupsLayers.push(objGroupLayers);
}
// Break the group (don't add a group of layer for each of their layer!)
break;
}
}
}

handleCatalogChanged(catalog: Catalog) {
if (!catalog || !catalog.url) {
return;
Expand All @@ -78,24 +140,8 @@ export class CatalogLayersListBindingDirective implements OnInit, OnDestroy {
const groupsLayers: GroupLayers[] = [];
this.capabilitiesService.getCapabilities('wms', catalog.url)
.subscribe((capabilities) => {
for (const group of capabilities.Capability.Layer.Layer) {
groupsLayers.push({
title: group.Title,
layers: group.Layer.map((layer) => {
return {
title: layer.Title,
type: 'wms',
url: catalog.url,
params: {
layers: layer.Name
}
};
})
});
}

this.includeRecursiveLayer(catalog, capabilities.Capability.Layer, groupsLayers);
this.component.groupsLayers = groupsLayers;
});
}

}
1 change: 1 addition & 0 deletions src/lib/catalog/shared/catalog.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface Catalog {
title?: string;
url?: string;
type?: string;
regFilters?: Array<string>;
}

export interface CatalogServiceOptions {
Expand Down