Skip to content

Commit

Permalink
feat(import-export): ajout de l'aggregation pour gpx (#623)
Browse files Browse the repository at this point in the history
* fix(catalog): apply the regular expression on the isolated layers of the first level of the catalog (#599)

Co-authored-by: hbernard <[email protected]>

* feat import-export ajout de l'aggregation pour gpx

* correctif pour le pull request camelCase et anglais
  • Loading branch information
LavoieO authored and mbarbeau committed May 11, 2020
1 parent d8a1431 commit 20253a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
3 changes: 2 additions & 1 deletion demo/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const environment: Environment = {
prefix: './locale/'
},
importExport: {
url: '/apis/ogre'
url: '/apis/ogre',
gpxAggregateInComment: true
},
catalog: {
sources: [
Expand Down
55 changes: 47 additions & 8 deletions packages/geo/src/lib/import-export/shared/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -41,7 +46,25 @@ export class ExportService {
projectionIn = 'EPSG:4326',
projectionOut = 'EPSG:4326'
): Observable<void> {
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('_'));
Expand All @@ -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(
Expand Down

0 comments on commit 20253a4

Please sign in to comment.