From 20253a4d41aa13b10f7513027e467b07b2c7fc38 Mon Sep 17 00:00:00 2001 From: LavoieO <64489810+LavoieO@users.noreply.github.com> Date: Fri, 1 May 2020 15:42:08 -0400 Subject: [PATCH] feat(import-export): ajout de l'aggregation pour gpx (#623) * fix(catalog): apply the regular expression on the isolated layers of the first level of the catalog (#599) Co-authored-by: hbernard * feat import-export ajout de l'aggregation pour gpx * correctif pour le pull request camelCase et anglais --- demo/src/environments/environment.ts | 3 +- .../import-export/shared/export.service.ts | 55 ++++++++++++++++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/demo/src/environments/environment.ts b/demo/src/environments/environment.ts index 34173fd92..62524f2d6 100644 --- a/demo/src/environments/environment.ts +++ b/demo/src/environments/environment.ts @@ -34,7 +34,8 @@ export const environment: Environment = { prefix: './locale/' }, importExport: { - url: '/apis/ogre' + url: '/apis/ogre', + gpxAggregateInComment: true }, catalog: { sources: [ diff --git a/packages/geo/src/lib/import-export/shared/export.service.ts b/packages/geo/src/lib/import-export/shared/export.service.ts index 4a8ecc588..9d6df56ce 100644 --- a/packages/geo/src/lib/import-export/shared/export.service.ts +++ b/packages/geo/src/lib/import-export/shared/export.service.ts @@ -29,9 +29,14 @@ export class ExportService { static noOgreFallbacks = ['GML', 'GPX', 'KML']; private ogreUrl: string; + private aggregateInComment: boolean = false; constructor(private config: ConfigService) { this.ogreUrl = this.config.getConfig('importExport.url'); + const gpxAggregateInComment = this.config.getConfig('importExport.gpxAggregateInComment'); + if (gpxAggregateInComment !== undefined) { + this.aggregateInComment = gpxAggregateInComment; + } } export( @@ -41,7 +46,25 @@ export class ExportService { projectionIn = 'EPSG:4326', projectionOut = 'EPSG:4326' ): Observable { - const exportOlFeatures = olFeatures.map((olFeature: OlFeature) => { + const exportOlFeatures = this.generateFeature(olFeatures, format); + + return this.exportAsync( + exportOlFeatures, + format, + title, + projectionIn, + projectionOut + ); + } + + private generateFeature( + olFeatures: OlFeature[], + format: ExportFormat): OlFeature[] { + if (format === ExportFormat.GPX && this.aggregateInComment) { + return this.generateAggratedFeature(olFeatures); + } + + return olFeatures.map((olFeature: OlFeature) => { const keys = olFeature .getKeys() .filter((key: string) => !key.startsWith('_')); @@ -54,14 +77,30 @@ export class ExportService { ); return new OlFeature(properties); }); + } - return this.exportAsync( - exportOlFeatures, - format, - title, - projectionIn, - projectionOut - ); + private generateAggratedFeature(olFeatures: OlFeature[]): OlFeature[] { + return olFeatures.map((olFeature: OlFeature) => { + const keys = olFeature + .getKeys() + .filter((key: string) => !key.startsWith('_')); + let comment: string = ''; + const properties: any[] = keys.reduce( + (acc: object, key: string) => { + if (key !== undefined && key !== 'geometry') { + comment += key + ':' + olFeature.get(key) + ' \r\n'; + } + acc[key] = olFeature.get(key); + return acc; + }, + { geometry: olFeature.getGeometry() } + ); + const newFeature = new OlFeature(properties); + newFeature.set('name', olFeature.getId()); + newFeature.set('cmt', comment); + + return newFeature; + }); } private exportAsync(