Skip to content

Commit

Permalink
feat(featuresList): sort by zIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Mar 5, 2018
1 parent 5222806 commit 0b56b68
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/lib/feature/shared/feature-group.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/feature/shared/feature.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Feature {
id: string;
source: string;
sourceType?: SourceFeatureType;
order?: number;
type: FeatureType;
title: string;
format?: FeatureFormat;
Expand Down
28 changes: 16 additions & 12 deletions src/lib/query/shared/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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'];
Expand All @@ -226,6 +229,7 @@ export class QueryService {
source: undefined,
sourceType: SourceFeatureType.Query,
type: FeatureType.Feature,
order: zIndex,
format: FeatureFormat.GeoJSON,
title: undefined,
icon: 'place',
Expand Down
1 change: 1 addition & 0 deletions src/lib/search/search-sources/datasource-search-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib/search/search-sources/icherche-search-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib/search/search-sources/nominatim-search-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/locale/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -161,7 +161,7 @@
},
"search": {
"dataSources": {
"name": "Layers (Couches)",
"name": "Couches",
"properties": {
"abstract": "Description",
"group": "Groupe",
Expand Down

0 comments on commit 0b56b68

Please sign in to comment.