From 0b56b68b50e00a331ce57cf9219cca63d41a0ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Mon, 5 Mar 2018 14:04:22 -0500 Subject: [PATCH] feat(featuresList): sort by zIndex --- src/lib/feature/shared/feature-group.pipe.ts | 7 +++-- src/lib/feature/shared/feature.interface.ts | 1 + src/lib/query/shared/query.service.ts | 28 +++++++++++-------- .../datasource-search-source.ts | 1 + .../search-sources/icherche-search-source.ts | 1 + .../search-sources/nominatim-search-source.ts | 1 + src/locale/fr.json | 4 +-- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/lib/feature/shared/feature-group.pipe.ts b/src/lib/feature/shared/feature-group.pipe.ts index af2844eb5d..96671ea6a4 100644 --- a/src/lib/feature/shared/feature-group.pipe.ts +++ b/src/lib/feature/shared/feature-group.pipe.ts @@ -19,8 +19,11 @@ export class FeatureGroupPipe implements PipeTransform { groupedFeatures[source].push(feature); }); - const sourceFeatures = Object.keys(groupedFeatures).sort().map( - (source: string) => [source, groupedFeatures[source]]); + const sourceFeatures = Object.keys(groupedFeatures).sort((a, b) => { + return groupedFeatures[a][0].order - groupedFeatures[b][0].order; + }).map( + (source: string) => [source, groupedFeatures[source]] + ); return sourceFeatures; } diff --git a/src/lib/feature/shared/feature.interface.ts b/src/lib/feature/shared/feature.interface.ts index 57006f2aa1..47602b53d9 100644 --- a/src/lib/feature/shared/feature.interface.ts +++ b/src/lib/feature/shared/feature.interface.ts @@ -6,6 +6,7 @@ export interface Feature { id: string; source: string; sourceType?: SourceFeatureType; + order?: number; type: FeatureType; title: string; format?: FeatureFormat; diff --git a/src/lib/query/shared/query.service.ts b/src/lib/query/shared/query.service.ts index ca6ceef7fc..a93d0c36b1 100644 --- a/src/lib/query/shared/query.service.ts +++ b/src/lib/query/shared/query.service.ts @@ -22,17 +22,18 @@ export class QueryService { query(layers: Layer[], options: QueryOptions) { this.unsubscribe(); + this.subscriptions = layers .filter((layer: Layer) => layer.visible) - .map((layer: Layer) => this.queryDataSource(layer.dataSource, options)); + .map((layer: Layer) => this.queryDataSource(layer.dataSource, options, layer.zIndex)); } - queryDataSource(dataSource: DataSource, options: QueryOptions) { + queryDataSource(dataSource: DataSource, options: QueryOptions, zIndex: number) { const url = (dataSource as any as QueryableDataSource).getQueryUrl(options); const request = this.http.get(url, {responseType: 'text'}); this.featureService.clear(); - return request.map(res => this.extractData(res, dataSource, options, url)) + return request.map(res => this.extractData(res, dataSource, options, url, zIndex)) .subscribe((features: Feature[]) => this.handleQueryResults(features, dataSource)); } @@ -45,17 +46,18 @@ export class QueryService { this.featureService.updateFeatures(features, dataSource.title); } - private extractData(res, dataSource: DataSource, - options: QueryOptions, url: string): Feature[] { + private extractData(res, dataSource: DataSource, options: QueryOptions, + url: string, zIndex: number): Feature[] { + const queryDataSource = (dataSource as any as QueryableDataSource); let features = []; switch (queryDataSource.queryFormat) { case QueryFormat.GML2: - features = this.extractGML2Data(res); + features = this.extractGML2Data(res, zIndex); break; case QueryFormat.GML3: - features = this.extractGML3Data(res); + features = this.extractGML3Data(res, zIndex); break; case QueryFormat.JSON: features = this.extractGeoJSONData(res); @@ -77,13 +79,14 @@ export class QueryService { id: uuid(), source: dataSource.title, sourceType: SourceFeatureType.Query, + order: zIndex, title: title ? title : `${dataSource.title} (${index + 1})`, projection: options.projection }); }); } - private extractGML2Data(res) { + private extractGML2Data(res, zIndex) { let parser = new ol.format.GML2(); let features = parser.readFeatures(res); @@ -93,14 +96,14 @@ export class QueryService { features = parser.readFeatures(res); } - return features.map(feature => this.featureToResult(feature)); + return features.map(feature => this.featureToResult(feature, zIndex)); } - private extractGML3Data(res) { + private extractGML3Data(res, zIndex) { const parser = new ol.format.GML3(); const features = parser.readFeatures(res); - return features.map(feature => this.featureToResult(feature)); + return features.map(feature => this.featureToResult(feature, zIndex)); } private extractGeoJSONData(res) { @@ -207,7 +210,7 @@ export class QueryService { return result; } - private featureToResult(feature: ol.Feature): Feature { + private featureToResult(feature: ol.Feature, zIndex: number): Feature { const featureGeometry = (feature.getGeometry() as any); const properties = Object.assign({}, feature.getProperties()); delete properties['geometry']; @@ -226,6 +229,7 @@ export class QueryService { source: undefined, sourceType: SourceFeatureType.Query, type: FeatureType.Feature, + order: zIndex, format: FeatureFormat.GeoJSON, title: undefined, icon: 'place', diff --git a/src/lib/search/search-sources/datasource-search-source.ts b/src/lib/search/search-sources/datasource-search-source.ts index 5fc4a4d2e5..f75a2732c7 100644 --- a/src/lib/search/search-sources/datasource-search-source.ts +++ b/src/lib/search/search-sources/datasource-search-source.ts @@ -80,6 +80,7 @@ export class DataSourceSearchSource extends SearchSource { id: result.id, source: this.getName(), sourceType: SourceFeatureType.Search, + order: 2, type: FeatureType.DataSource, title: result.source.title, title_html: result.highlight.title, diff --git a/src/lib/search/search-sources/icherche-search-source.ts b/src/lib/search/search-sources/icherche-search-source.ts index 311a10907f..6f76f90c30 100644 --- a/src/lib/search/search-sources/icherche-search-source.ts +++ b/src/lib/search/search-sources/icherche-search-source.ts @@ -73,6 +73,7 @@ export class IChercheSearchSource extends SearchSource { id: result._id, source: IChercheSearchSource._name, sourceType: SourceFeatureType.Search, + order: 1, type: FeatureType.Feature, format: FeatureFormat.GeoJSON, title: result.properties.recherche, diff --git a/src/lib/search/search-sources/nominatim-search-source.ts b/src/lib/search/search-sources/nominatim-search-source.ts index ac0ff76c08..2564221591 100644 --- a/src/lib/search/search-sources/nominatim-search-source.ts +++ b/src/lib/search/search-sources/nominatim-search-source.ts @@ -62,6 +62,7 @@ export class NominatimSearchSource extends SearchSource { id: result.place_id, source: NominatimSearchSource._name, sourceType: SourceFeatureType.Search, + order: 0, type: FeatureType.Feature, format: FeatureFormat.GeoJSON, title: result.display_name, diff --git a/src/locale/fr.json b/src/locale/fr.json index 5ace89ec4f..8e50771429 100644 --- a/src/locale/fr.json +++ b/src/locale/fr.json @@ -104,7 +104,7 @@ "showLayer": "Afficher la couche", "showMetadata": "Montrer les métadonnées" }, - "download":{ + "download":{ "action": "Télécharger les données associées", "title": "Téléchargement des données", "start": "Vérifiez la progression du téléchargement dans votre navigateur", @@ -161,7 +161,7 @@ }, "search": { "dataSources": { - "name": "Layers (Couches)", + "name": "Couches", "properties": { "abstract": "Description", "group": "Groupe",