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

feat import-export ajout de l'aggregation pour gpx #623

Merged
merged 4 commits into from
May 1, 2020
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
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