Skip to content

Commit

Permalink
feat(datasource): retrieve query format from capabilities (#582)
Browse files Browse the repository at this point in the history
* query format from capabilities

* lint

* fix(geojson2): extract

* Update capabilities.service.ts
  • Loading branch information
mbarbeau committed May 11, 2020
1 parent b9a1727 commit 1278cef
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
33 changes: 31 additions & 2 deletions packages/geo/src/lib/datasource/shared/capabilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -202,6 +230,7 @@ export class CapabilitiesService {
legendOptions
},
queryable,
queryFormat,
timeFilter: timeFilterable ? timeFilter : undefined,
timeFilterable: timeFilterable ? true : undefined
});
Expand Down
13 changes: 13 additions & 0 deletions packages/geo/src/lib/query/shared/query.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
41 changes: 13 additions & 28 deletions packages/geo/src/lib/query/shared/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
WMSDataSourceOptions
} from '../../datasource';

import { QueryFormat, QueryHtmlTarget } from './query.enums';
import {
QueryFormat,
QueryFormatMimeType,
QueryHtmlTarget
} from './query.enums';
import {
QueryOptions,
QueryableDataSource,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1278cef

Please sign in to comment.