diff --git a/packages/context/src/lib/context-manager/shared/context.service.ts b/packages/context/src/lib/context-manager/shared/context.service.ts index a5f20cf07b..a50591e301 100644 --- a/packages/context/src/lib/context-manager/shared/context.service.ts +++ b/packages/context/src/lib/context-manager/shared/context.service.ts @@ -30,6 +30,7 @@ import { import { AuthService } from '@igo2/auth'; import type { IgoMap, Layer, LayerOptions } from '@igo2/geo'; +import { ExportService } from '@igo2/geo'; import { TypePermission } from './context.enum'; import { @@ -76,6 +77,7 @@ export class ContextService { private config: ConfigService, private messageService: MessageService, private storageService: StorageService, + private exportService: ExportService, @Optional() private route: RouteService ) { this.options = Object.assign( @@ -579,17 +581,22 @@ export class ContextService { const writer = new GeoJSON(); if (layer.ol.getSource() instanceof Cluster) { const clusterSource = layer.ol.getSource() as Cluster; + let olFeatures = clusterSource.getFeatures(); + olFeatures = (olFeatures as any).flatMap((cluster: any) => cluster.get('features')); + const cleanedOlFeatures = this.exportService.generateFeature(olFeatures, 'GeoJSON', '_featureStore'); features = writer.writeFeatures( - clusterSource.getFeatures(), + cleanedOlFeatures, { dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857' } ); } else { - const source = layer.ol.getSource() as any; + const source = layer.ol.getSource() as olVectorSource; + const olFeatures = source.getFeatures(); + const cleanedOlFeatures = this.exportService.generateFeature(olFeatures, 'GeoJSON', '_featureStore'); features = writer.writeFeatures( - source.getFeatures(), + cleanedOlFeatures, { dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857' 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 61a832d997..88359c36e7 100644 --- a/packages/geo/src/lib/import-export/shared/export.service.ts +++ b/packages/geo/src/lib/import-export/shared/export.service.ts @@ -58,9 +58,10 @@ export class ExportService { return this.exportAsync(exportOlFeatures, format, title, encoding, projectionIn, projectionOut); } - private generateFeature( + public generateFeature( olFeatures: OlFeature[], - format: ExportFormat + format: ExportFormat, + excludePrefix: string = '_' ): OlFeature[] { if (format === ExportFormat.GPX && this.aggregateInComment) { return this.generateAggregatedFeature(olFeatures); @@ -69,7 +70,7 @@ export class ExportService { return olFeatures.map((olFeature: OlFeature) => { const keys = olFeature .getKeys() - .filter((key: string) => !key.startsWith('_')); + .filter((key: string) => !key.startsWith(excludePrefix)); const properties = keys.reduce( (acc: object, key: string) => { acc[key] = olFeature.get(key);