Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ALIAS to wms getfeatureinfo(gml), wfs and vector datasources #249

Merged
merged 4 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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