From 814af718211e6cd00555f33472bba2a139bc8595 Mon Sep 17 00:00:00 2001 From: Michael Lane Date: Wed, 2 May 2018 08:46:39 -0400 Subject: [PATCH 1/2] Dig multiples levels in getCapabilities service Add regex filter on layer's name when added by getCapabilities --- .../catalog-layers-list-binding.directive.ts | 97 ++++++++++++++----- src/lib/catalog/shared/catalog.interface.ts | 1 + 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts b/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts index c5c70c741c..3aaf2d8510 100644 --- a/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts +++ b/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts @@ -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'; @@ -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; } @@ -59,6 +61,67 @@ 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(function(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; @@ -78,24 +141,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; }); } - } diff --git a/src/lib/catalog/shared/catalog.interface.ts b/src/lib/catalog/shared/catalog.interface.ts index 6d3db36579..9719db824a 100644 --- a/src/lib/catalog/shared/catalog.interface.ts +++ b/src/lib/catalog/shared/catalog.interface.ts @@ -3,6 +3,7 @@ export interface Catalog { title?: string; url?: string; type?: string; + regFilters?: Array; } export interface CatalogServiceOptions { From b518a41da47e4db424ad8c13ea32f5f81d8ee583 Mon Sep 17 00:00:00 2001 From: Michael Lane Date: Wed, 2 May 2018 11:14:10 -0400 Subject: [PATCH 2/2] correction to respect npm test --- .../catalog-layers-list-binding.directive.ts | 79 +++++++++---------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts b/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts index 3aaf2d8510..a239427101 100644 --- a/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts +++ b/src/lib/catalog/catalog-layers-list/catalog-layers-list-binding.directive.ts @@ -71,52 +71,51 @@ export class CatalogLayersListBindingDirective implements OnInit, OnDestroy { let currentRegFilter; let boolRegFilter = true; let objGroupLayers; - //Dig all levels until last level (layer object are not defined on last level) + // 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 + 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(function(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; - } + } 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) { + } + // 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 the group (don't add a group of layer for each of their layer!) break; } }