diff --git a/demo/src/app/geo/spatial-filter/spatial-filter.component.ts b/demo/src/app/geo/spatial-filter/spatial-filter.component.ts index d857b2e30d..d556d8227b 100644 --- a/demo/src/app/geo/spatial-filter/spatial-filter.component.ts +++ b/demo/src/app/geo/spatial-filter/spatial-filter.component.ts @@ -209,7 +209,6 @@ export class AppSpatialFilterComponent { for (const feature of features) { if (this.type === SpatialFilterType.Predefined) { for (const layer of this.map.layers) { - console.log(layer); if ( layer.options._internal && layer.options._internal.code === feature.properties.code diff --git a/packages/geo/src/lib/catalog/shared/catalog.abstract.ts b/packages/geo/src/lib/catalog/shared/catalog.abstract.ts index eff26dd1fa..9475bbc000 100644 --- a/packages/geo/src/lib/catalog/shared/catalog.abstract.ts +++ b/packages/geo/src/lib/catalog/shared/catalog.abstract.ts @@ -79,6 +79,18 @@ class BaselayersCatalog extends Catalog { } } +class ArcGISRestCatalog extends Catalog { + constructor(options: Catalog, service: CatalogService) { + super(options, service); + const sType: string = TypeCatalog[TypeCatalog.arcgisrest]; + this.type = TypeCatalog[sType]; + } + + public collectCatalogItems() { + return this.catalogService.loadCatalogArcGISRestItems(this); + } +} + export class CompositeCatalog extends Catalog implements ICompositeCatalog { composite: ICatalog[]; @@ -103,6 +115,8 @@ export class CatalogFactory { catalog = new CompositeCatalog(options, service); } else if (options.type === TypeCatalog[TypeCatalog.baselayers]) { catalog = new BaselayersCatalog(options, service); + } else if (options.type === TypeCatalog[TypeCatalog.arcgisrest]) { + catalog = new ArcGISRestCatalog(options, service); } else if (options.type === TypeCatalog[TypeCatalog.wmts]) { catalog = new WMTSCatalog(options, service); } else { diff --git a/packages/geo/src/lib/catalog/shared/catalog.enum.ts b/packages/geo/src/lib/catalog/shared/catalog.enum.ts index c31517feb6..cda367920a 100644 --- a/packages/geo/src/lib/catalog/shared/catalog.enum.ts +++ b/packages/geo/src/lib/catalog/shared/catalog.enum.ts @@ -4,7 +4,7 @@ export enum CatalogItemType { } export enum TypeCatalog { - wms, wmts, baselayers, composite + wms, wmts, baselayers, arcgisrest, composite } export type TypeCatalogStrings = keyof typeof TypeCatalog; diff --git a/packages/geo/src/lib/catalog/shared/catalog.service.ts b/packages/geo/src/lib/catalog/shared/catalog.service.ts index e2420d5a8f..9de894e981 100644 --- a/packages/geo/src/lib/catalog/shared/catalog.service.ts +++ b/packages/geo/src/lib/catalog/shared/catalog.service.ts @@ -10,7 +10,8 @@ import { TypeCapabilities, WMSDataSourceOptions, WMSDataSourceOptionsParams, - WMTSDataSourceOptions + WMTSDataSourceOptions, + ArcGISRestDataSourceOptions } from '../../datasource'; import { LayerOptions, ImageLayerOptions } from '../../layer'; import { getResolutionFromScale } from '../../map'; @@ -23,7 +24,7 @@ import { import { Catalog, CatalogFactory, CompositeCatalog } from './catalog.abstract'; import { CatalogItemType, TypeCatalog } from './catalog.enum'; import { QueryFormat } from '../../query'; -import { generateIdFromSourceOptions } from '../../utils'; +import { generateIdFromSourceOptions, generateId } from '../../utils'; @Injectable({ providedIn: 'root' @@ -148,6 +149,14 @@ export class CatalogService { ); } + loadCatalogArcGISRestItems(catalog: Catalog): Observable { + return this.getCatalogCapabilities(catalog).pipe( + map((capabilities: any) => { + return this.getArcGISRESTItems(catalog, capabilities) + }) + ); + } + loadCatalogCompositeLayerItems(catalog: Catalog): Observable { const compositeCatalog = (catalog as CompositeCatalog).composite; @@ -508,6 +517,50 @@ export class CatalogService { .filter((item: CatalogItemLayer | undefined) => item !== undefined); } + private getArcGISRESTItems( + catalog: Catalog, + capabilities + ): CatalogItemLayer[] { + const layers = capabilities.layers; + const regexes = (catalog.regFilters || []).map( + (pattern: string) => new RegExp(pattern) + ); + + return layers + .map((layer: any) => { + if (this.testLayerRegexes(layer.id, regexes) === false) { + return undefined; + } + const baseSourceOptions = { + type: 'arcgisrest', + url: catalog.url, + crossOrigin: catalog.setCrossOriginAnonymous + ? 'anonymous' + : undefined, + layer: layer.id as string, + matrixSet: catalog.matrixSet, + optionsFromCapabilities: true, + style: 'default' + } as ArcGISRestDataSourceOptions; + const sourceOptions = Object.assign( + {}, + baseSourceOptions, + catalog.sourceOptions + ) as ArcGISRestDataSourceOptions; + + return ObjectUtils.removeUndefined({ + id: generateIdFromSourceOptions(sourceOptions), + type: CatalogItemType.Layer, + title: layer.name, + address: catalog.id, + options: { + sourceOptions + } + }); + }) + .filter((item: CatalogItemLayer | undefined) => item !== undefined); + } + private testLayerRegexes(layerName: string, regexes: RegExp[]): boolean { if (regexes.length === 0) { return true; diff --git a/packages/geo/src/lib/datasource/shared/capabilities.service.ts b/packages/geo/src/lib/datasource/shared/capabilities.service.ts index 68fd55382b..5c19d8ea32 100644 --- a/packages/geo/src/lib/datasource/shared/capabilities.service.ts +++ b/packages/geo/src/lib/datasource/shared/capabilities.service.ts @@ -4,7 +4,7 @@ import { Observable, forkJoin, of } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; import { Cacheable } from 'ngx-cacheable'; -import { WMSCapabilities, WMTSCapabilities } from 'ol/format'; +import { WMSCapabilities, WMTSCapabilities, EsriJSON } from 'ol/format'; import { optionsFromCapabilities } from 'ol/source/WMTS.js'; import olAttribution from 'ol/control/Attribution'; @@ -34,7 +34,8 @@ import { export enum TypeCapabilities { wms = 'wms', - wmts = 'wmts' + wmts = 'wmts', + arcgisrest = 'esriJSON' } export type TypeCapabilitiesStrings = keyof typeof TypeCapabilities; @@ -45,7 +46,8 @@ export type TypeCapabilitiesStrings = keyof typeof TypeCapabilities; export class CapabilitiesService { private parsers = { wms: new WMSCapabilities(), - wmts: new WMTSCapabilities() + wmts: new WMTSCapabilities(), + esriJSON: new EsriJSON() }; constructor(private http: HttpClient) {} @@ -154,14 +156,22 @@ export class CapabilitiesService { } }); - const request = this.http.get(baseUrl, { - params, - responseType: 'text' - }); + let request; + if ((service as any) === 'esriJSON') { + request = this.http.get(baseUrl + '?f=json'); + } else { + request = this.http.get(baseUrl, { + params, + responseType: 'text' + }); + } return request.pipe( map(res => { try { + if ((service as any) === 'esriJSON') { + return res; + } return this.parsers[service].read(res); } catch (e) { return undefined; @@ -293,6 +303,7 @@ export class CapabilitiesService { arcgisOptions: any, legend?: any ): ArcGISRestDataSourceOptions { + const title = arcgisOptions.name; const legendInfo = legend.layers ? legend : undefined; const styleGenerator = new EsriStyleGenerator(); const units = arcgisOptions.units === 'esriMeters' ? 'm' : 'degrees'; @@ -328,7 +339,10 @@ export class CapabilitiesService { } ); const options = ObjectUtils.removeUndefined({ - params + params, + _layerOptionsFromSource: { + title + } }); return ObjectUtils.mergeDeep(options, baseOptions); }