diff --git a/packages/context/src/lib/context-manager/shared/layer-context.directive.ts b/packages/context/src/lib/context-manager/shared/layer-context.directive.ts index c5f9916a61..a8a6f1302e 100644 --- a/packages/context/src/lib/context-manager/shared/layer-context.directive.ts +++ b/packages/context/src/lib/context-manager/shared/layer-context.directive.ts @@ -7,6 +7,7 @@ import { RouteService } from '@igo2/core'; import { IgoMap, MapBrowserComponent, + Layer, LayerService, LayerOptions } from '@igo2/geo'; @@ -18,9 +19,12 @@ import { DetailedContext } from './context.interface'; selector: '[igoLayerContext]' }) export class LayerContextDirective implements OnInit, OnDestroy { + private context$$: Subscription; private queryParams: any; + private contextLayers: Layer[] = []; + get map(): IgoMap { return this.component.map; } @@ -57,14 +61,13 @@ export class LayerContextDirective implements OnInit, OnDestroy { } private handleContextChange(context: DetailedContext) { - if (context.layers === undefined) { - return; - } + if (context.layers === undefined) { return; } - this.map.removeLayers(); + this.map.removeLayers(this.contextLayers); + this.contextLayers = []; - context.layers.forEach(contextLayer => { - this.addLayerToMap(contextLayer); + context.layers.forEach((layerOptions: LayerOptions) => { + this.addLayerToMap(layerOptions); }); } @@ -87,7 +90,7 @@ export class LayerContextDirective implements OnInit, OnDestroy { layer.id, layer ); - + this.contextLayers.push(layer); this.map.addLayer(layer); }); } diff --git a/packages/geo/src/lib/feature/shared/strategies/selection.ts b/packages/geo/src/lib/feature/shared/strategies/selection.ts index bb1a49d246..c9a905b27f 100644 --- a/packages/geo/src/lib/feature/shared/strategies/selection.ts +++ b/packages/geo/src/lib/feature/shared/strategies/selection.ts @@ -261,7 +261,8 @@ export class FeatureStoreSelectionStrategy extends FeatureStoreStrategy { const overlayLayer = new VectorLayer({ zIndex: 200, source: new FeatureDataSource(), - style: this.options ? this.options.style : undefined + style: this.options ? this.options.style : undefined, + showInLayerList: false }); return new FeatureStore([], {map: this.map}).bindLayer(overlayLayer); @@ -272,8 +273,7 @@ export class FeatureStoreSelectionStrategy extends FeatureStoreStrategy { * features. */ private addOverlayLayer() { - // TODO: why do we need to cast as any? - this.map.addLayer(this.overlayStore.layer as any, false); + this.map.ol.addLayer(this.overlayStore.layer.ol); } /** @@ -281,8 +281,6 @@ export class FeatureStoreSelectionStrategy extends FeatureStoreStrategy { */ private removeOverlayLayer() { this.overlayStore.source.ol.clear(); - // Remove directly from the olMap because, for some reason, - // removing from the IgoMap doesn't remove the layer this.map.ol.removeLayer(this.overlayStore.layer.ol); } } diff --git a/packages/geo/src/lib/import-export/shared/import-export.service.ts b/packages/geo/src/lib/import-export/shared/import-export.service.ts index 7fe02b475e..b5aad6d2be 100644 --- a/packages/geo/src/lib/import-export/shared/import-export.service.ts +++ b/packages/geo/src/lib/import-export/shared/import-export.service.ts @@ -3,6 +3,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import * as olformat from 'ol/format'; import * as olstyle from 'ol/style'; +import OlFeature from 'ol/Feature'; import { ConfigService, MessageService, LanguageService } from '@igo2/core'; import { MapService } from '../../map/shared/map.service'; @@ -73,15 +74,24 @@ export class ImportExportService { public export(data: ExportOptions) { const map = this.mapService.getMap(); const layer = map.getLayerById(data.layer); - const source: any = layer.ol.getSource(); + const olSource = layer.ol.getSource(); - const formatStr: any = data.format; + const formatStr = data.format; const format = data.format === 'shapefile' ? new olformat.GeoJSON() : new olformat[formatStr](); - const featuresText = format.writeFeatures(source.getFeatures(), { + const olFeatures = olSource.getFeatures().map((olFeature: OlFeature) => { + const keys = olFeature.getKeys().filter((key: string) => !key.startsWith('_')); + const properties = keys.reduce((acc: object, key: string) => { + acc[key] = olFeature.get(key); + return acc; + }, {geometry: olFeature.getGeometry()}); + return new OlFeature(properties); + }); + + const featuresText = format.writeFeatures(olFeatures, { dataProjection: 'EPSG:4326', featureProjection: map.projection, featureType: 'feature', diff --git a/packages/geo/src/lib/layer/layer-item/layer-item.component.html b/packages/geo/src/lib/layer/layer-item/layer-item.component.html index fbc56bcd17..2a81aea535 100644 --- a/packages/geo/src/lib/layer/layer-item/layer-item.component.html +++ b/packages/geo/src/lib/layer/layer-item/layer-item.component.html @@ -57,9 +57,9 @@