Skip to content

Commit

Permalink
feat(query): Provide ALIAS to wms getfeatureinfo(gml), wfs and vector…
Browse files Browse the repository at this point in the history
… datasources (#249)

* feat(query) Adding an alias property to query results

* feat(deature-details) Providing alias into the feature-details section

* feat(query) Provide alias for vertor source (wfs&file based)

* fix(query) handling layer with undefined title
  • Loading branch information
pelord authored and mbarbeau committed Dec 20, 2018
1 parent 7e609af commit 871be03
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<table class="igo-striped" *ngIf="feature && isObject(feature.properties) && feature.properties.target !== 'innerhtml'">
<tbody>
<tr *ngFor="let property of feature.properties | keyvalue">
<tr *ngFor="let property of filterFeatureProperties(feature) | keyvalue">

<td *ngIf="feature.properties.target === '_blank' && property.key === 'url'">
<mat-icon mat-list-avatar>{{feature.icon}}</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class FeatureDetailsComponent {
constructor(
private cdRef: ChangeDetectorRef,
private sanitizer: DomSanitizer
) {}
) { }

isUrl(value): SafeResourceUrl {
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
Expand All @@ -36,4 +36,25 @@ export class FeatureDetailsComponent {
isObject(value) {
return typeof value === 'object';
}

filterFeatureProperties(feature) {
const allowedFieldsAndAlias = feature.alias;
const properties = Object.assign({}, feature.properties);

if (allowedFieldsAndAlias) {
Object.keys(properties).forEach(property => {
if (Object.keys(allowedFieldsAndAlias).indexOf(property) === -1) {
delete properties[property];
} else {
properties[allowedFieldsAndAlias[property]] = properties[property];
if (allowedFieldsAndAlias[property] !== property) {
delete properties[property];
}
}
});
return properties;
} else {
return feature.properties;
}
}
}
1 change: 1 addition & 0 deletions projects/geo/src/lib/feature/shared/feature.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Feature {
extent?: [number, number, number, number];
properties?: { [key: string]: any };
layer?: AnyLayerOptions;
alias?: { [key: string]: any };
}

export interface FeatureGeometry {
Expand Down
31 changes: 26 additions & 5 deletions projects/geo/src/lib/query/shared/query.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class QueryDirective implements AfterViewInit, OnDestroy {
}
let queryTitleValue = '';
if (
layerOL.get('sourceOptions') &&
layerOL.get('sourceOptions').queryTitle &&
featureOL
.getProperties()
Expand All @@ -119,6 +120,25 @@ export class QueryDirective implements AfterViewInit, OnDestroy {
];
}
featureOL.set('clickedTitle', title + queryTitleValue);
let allowedFieldsAndAlias;
if (
layerOL.get('sourceOptions') &&
layerOL.get('sourceOptions').sourceFields &&
layerOL.get('sourceOptions').sourceFields.length >= 1) {
allowedFieldsAndAlias = {};
layerOL.get('sourceOptions').sourceFields.forEach(sourceField => {
const alias = sourceField.alias ? sourceField.alias : sourceField.name;
allowedFieldsAndAlias[sourceField.name] = alias;
});
}
featureOL.set('igoAliasList', allowedFieldsAndAlias);
let groupTitle = this.languageService.translate.instant(
'igo.geo.clickOnMap.clickedFeature');
if (
layerOL.get('title')) {
groupTitle = layerOL.get('title');
}
featureOL.set('igoLayerTitle', groupTitle);
return featureOL;
}
}
Expand Down Expand Up @@ -165,16 +185,17 @@ export class QueryDirective implements AfterViewInit, OnDestroy {
parsedClickedFeatures = featuresGeoJSON.features.map(f =>
Object.assign({}, f, {
sourceType: SourceFeatureType.Click,
source: this.languageService.translate.instant(
'igo.geo.clickOnMap.clickedFeature'
),
source: f.properties.igoLayerTitle,
id: f.properties.clickedTitle + ' ' + String(i++),
icon: 'mouse',
title: f.properties.clickedTitle
icon: 'place',
title: f.properties.clickedTitle,
alias: f.properties.igoAliasList
})
);
parsedClickedFeatures.forEach(element => {
delete element.properties['clickedTitle'];
delete element.properties['igoAliasList'];
delete element.properties['igoLayerTitle'];
});
const view = this.map.ol.getView();
const queries$ = this.queryService.query(this.queryLayers, {
Expand Down
27 changes: 19 additions & 8 deletions projects/geo/src/lib/query/shared/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ export class QueryService {
): Feature[] {
const queryDataSource = layer.dataSource as QueryableDataSource;

let allowedFieldsAndAlias;
if (layer.options &&
layer.options.sourceOptions &&
layer.options.sourceOptions.sourceFields && layer.options.sourceOptions.sourceFields.length >= 1) {
allowedFieldsAndAlias = {};
layer.options.sourceOptions.sourceFields.forEach(sourceField => {
const alias = sourceField.alias ? sourceField.alias : sourceField.name;
allowedFieldsAndAlias[sourceField.name] = alias;
});
}
let features = [];
switch (queryDataSource.options.queryFormat) {
case QueryFormat.GML3:
features = this.extractGML3Data(res, layer.zIndex);
features = this.extractGML3Data(res, layer.zIndex, allowedFieldsAndAlias);
break;
case QueryFormat.JSON:
case QueryFormat.GEOJSON:
Expand All @@ -89,7 +99,7 @@ export class QueryService {
break;
case QueryFormat.GML2:
default:
features = this.extractGML2Data(res, layer.zIndex);
features = this.extractGML2Data(res, layer, allowedFieldsAndAlias);
break;
}

Expand All @@ -110,7 +120,7 @@ export class QueryService {
});
}

private extractGML2Data(res, zIndex) {
private extractGML2Data(res, zIndex, allowedFieldsAndAlias?) {
let parser = new olFormatGML2();
let features = parser.readFeatures(res);

Expand All @@ -120,14 +130,14 @@ export class QueryService {
features = parser.readFeatures(res);
}

return features.map(feature => this.featureToResult(feature, zIndex));
return features.map(feature => this.featureToResult(feature, zIndex, allowedFieldsAndAlias));
}

private extractGML3Data(res, zIndex) {
private extractGML3Data(res, zIndex, allowedFieldsAndAlias?) {
const parser = new olFormatGML3();
const features = parser.readFeatures(res);

return features.map(feature => this.featureToResult(feature, zIndex));
return features.map(feature => this.featureToResult(feature, zIndex, allowedFieldsAndAlias));
}

private extractGeoJSONData(res) {
Expand Down Expand Up @@ -275,7 +285,7 @@ export class QueryService {
return result;
}

private featureToResult(featureOL: olFeature, zIndex: number): Feature {
private featureToResult(featureOL: olFeature, zIndex: number, allowedFieldsAndAlias?): Feature {
const featureGeometry = featureOL.getGeometry() as any;
const properties = Object.assign({}, featureOL.getProperties());
delete properties['geometry'];
Expand All @@ -301,7 +311,8 @@ export class QueryService {
icon: 'place',
projection: undefined,
properties: properties,
geometry: geometry
geometry: geometry,
alias: allowedFieldsAndAlias
};
}

Expand Down

0 comments on commit 871be03

Please sign in to comment.