From 1278cef19772558b8f8785f5f4d5d9466bb43d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Mon, 24 Feb 2020 07:57:46 -0500 Subject: [PATCH] feat(datasource): retrieve query format from capabilities (#582) * query format from capabilities * lint * fix(geojson2): extract * Update capabilities.service.ts --- .../datasource/shared/capabilities.service.ts | 33 ++++++++++++++- .../geo/src/lib/query/shared/query.enums.ts | 13 ++++++ .../geo/src/lib/query/shared/query.service.ts | 41 ++++++------------- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/packages/geo/src/lib/datasource/shared/capabilities.service.ts b/packages/geo/src/lib/datasource/shared/capabilities.service.ts index 95e0699347..5a238fdf9a 100644 --- a/packages/geo/src/lib/datasource/shared/capabilities.service.ts +++ b/packages/geo/src/lib/datasource/shared/capabilities.service.ts @@ -11,6 +11,10 @@ import olAttribution from 'ol/control/Attribution'; import { ObjectUtils } from '@igo2/utils'; import { getResolutionFromScale } from '../../map'; import { EsriStyleGenerator } from '../utils/esri-style-generator'; +import { + QueryFormat, + QueryFormatMimeType +} from '../../query/shared/query.enums'; import { WMTSDataSourceOptions, @@ -29,7 +33,8 @@ import { } from '../../filter/shared/time-filter.enum'; export enum TypeCapabilities { - wms = 'wms', wmts = 'wmts' + wms = 'wms', + wmts = 'wmts' } export type TypeCapabilitiesStrings = keyof typeof TypeCapabilities; @@ -182,11 +187,34 @@ export class CapabilitiesService { const metadata = layer.DataURL ? layer.DataURL[0] : undefined; const abstract = layer.Abstract ? layer.Abstract : undefined; const keywordList = layer.KeywordList ? layer.KeywordList : undefined; - const queryable = layer.queryable; + let queryable = layer.queryable; const timeFilter = this.getTimeFilter(layer); const timeFilterable = timeFilter && Object.keys(timeFilter).length > 0; const legendOptions = layer.Style ? this.getStyle(layer.Style) : undefined; + let queryFormat: QueryFormat; + const queryFormatMimeTypePriority = [ + QueryFormatMimeType.GEOJSON, + QueryFormatMimeType.GEOJSON2, + QueryFormatMimeType.GML3, + QueryFormatMimeType.GML2, + QueryFormatMimeType.JSON, + QueryFormatMimeType.HTML + ]; + + for (const mimeType of queryFormatMimeTypePriority) { + if (capabilities.Capability.Request.GetFeatureInfo.Format.indexOf(mimeType) !== -1) { + const keyEnum = Object.keys(QueryFormatMimeType).find( + key => QueryFormatMimeType[key] === mimeType + ); + queryFormat = QueryFormat[keyEnum]; + break; + } + } + if (!queryFormat) { + queryable = false; + } + const options: WMSDataSourceOptions = ObjectUtils.removeUndefined({ _layerOptionsFromCapabilities: { title: layer.Title, @@ -202,6 +230,7 @@ export class CapabilitiesService { legendOptions }, queryable, + queryFormat, timeFilter: timeFilterable ? timeFilter : undefined, timeFilterable: timeFilterable ? true : undefined }); diff --git a/packages/geo/src/lib/query/shared/query.enums.ts b/packages/geo/src/lib/query/shared/query.enums.ts index 049bcd6c66..914dde6167 100644 --- a/packages/geo/src/lib/query/shared/query.enums.ts +++ b/packages/geo/src/lib/query/shared/query.enums.ts @@ -3,12 +3,25 @@ export enum QueryFormat { GML3 = 'gml3', JSON = 'json', GEOJSON = 'geojson', + GEOJSON2 = 'geojson2', ESRIJSON = 'esrijson', TEXT = 'text', HTML = 'html', HTMLGML2 = 'htmlgml2' } +export enum QueryFormatMimeType { + GML2 = 'application/vnd.ogc.gml', + GML3 = 'application/vnd.ogc.gml/3.1.1', + JSON = 'application/json', + GEOJSON = 'application/geojson', + GEOJSON2 = 'geojson', + ESRIJSON = 'application/json', + TEXT = 'text/plain', + HTML = 'text/html', + HTMLGML2 = 'text/html' +} + export enum QueryHtmlTarget { IFRAME = 'iframe', BLANK = '_blank' diff --git a/packages/geo/src/lib/query/shared/query.service.ts b/packages/geo/src/lib/query/shared/query.service.ts index a096dd55a7..0fb8c20cc3 100644 --- a/packages/geo/src/lib/query/shared/query.service.ts +++ b/packages/geo/src/lib/query/shared/query.service.ts @@ -22,7 +22,11 @@ import { WMSDataSourceOptions } from '../../datasource'; -import { QueryFormat, QueryHtmlTarget } from './query.enums'; +import { + QueryFormat, + QueryFormatMimeType, + QueryHtmlTarget +} from './query.enums'; import { QueryOptions, QueryableDataSource, @@ -236,6 +240,7 @@ export class QueryService { break; case QueryFormat.JSON: case QueryFormat.GEOJSON: + case QueryFormat.GEOJSON2: features = this.extractGeoJSONData(res); break; case QueryFormat.ESRIJSON: @@ -599,33 +604,13 @@ export class QueryService { return url; } - private getMimeInfoFormat(queryFormat) { - let mime; - switch (queryFormat) { - case QueryFormat.GML2: - mime = 'application/vnd.ogc.gml'; - break; - case QueryFormat.GML3: - mime = 'application/vnd.ogc.gml/3.1.1'; - break; - case QueryFormat.JSON: - mime = 'application/json'; - break; - case QueryFormat.GEOJSON: - mime = 'application/geojson'; - break; - case QueryFormat.TEXT: - mime = 'text/plain'; - break; - case QueryFormat.HTML: - mime = 'text/html'; - break; - case QueryFormat.HTMLGML2: - mime = 'text/html'; - break; - default: - mime = 'application/vnd.ogc.gml'; - break; + private getMimeInfoFormat(queryFormat: string) { + let mime = 'application/vnd.ogc.gml'; + const keyEnum = Object.keys(QueryFormat).find( + key => QueryFormat[key] === queryFormat + ); + if (keyEnum) { + mime = QueryFormatMimeType[keyEnum]; } return mime;