Skip to content

Commit

Permalink
feat(catalog): arcgis rest data catalog (#709)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* WIP

* WIP

* feat(catalog): Allow arcGISRest data catalog

* unnecessary changes
  • Loading branch information
PhilippeLafreniere18 authored and Marc-André Barbeau committed Sep 8, 2020
1 parent afde233 commit 2af389a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/geo/src/lib/catalog/shared/catalog.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/catalog/shared/catalog.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
57 changes: 55 additions & 2 deletions packages/geo/src/lib/catalog/shared/catalog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
TypeCapabilities,
WMSDataSourceOptions,
WMSDataSourceOptionsParams,
WMTSDataSourceOptions
WMTSDataSourceOptions,
ArcGISRestDataSourceOptions
} from '../../datasource';
import { LayerOptions, ImageLayerOptions } from '../../layer';
import { getResolutionFromScale } from '../../map';
Expand All @@ -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'
Expand Down Expand Up @@ -148,6 +149,14 @@ export class CatalogService {
);
}

loadCatalogArcGISRestItems(catalog: Catalog): Observable<CatalogItem[]> {
return this.getCatalogCapabilities(catalog).pipe(
map((capabilities: any) => {
return this.getArcGISRESTItems(catalog, capabilities)
})
);
}

loadCatalogCompositeLayerItems(catalog: Catalog): Observable<CatalogItem[]> {
const compositeCatalog = (catalog as CompositeCatalog).composite;

Expand Down Expand Up @@ -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;
Expand Down
30 changes: 22 additions & 8 deletions packages/geo/src/lib/datasource/shared/capabilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -34,7 +34,8 @@ import {

export enum TypeCapabilities {
wms = 'wms',
wmts = 'wmts'
wmts = 'wmts',
arcgisrest = 'esriJSON'
}

export type TypeCapabilitiesStrings = keyof typeof TypeCapabilities;
Expand All @@ -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) {}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -328,7 +339,10 @@ export class CapabilitiesService {
}
);
const options = ObjectUtils.removeUndefined({
params
params,
_layerOptionsFromSource: {
title
}
});
return ObjectUtils.mergeDeep(options, baseOptions);
}
Expand Down

0 comments on commit 2af389a

Please sign in to comment.