From c5339333f226a02fb13ec09a5c42eabe8cf90f9f Mon Sep 17 00:00:00 2001 From: Alexandre Caron Date: Wed, 6 Nov 2024 14:11:38 -0500 Subject: [PATCH 1/2] fix: code review adjustment --- package-lock.json | 2 +- .../tree-drag-drop.directive.ts | 5 +- packages/common/src/locale/en.common.json | 2 +- packages/common/src/locale/fr.common.json | 2 +- .../context-import-export.component.ts | 25 +++---- .../shared/context-import.utils.ts | 4 +- .../context-manager/shared/context.service.ts | 8 +-- .../shared/layer-context.directive.ts | 4 +- .../catalog-browser-layer.component.ts | 2 +- .../catalog-browser.component.ts | 12 ++-- .../datasource/shared/capabilities.service.ts | 7 +- .../datasources/wfs-datasource.interface.ts | 4 +- .../datasources/wms-datasource.interface.ts | 8 +-- .../shared/options/options-api.service.ts | 18 ----- .../lib/feature/shared/feature-store.utils.ts | 4 +- .../feature/shared/strategies/selection.ts | 2 +- .../time-filter-form.component.ts | 4 +- .../lib/geometry/shared/controls/modify.ts | 1 + .../import-export/import-export.component.ts | 14 ++-- .../import-export/shared/export.service.ts | 4 +- .../lib/import-export/shared/import.utils.ts | 4 +- .../src/lib/layer/shared/layer-controller.ts | 17 ++++- .../baselayers-switcher.component.ts | 14 +++- .../mini-basemap.component.ts | 6 +- .../lib/map/shared/hover-feature.directive.ts | 2 - .../geo/src/lib/map/shared/map.abstract.ts | 17 +---- packages/geo/src/lib/map/shared/map.ts | 68 +------------------ .../metadata-button.component.ts | 2 +- .../src/lib/query/shared/query.directive.ts | 4 +- .../geo/src/lib/query/shared/query.service.ts | 1 + .../search-results-add-button.component.ts | 8 ++- .../search-pointer-summary.directive.ts | 2 - .../shared/edition-workspace.service.ts | 2 +- .../lib/workspace/shared/edition-workspace.ts | 6 +- .../workspace/shared/wms-workspace.service.ts | 2 +- .../lib/workspace/shared/workspace.utils.ts | 6 +- packages/geo/src/locale/en.geo.json | 9 +-- packages/geo/src/locale/fr.geo.json | 9 +-- .../src/lib/directions/directions.state.ts | 8 ++- .../integration/src/lib/draw/draw.state.ts | 2 +- .../active-time-filter-tool.component.ts | 15 +--- .../spatial-filter-tool.component.ts | 14 ++-- packages/utils/src/lib/tree/tree.ts | 4 +- .../src/app/geo/catalog/catalog.component.ts | 2 +- .../geo/directions/directions.component.ts | 2 +- .../demo/src/app/geo/draw/draw.component.ts | 2 +- .../src/app/geo/feature/feature.component.ts | 4 +- .../app/geo/geometry/geometry.component.ts | 2 +- .../demo/src/app/geo/hover/hover.component.ts | 6 +- .../import-export/import-export.component.ts | 2 +- .../demo/src/app/geo/layer/layer.component.ts | 2 +- .../src/app/geo/legend/legend.component.ts | 20 +++--- .../src/app/geo/measure/measure.component.ts | 2 +- .../geo/ogc-filter/ogc-filter.component.ts | 20 +++--- .../src/app/geo/overlay/overlay.component.ts | 2 +- .../demo/src/app/geo/print/print.component.ts | 8 +-- .../demo/src/app/geo/query/query.component.ts | 14 ++-- .../src/app/geo/search/search.component.ts | 2 +- .../geo/simple-map/simple-map.component.ts | 2 +- .../spatial-filter.component.ts | 18 ++--- .../geo/time-filter/time-filter.component.ts | 4 +- .../app/geo/workspace/workspace.component.ts | 6 +- 62 files changed, 198 insertions(+), 276 deletions(-) diff --git a/package-lock.json b/package-lock.json index dee250ccd..ea3d9e587 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29928,7 +29928,7 @@ "projects/demo": {}, "projects/igo2": { "name": "igo", - "version": "17.0.1", + "version": "17.0.0", "license": "LiLiQ-R", "dependencies": { "@angular/animations": "^18.2.1", diff --git a/packages/common/drag-drop/src/tree-drag-drop/tree-drag-drop.directive.ts b/packages/common/drag-drop/src/tree-drag-drop/tree-drag-drop.directive.ts index 52df7eeda..355fd70fc 100644 --- a/packages/common/drag-drop/src/tree-drag-drop/tree-drag-drop.directive.ts +++ b/packages/common/drag-drop/src/tree-drag-drop/tree-drag-drop.directive.ts @@ -23,6 +23,7 @@ import { TreeFlatNode } from './tree-drag-drop.interface'; +// eslint-disable-next-line @typescript-eslint/no-explicit-any export interface TreeDropEvent { node: TreeFlatNode; ref: TreeFlatNode; @@ -79,11 +80,11 @@ export class TreeDragDropDirective implements AfterContentInit, OnDestroy { // eslint-disable-next-line @angular-eslint/no-output-on-prefix @Output() onDropError = new EventEmitter(); - @HostListener('dragover', ['$event']) hostDragOver(event: any): void { + @HostListener('dragover', ['$event']) hostDragOver(event: Event): void { event.preventDefault(); } - @HostListener('drop', ['$event']) hostDrop(event: any): void { + @HostListener('drop', ['$event']) hostDrop(event: DragEvent): void { this.drop(event); } diff --git a/packages/common/src/locale/en.common.json b/packages/common/src/locale/en.common.json index a91af6b3a..be2def570 100644 --- a/packages/common/src/locale/en.common.json +++ b/packages/common/src/locale/en.common.json @@ -12,7 +12,7 @@ "dragDrop": { "cannot": { "dropInsideItself": "Unable to move the item inside itself", - "maxLevel": "The maximum hierarchical level is {{value}}" + "maxLevel": "The maximum hierarchical level is reached ({{value}})" } }, "selectValueDialog": { diff --git a/packages/common/src/locale/fr.common.json b/packages/common/src/locale/fr.common.json index 362dbca34..76430f40f 100644 --- a/packages/common/src/locale/fr.common.json +++ b/packages/common/src/locale/fr.common.json @@ -12,7 +12,7 @@ "dragDrop": { "cannot": { "dropInsideItself": "Impossible de bouger l'item à l'intérieur de lui même", - "maxLevel": "Le maximum de niveau hiérarchique est de {{value}}" + "maxLevel": "Le maximum de niveau hiérarchique est atteint ({{value}})" } }, "selectValueDialog": { diff --git a/packages/context/src/lib/context-import-export/context-import-export/context-import-export.component.ts b/packages/context/src/lib/context-import-export/context-import-export/context-import-export.component.ts index 2b7a0220b..4d052f978 100644 --- a/packages/context/src/lib/context-import-export/context-import-export/context-import-export.component.ts +++ b/packages/context/src/lib/context-import-export/context-import-export/context-import-export.component.ts @@ -1,5 +1,5 @@ import { AsyncPipe, NgFor, NgIf } from '@angular/common'; -import { Component, Input, OnDestroy, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { FormsModule, ReactiveFormsModule, @@ -21,8 +21,8 @@ import { IgoLanguageModule } from '@igo2/core/language'; import { MessageService } from '@igo2/core/message'; import { type AnyLayer, type IgoMap, VectorLayer } from '@igo2/geo'; -import { BehaviorSubject, Subscription } from 'rxjs'; -import { filter, take } from 'rxjs/operators'; +import { BehaviorSubject } from 'rxjs'; +import { take } from 'rxjs/operators'; import { DetailedContext } from '../../context-manager/shared/context.interface'; import { ContextService } from '../../context-manager/shared/context.service'; @@ -57,21 +57,19 @@ import { IgoLanguageModule ] }) -export class ContextImportExportComponent implements OnInit, OnDestroy { +export class ContextImportExportComponent implements OnInit { public form: UntypedFormGroup; public layers: VectorLayer[]; public inputProj = 'EPSG:4326'; public loading$ = new BehaviorSubject(false); public forceNaming = false; public layerList: AnyLayer[]; - public userControlledLayerList: AnyLayer[]; + public userControlledLayerList: readonly AnyLayer[]; public res: DetailedContext; private clientSideFileSizeMax: number; public fileSizeMb: number; public activeImportExport = 'import'; - private layers$$: Subscription; - @Input() map: IgoMap; constructor( @@ -92,12 +90,9 @@ export class ContextImportExportComponent implements OnInit, OnDestroy { this.clientSideFileSizeMax = (configFileSizeMb ? configFileSizeMb : 30) * Math.pow(1024, 2); this.fileSizeMb = this.clientSideFileSizeMax / Math.pow(1024, 2); - this.layers$$ = this.map.layerController.layers$ - .pipe(filter((layers) => !!layers)) - .subscribe((layers) => { - this.layerList = layers; - this.userControlledLayerList = layers; - }); + + this.layerList = this.map.layerController.all; + this.userControlledLayerList = this.map.layerController.treeLayers; } importFiles(files: File[]) { @@ -180,8 +175,4 @@ export class ContextImportExportComponent implements OnInit, OnDestroy { onImportExportChange(event) { this.activeImportExport = event.value; } - - ngOnDestroy(): void { - this.layers$$.unsubscribe(); - } } diff --git a/packages/context/src/lib/context-import-export/shared/context-import.utils.ts b/packages/context/src/lib/context-import-export/shared/context-import.utils.ts index d8416d996..77c04fadb 100644 --- a/packages/context/src/lib/context-import-export/shared/context-import.utils.ts +++ b/packages/context/src/lib/context-import-export/shared/context-import.utils.ts @@ -177,7 +177,7 @@ export function addImportedFeaturesToMap( visible: extraFeatures.visible, opacity: extraFeatures.opacity }); - map.addLayer(layer); + map.layerController.add(layer); return layer; } @@ -268,7 +268,7 @@ export function addImportedFeaturesStyledToMap( opacity: extraFeatures.opacity, visible: extraFeatures.visible }); - map.addLayer(layer); + map.layerController.add(layer); return layer; } 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 dc594d642..9a99c5e16 100644 --- a/packages/context/src/lib/context-manager/shared/context.service.ts +++ b/packages/context/src/lib/context-manager/shared/context.service.ts @@ -8,7 +8,7 @@ import { LanguageService } from '@igo2/core/language'; import { Message, MessageService } from '@igo2/core/message'; import { RouteService } from '@igo2/core/route'; import { StorageService } from '@igo2/core/storage'; -import type { AnyLayer, Layer, MapBase } from '@igo2/geo'; +import type { AnyLayer, IgoMap, Layer } from '@igo2/geo'; import { ExportService, isLayerGroup } from '@igo2/geo'; import { ObjectUtils, uuid } from '@igo2/utils'; @@ -434,7 +434,7 @@ export class ContextService { this.editedContext$.next(context); } - getContextFromMap(igoMap: MapBase, empty?: boolean): DetailedContext { + getContextFromMap(igoMap: IgoMap, empty?: boolean): DetailedContext { const view = igoMap.ol.getView(); const proj = view.getProjection().getCode(); const center: any = new olPoint(view.getCenter()).transform( @@ -483,7 +483,7 @@ export class ContextService { } getContextFromLayers( - igoMap: MapBase, + igoMap: IgoMap, layers: AnyLayer[], name: string, keepCurrentView?: boolean @@ -636,7 +636,7 @@ export class ContextService { } } - getContextLayers(map: MapBase) { + getContextLayers(map: IgoMap) { return map.layerController.treeLayers; } 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 d6f257496..7dd736905 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 @@ -80,7 +80,7 @@ export class LayerContextDirective implements OnInit, OnDestroy { if (this.removeLayersOnContextChange === true) { this.map.layerController.reset(); } else { - this.map.removeLayer(...this.contextLayers); + this.map.layerController.remove(...this.contextLayers); } this.contextLayers = []; this.layerService.unavailableLayers = []; @@ -138,7 +138,7 @@ export class LayerContextDirective implements OnInit, OnDestroy { const layersSorted = sortLayersByZindex(layersFiltrered, 'asc'); this.contextLayers.concat(layersSorted); - this.map.addLayer(...layersSorted); + this.map.layerController.add(...layersSorted); } private computeLayerVisibilityFromUrl(layer: AnyLayer): boolean { diff --git a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-layer.component.ts b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-layer.component.ts index c50f48152..fb769c0d0 100644 --- a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-layer.component.ts +++ b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-layer.component.ts @@ -257,7 +257,7 @@ export class CatalogBrowserLayerComponent implements OnInit, OnDestroy { isVisible() { if (this.layer?.id) { - const layer = this.map.layerController.getBySourceId(this.layer?.id); + const layer = this.map.layerController.getById(this.layer?.id); this.isVisible$.next(layer?.displayed); } } diff --git a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts index 4c559c8bc..280da14a2 100644 --- a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts +++ b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts @@ -197,7 +197,7 @@ export class CatalogBrowserComponent implements OnInit, OnDestroy { this.map.layersAddedByClick$.next(layers); } this.store.state.updateMany(catalogLayers, { added: true }); - this.map.addLayer(...layers.filter(Boolean)); + this.map.layerController.add(...layers.filter(Boolean)); }); } @@ -209,14 +209,16 @@ export class CatalogBrowserComponent implements OnInit, OnDestroy { layers.forEach((layer: CatalogItemLayer) => { this.store.state.update(layer, { added: false }); if (layer.options.baseLayer === true) { - const currLayer = this.map.getLayerById(String(layer.options.id)); + const currLayer = this.map.layerController.getById( + String(layer.options.id) + ); if (currLayer !== undefined) { - this.map.removeLayer(currLayer); + this.map.layerController.remove(currLayer); } } else { - const currLayer = this.map.layerController.getBySourceId(layer.id); + const currLayer = this.map.layerController.getById(layer.id); if (currLayer !== undefined) { - this.map.removeLayer(currLayer); + this.map.layerController.remove(currLayer); } } }); diff --git a/packages/geo/src/lib/datasource/shared/capabilities.service.ts b/packages/geo/src/lib/datasource/shared/capabilities.service.ts index 6e0c68004..116f8badf 100644 --- a/packages/geo/src/lib/datasource/shared/capabilities.service.ts +++ b/packages/geo/src/lib/datasource/shared/capabilities.service.ts @@ -16,6 +16,10 @@ import { TimeFilterStyle, TimeFilterType } from '../../filter/shared/time-filter.enum'; +import type { + ItemStyleOptions, + LegendOptions +} from '../../layer/shared/layers/legend.interface'; import { MapService } from '../../map/shared/map.service'; import { getResolutionFromScale } from '../../map/shared/map.utils'; import { @@ -34,9 +38,6 @@ import { TileArcGISRestDataSourceOptions } from './datasources/tilearcgisrest-da import { WMSDataSourceOptions } from './datasources/wms-datasource.interface'; import { WMTSDataSourceOptions } from './datasources/wmts-datasource.interface'; -type ItemStyleOptions = any; -type LegendOptions = any; - @Injectable({ providedIn: 'root' }) diff --git a/packages/geo/src/lib/datasource/shared/datasources/wfs-datasource.interface.ts b/packages/geo/src/lib/datasource/shared/datasources/wfs-datasource.interface.ts index aae529776..a21215d07 100644 --- a/packages/geo/src/lib/datasource/shared/datasources/wfs-datasource.interface.ts +++ b/packages/geo/src/lib/datasource/shared/datasources/wfs-datasource.interface.ts @@ -1,5 +1,5 @@ -import { OgcFiltersOptions } from '../../../filter'; -import { FeatureDataSourceOptions } from './feature-datasource.interface'; +import type { OgcFiltersOptions } from '../../../filter'; +import type { FeatureDataSourceOptions } from './feature-datasource.interface'; export interface WFSDataSourceOptions extends FeatureDataSourceOptions { // type?: 'wfs'; diff --git a/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts b/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts index 39050425f..1b8e1aac4 100644 --- a/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts +++ b/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts @@ -1,9 +1,9 @@ import type { ServerType } from 'ol/source/wms'; -import { OgcFiltersOptions } from '../../../filter'; -import { TimeFilterOptions } from '../../../filter/shared/time-filter.interface'; -import { DataSourceOptions } from './datasource.interface'; -import { WFSDataSourceOptionsParams } from './wfs-datasource.interface'; +import type { OgcFiltersOptions } from '../../../filter'; +import type { TimeFilterOptions } from '../../../filter/shared/time-filter.interface'; +import type { DataSourceOptions } from './datasource.interface'; +import type { WFSDataSourceOptionsParams } from './wfs-datasource.interface'; export interface WMSDataSourceOptions extends DataSourceOptions { // type?: 'wms'; diff --git a/packages/geo/src/lib/datasource/shared/options/options-api.service.ts b/packages/geo/src/lib/datasource/shared/options/options-api.service.ts index f20815846..6b60d1fca 100644 --- a/packages/geo/src/lib/datasource/shared/options/options-api.service.ts +++ b/packages/geo/src/lib/datasource/shared/options/options-api.service.ts @@ -5,7 +5,6 @@ import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { - AnyDataSourceOptions, ArcGISRestDataSourceOptions, ArcGISRestImageDataSourceOptions, TileArcGISRestDataSourceOptions, @@ -125,21 +124,4 @@ export class OptionsApiService extends OptionsService { ) ); } - - private handleSourceOptions(res: { - sourceOptions: T; - layerOptions: Record; - }): T { - if (!res || !res.sourceOptions) { - return {} as T; - } - if (res.layerOptions) { - res.sourceOptions._layerOptionsFromSource = res.layerOptions; - } else { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { sourceOptions, layerOptions, ...restOptions } = res; - res.sourceOptions._layerOptionsFromSource = restOptions; - } - return res.sourceOptions; - } } diff --git a/packages/geo/src/lib/feature/shared/feature-store.utils.ts b/packages/geo/src/lib/feature/shared/feature-store.utils.ts index 042b497cb..a4f08b18c 100644 --- a/packages/geo/src/lib/feature/shared/feature-store.utils.ts +++ b/packages/geo/src/lib/feature/shared/feature-store.utils.ts @@ -15,7 +15,7 @@ export function tryBindStoreLayer( ): VectorLayer { if (store.layer !== undefined) { if (!store.map.layerController.getById(store.layer.id)) { - store.map.addLayer(store.layer); + store.map.layerController.add(store.layer); } return store.layer; } @@ -27,7 +27,7 @@ export function tryBindStoreLayer( }); store.bindLayer(layer); if (!store.map.layerController.getById(store.layer.id)) { - store.map.addLayer(store.layer); + store.map.layerController.add(store.layer); } return layer; diff --git a/packages/geo/src/lib/feature/shared/strategies/selection.ts b/packages/geo/src/lib/feature/shared/strategies/selection.ts index e8721ea70..d2b785797 100644 --- a/packages/geo/src/lib/feature/shared/strategies/selection.ts +++ b/packages/geo/src/lib/feature/shared/strategies/selection.ts @@ -471,6 +471,6 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy { */ private removeOverlayLayer() { this.overlayStore.source.ol.clear(); - this.map.removeLayer(this.overlayStore.layer); + this.map.layerController.remove(this.overlayStore.layer); } } diff --git a/packages/geo/src/lib/filter/time-filter-form/time-filter-form.component.ts b/packages/geo/src/lib/filter/time-filter-form/time-filter-form.component.ts index 938480129..03a09c3f9 100644 --- a/packages/geo/src/lib/filter/time-filter-form/time-filter-form.component.ts +++ b/packages/geo/src/lib/filter/time-filter-form/time-filter-form.component.ts @@ -77,7 +77,7 @@ export class TimeFilterFormComponent implements OnInit { public startListYears: string[] = []; public endListYears: string[] = []; - public interval: any; + public interval: number; public playIcon = 'play-circle'; public resetIcon = 'replay'; @@ -383,7 +383,7 @@ export class TimeFilterFormComponent implements OnInit { this.stopFilter(); } else { this.playIcon = 'pause_circle'; - this.interval = setInterval( + this.interval = window.setInterval( (that) => { let newMinDateNumber; const maxDateNumber = new Date(that.max); diff --git a/packages/geo/src/lib/geometry/shared/controls/modify.ts b/packages/geo/src/lib/geometry/shared/controls/modify.ts index 49a6f3ede..cbb72270c 100644 --- a/packages/geo/src/lib/geometry/shared/controls/modify.ts +++ b/packages/geo/src/lib/geometry/shared/controls/modify.ts @@ -274,6 +274,7 @@ export class ModifyControl { return; } + this.deactivateModifyInteraction(); this.deactivateModifyInteraction(); this.olModifyInteraction = undefined; } diff --git a/packages/geo/src/lib/import-export/import-export/import-export.component.ts b/packages/geo/src/lib/import-export/import-export/import-export.component.ts index cecd9e5b7..3a57e0c3e 100644 --- a/packages/geo/src/lib/import-export/import-export/import-export.component.ts +++ b/packages/geo/src/lib/import-export/import-export/import-export.component.ts @@ -252,7 +252,7 @@ export class ImportExportComponent implements OnDestroy, OnInit { this.form.patchValue(exportOptions, { emitEvent: true }); if (exportOptions.layers) { this.computeFormats( - exportOptions.layers.map((l) => this.map.getLayerById(l)) + exportOptions.layers.map((l) => this.map.layerController.getById(l)) ); } }); @@ -277,7 +277,9 @@ export class ImportExportComponent implements OnDestroy, OnInit { const selectedLayers = layersId instanceof Array ? layersId : [layersId]; this.form.patchValue({ layers: selectedLayers }, { emitEvent: false }); - const layers = selectedLayers.map((l) => this.map.getLayerById(l)); + const layers = selectedLayers.map((l) => + this.map.layerController.getById(l) + ); this.computeFormats(layers); if (this.formats$.value.indexOf(this.form.value.format) === -1) { @@ -432,7 +434,7 @@ export class ImportExportComponent implements OnDestroy, OnInit { } public getLayerTitleById(id): string { - return this.map.getLayerById(id)?.title; + return this.map.layerController.getById(id)?.title; } layerHasSelectedFeatures(layer: Layer): boolean { @@ -492,7 +494,7 @@ export class ImportExportComponent implements OnDestroy, OnInit { const previousSpecs = this.previousLayerSpecs$.value; if (previousSpecs && previousSpecs.length) { previousSpecs.forEach((specs) => { - const previousLayer = this.map.getLayerById(specs.id); + const previousLayer = this.map.layerController.getById(specs.id); previousLayer.visible = specs.visible; previousLayer.opacity = specs.opacity; (previousLayer as any).queryable = specs.queryable; @@ -568,7 +570,7 @@ export class ImportExportComponent implements OnDestroy, OnInit { for (const layerId of data.layers) { this.loading$.next(true); - const layer = this.map.getLayerById(layerId); + const layer = this.map.layerController.getById(layerId); if (isLayerGroup(layer)) { continue; } @@ -717,7 +719,7 @@ export class ImportExportComponent implements OnDestroy, OnInit { ): Promise { return data.layers.reduce(async (typesPromise, layerId) => { const types = await typesPromise; - const layer = this.map.getLayerById(layerId); + const layer = this.map.layerController.getById(layerId); if (isLayerGroup(layer)) { return typesPromise; } 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 6fdd5e05f..fcc199c65 100644 --- a/packages/geo/src/lib/import-export/shared/export.service.ts +++ b/packages/geo/src/lib/import-export/shared/export.service.ts @@ -260,7 +260,7 @@ export class ExportService { const workbook = utils.book_new(); for (const layerName of data.layers) { - const layer = map.getLayerById(layerName); + const layer = map.layerController.getById(layerName); if (isLayerGroup(layer)) { continue; } @@ -285,7 +285,7 @@ export class ExportService { } private getLayerTitleFromId(id: string, map: IgoMap): string { - const layer = map.getLayerById(id); + const layer = map.layerController.getById(id); return layer.title; } diff --git a/packages/geo/src/lib/import-export/shared/import.utils.ts b/packages/geo/src/lib/import-export/shared/import.utils.ts index fb3c60a2a..24de8b5b1 100644 --- a/packages/geo/src/lib/import-export/shared/import.utils.ts +++ b/packages/geo/src/lib/import-export/shared/import.utils.ts @@ -69,7 +69,7 @@ export function addLayerAndFeaturesToMap( style: randomStyle }) as VectorLayer; layer.setExtent(computeOlFeaturesExtent(olFeatures, map.viewProjection)); - map.addLayer(layer); + map.layerController.add(layer); moveToOlFeatures(map.viewController, olFeatures); return layer; @@ -227,7 +227,7 @@ export function addLayerAndFeaturesStyledToMap( imposedLayerOptions ) ); - map.addLayer(layer); + map.layerController.add(layer); if (zoomTo) { moveToOlFeatures(map.viewController, olFeatures); } diff --git a/packages/geo/src/lib/layer/shared/layer-controller.ts b/packages/geo/src/lib/layer/shared/layer-controller.ts index 15b19266a..8eadc969a 100644 --- a/packages/geo/src/lib/layer/shared/layer-controller.ts +++ b/packages/geo/src/lib/layer/shared/layer-controller.ts @@ -81,7 +81,7 @@ export class LayerController extends LayerSelectionModel { ]; } - get baseLayers(): ReadonlyArray { + get baseLayers(): readonly Layer[] { return this._baseLayers; } @@ -89,7 +89,7 @@ export class LayerController extends LayerSelectionModel { return this.baseLayers.find((layer) => layer.visible); } - get treeLayers(): ReadonlyArray { + get treeLayers(): readonly AnyLayer[] { return this.tree.data; } @@ -117,12 +117,23 @@ export class LayerController extends LayerSelectionModel { } selectBaseLayer(layer: Layer): void { + if (!isBaseLayer(layer)) { + return; + } + if (this.baseLayerSelection) { this.baseLayerSelection.visible = false; } layer.visible = true; this.baseLayerSelection = layer; + + this._map.viewController.olView.setMinZoom( + layer.dataSource.options.minZoom || (this._map.options.view || {}).minZoom + ); + this._map.viewController.olView.setMaxZoom( + layer.dataSource.options.maxZoom || (this._map.options.view || {}).maxZoom + ); } remove(...layers: AnyLayer[]): void { @@ -230,7 +241,7 @@ export class LayerController extends LayerSelectionModel { increment: number ): number[] { const index = position.pop(); - let nextPosition = position.concat(index + increment); + const nextPosition = position.concat(index + increment); const layer = this.tree.getNodeByPosition(nextPosition); if (layer && !layer.showInLayerList) { const nextIndex = increment > 1 ? 1 : increment; diff --git a/packages/geo/src/lib/map/baselayers-switcher/baselayers-switcher.component.ts b/packages/geo/src/lib/map/baselayers-switcher/baselayers-switcher.component.ts index 7409d86a8..524917d67 100644 --- a/packages/geo/src/lib/map/baselayers-switcher/baselayers-switcher.component.ts +++ b/packages/geo/src/lib/map/baselayers-switcher/baselayers-switcher.component.ts @@ -1,5 +1,5 @@ import { NgClass, NgFor, NgIf } from '@angular/common'; -import { AfterViewInit, Component, Input } from '@angular/core'; +import { AfterViewInit, Component, Input, OnDestroy } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; @@ -7,6 +7,8 @@ import { MatTooltipModule } from '@angular/material/tooltip'; import { IgoLanguageModule } from '@igo2/core/language'; import { Media, MediaService } from '@igo2/core/media'; +import { Subscription } from 'rxjs'; + import { Layer } from '../../layer/shared'; import { IgoMap } from '../shared/map'; import { baseLayersSwitcherSlideInOut } from './baselayers-switcher.animation'; @@ -29,7 +31,7 @@ import { MiniBaseMapComponent } from './mini-basemap.component'; IgoLanguageModule ] }) -export class BaseLayersSwitcherComponent implements AfterViewInit { +export class BaseLayersSwitcherComponent implements AfterViewInit, OnDestroy { @Input() map: IgoMap; @Input() useStaticIcon: boolean; @@ -37,6 +39,8 @@ export class BaseLayersSwitcherComponent implements AfterViewInit { public expand = false; public showButton = true; + private layers$$: Subscription; + get hasMoreThanTwo(): boolean { return this.baseLayers.length > 1; } @@ -49,11 +53,15 @@ export class BaseLayersSwitcherComponent implements AfterViewInit { } ngAfterViewInit() { - this.map.layerController.baseLayers$.subscribe((layers) => { + this.layers$$ = this.map.layerController.baseLayers$.subscribe((layers) => { this._baseLayers = layers ?? []; }); } + ngOnDestroy() { + this.layers$$.unsubscribe(); + } + collapseOrExpand() { if (this.hasMoreThanTwo || this.useStaticIcon) { this.expand = !this.expand; diff --git a/packages/geo/src/lib/map/baselayers-switcher/mini-basemap.component.ts b/packages/geo/src/lib/map/baselayers-switcher/mini-basemap.component.ts index 9717be092..df8fed901 100644 --- a/packages/geo/src/lib/map/baselayers-switcher/mini-basemap.component.ts +++ b/packages/geo/src/lib/map/baselayers-switcher/mini-basemap.component.ts @@ -88,7 +88,7 @@ export class MiniBaseMapComponent implements AfterViewInit, OnDestroy { if (this.disabled) { return; } - this.map.changeBaseLayer(baseLayer); + this.map.layerController.selectBaseLayer(baseLayer); this.appRef.tick(); } @@ -118,7 +118,7 @@ export class MiniBaseMapComponent implements AfterViewInit, OnDestroy { ); const layer = this.layerService.createLayer(options); - this.basemap.addLayer(layer); + this.basemap.layerController.add(layer); this.handleLinkedBaseLayer(layer); } @@ -149,7 +149,7 @@ export class MiniBaseMapComponent implements AfterViewInit, OnDestroy { baseLayer: false } as LayerOptions ); - this.basemap.addLayer( + this.basemap.layerController.add( this.layerService.createLayer(linkedLayerOptions) ); } diff --git a/packages/geo/src/lib/map/shared/hover-feature.directive.ts b/packages/geo/src/lib/map/shared/hover-feature.directive.ts index 4d74d53f1..3a64dc7ec 100644 --- a/packages/geo/src/lib/map/shared/hover-feature.directive.ts +++ b/packages/geo/src/lib/map/shared/hover-feature.directive.ts @@ -52,7 +52,6 @@ export class HoverFeatureDirective implements OnInit, OnDestroy { new EntityStore>([]); private lastTimeoutRequest; private store$$: Subscription; - private layers$$: Subscription; private selectionLayer: olLayerVectorTile; private selectionMVT = {}; @@ -215,7 +214,6 @@ export class HoverFeatureDirective implements OnInit, OnDestroy { this.unlistenToMapPointerMove(); this.unsubscribeToPointerStore(); this.unlistenToMapSingleClick(); - this.layers$$?.unsubscribe(); } /** diff --git a/packages/geo/src/lib/map/shared/map.abstract.ts b/packages/geo/src/lib/map/shared/map.abstract.ts index 22e4e5f6f..9da4e65ea 100644 --- a/packages/geo/src/lib/map/shared/map.abstract.ts +++ b/packages/geo/src/lib/map/shared/map.abstract.ts @@ -1,8 +1,6 @@ import { SubjectStatus } from '@igo2/utils'; -import { Layer as OlLayer } from 'ol/layer'; import { Projection } from 'ol/proj'; -import { Source } from 'ol/source'; import { Map } from 'ol'; import { BehaviorSubject, Subject } from 'rxjs'; @@ -19,6 +17,7 @@ import { import { MapControlsOptions, MapExtent, + MapOptions, MapViewOptions } from '../shared/map.interface'; import { LayerWatcher, LayerWatcherChange } from '../utils'; @@ -39,6 +38,7 @@ export abstract class MapBase { selectedFeatures$: BehaviorSubject; bufferDataSource: FeatureDataSource; layerWatcher: LayerWatcher; + readonly options: MapOptions; // Getter layerController: LayerController; @@ -46,7 +46,6 @@ export abstract class MapBase { viewProjection: Projection; projectionCode: string; - abstract init(): void; abstract setTarget(id: string): void; abstract updateView(options: MapViewOptions): void; abstract setView(options: MapViewOptions): void; @@ -54,16 +53,6 @@ export abstract class MapBase { abstract getCenter(projection?: string | Projection): [number, number]; abstract getExtent(projection?: string | Projection): MapExtent; abstract getZoom(): number; - abstract changeBaseLayer(baseLayer: Layer): void; - abstract getBaseLayers(): AnyLayer[]; - abstract getLayerById(id: string): AnyLayer | undefined; - abstract getLayerByAlias(alias: string): AnyLayer; + /** @deprecated find a way to remove this method. For now we discourage to use it until we find the way to remove it */ abstract getLayerByOlUId(olUId: string): AnyLayer; - abstract getLayerByOlLayer(olLayer: OlLayer): AnyLayer; - /** @deprecated */ - abstract addLayer(...layers: AnyLayer[]): void; - /** @deprecated */ - abstract removeLayer(...layers: AnyLayer[]): void; - /** @deprecated */ - abstract removeAllLayers(): void; } diff --git a/packages/geo/src/lib/map/shared/map.ts b/packages/geo/src/lib/map/shared/map.ts index 7a69e96a8..625593023 100644 --- a/packages/geo/src/lib/map/shared/map.ts +++ b/packages/geo/src/lib/map/shared/map.ts @@ -7,18 +7,16 @@ import olView, { ViewOptions } from 'ol/View'; import olControlAttribution from 'ol/control/Attribution'; import olControlScaleLine from 'ol/control/ScaleLine'; import * as olinteraction from 'ol/interaction'; -import olLayer from 'ol/layer/Layer'; import * as olproj from 'ol/proj'; import OlProjection from 'ol/proj/Projection'; import * as olproj4 from 'ol/proj/proj4'; -import olSource from 'ol/source/Source'; import { getUid } from 'ol/util'; import proj4 from 'proj4'; import { BehaviorSubject, Subject } from 'rxjs'; import { FeatureDataSource } from '../../datasource/shared/datasources/feature-datasource'; -import { LayerController, isBaseLayer, isLayerItem } from '../../layer'; +import { LayerController } from '../../layer'; import { AnyLayer, Layer } from '../../layer/shared/layers'; import { Overlay } from '../../overlay/shared/overlay'; import { LayerWatcher, LayerWatcherChange } from '../utils/layer-watcher'; @@ -53,7 +51,7 @@ export class IgoMap implements MapBase { public bufferDataSource: FeatureDataSource; public layerWatcher: LayerWatcher; - private options: MapOptions; + readonly options: MapOptions; private mapViewOptions: MapViewOptions; private defaultOptions: Partial = { controls: { attribution: false } @@ -254,70 +252,10 @@ export class IgoMap implements MapBase { return this.viewController.getZoom(); } - changeBaseLayer(layer: AnyLayer) { - if (!isBaseLayer(layer)) { - return; - } - - this.layerController.selectBaseLayer(layer); - - // TODO(MIGO2-493): The LayerController doesn't limit the zoom - this.viewController.olView.setMinZoom( - layer.dataSource.options.minZoom || (this.options.view || {}).minZoom - ); - this.viewController.olView.setMaxZoom( - layer.dataSource.options.maxZoom || (this.options.view || {}).maxZoom - ); - } - - /** @deprecated use this.layerController.baseLayers */ - getBaseLayers(): AnyLayer[] { - return [...this.layerController.baseLayers]; - } - - /** @deprecated use this.layerController.getById */ - getLayerById(id: string): AnyLayer { - return this.layerController.getById(id); - } - - getLayerByAlias(alias: string): AnyLayer { - return this.layerController.all.find( - (layer) => isLayerItem(layer) && layer.alias && layer.alias === alias - ); - } - + /** @deprecated find a way to remove this method. For now we discourage to use it until we find the way to remove it */ getLayerByOlUId(olUId: string): AnyLayer { return this.layerController.all.find( (layer) => getUid(layer.ol) && getUid(layer.ol) === olUId ); } - - getLayerByOlLayer(olLayer: olLayer): AnyLayer { - const olUId = getUid(olLayer); - return this.getLayerByOlUId(olUId); - } - - /** - * @deprecated use this.layerController.add - */ - addLayer(...layers: AnyLayer[]) { - this.layerController.add(...layers); - } - - /** - * Remove many layers - * @deprecated use this.layerController.remove - * @param layers Layers to remove - */ - removeLayer(...layers: AnyLayer[]) { - this.layerController.remove(...layers); - } - - /** - * Remove all layers - * @deprecated use this.layerController.reset - */ - removeAllLayers() { - this.layerController.reset(); - } } diff --git a/packages/geo/src/lib/metadata/metadata-button/metadata-button.component.ts b/packages/geo/src/lib/metadata/metadata-button/metadata-button.component.ts index 934528c12..05f02d561 100644 --- a/packages/geo/src/lib/metadata/metadata-button/metadata-button.component.ts +++ b/packages/geo/src/lib/metadata/metadata-button/metadata-button.component.ts @@ -80,7 +80,7 @@ export class MetadataButtonComponent { if (!this.layer) { return; } - return this.layer.options as any; + return this.layer.options; } } diff --git a/packages/geo/src/lib/query/shared/query.directive.ts b/packages/geo/src/lib/query/shared/query.directive.ts index 6751762c1..3b0fd52cc 100644 --- a/packages/geo/src/lib/query/shared/query.directive.ts +++ b/packages/geo/src/lib/query/shared/query.directive.ts @@ -200,7 +200,9 @@ export class QueryDirective implements AfterViewInit, OnDestroy { this.map.ol.forEachFeatureAtPixel( event.pixel, (featureOL: OlFeature, layerOL: any) => { - const layer = this.map.getLayerById(layerOL.values_._layer.id); + const layer = this.map.layerController.getById( + layerOL.values_._layer.id + ); if (isLayerGroup(layer) || !layer.displayed) { return; } diff --git a/packages/geo/src/lib/query/shared/query.service.ts b/packages/geo/src/lib/query/shared/query.service.ts index b295fe20b..de20a6a9c 100644 --- a/packages/geo/src/lib/query/shared/query.service.ts +++ b/packages/geo/src/lib/query/shared/query.service.ts @@ -70,6 +70,7 @@ export class QueryService { // the directive accept array in this format [observable, observable...] // if we use multiple 'url' in queryUrl so the result => this form [observable, observable, [observable, observable]] // so we need to flat the array + // eslint-disable-next-line prefer-spread const flattenedQueries$ = [].concat.apply([], queries$); return flattenedQueries$; } diff --git a/packages/geo/src/lib/search/search-results/search-results-add-button.component.ts b/packages/geo/src/lib/search/search-results/search-results-add-button.component.ts index 1ad85d047..392e8dd97 100644 --- a/packages/geo/src/lib/search/search-results/search-results-add-button.component.ts +++ b/packages/geo/src/lib/search/search-results/search-results-add-button.component.ts @@ -264,7 +264,7 @@ export class SearchResultAddButtonComponent implements OnInit, OnDestroy { if (event.type === 'click') { this.map.layersAddedByClick$.next([layer]); } - this.map.addLayer(layer); + this.map.layerController.add(layer); }) ); } @@ -287,7 +287,7 @@ export class SearchResultAddButtonComponent implements OnInit, OnDestroy { if (!layer) { return; } - this.map.removeLayer(layer); + this.map.layerController.remove(layer); } isInResolutionsRange(resolution: number) { @@ -300,7 +300,9 @@ export class SearchResultAddButtonComponent implements OnInit, OnDestroy { isVisible() { if (this.layer?.data?.sourceOptions?.id) { - const oLayer = this.map.getLayerById(this.layer.data.sourceOptions.id); + const oLayer = this.map.layerController.getBySourceId( + this.layer.data.sourceOptions.id + ); this.isVisible$.next(oLayer?.visible ?? false); } diff --git a/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts b/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts index 8ced4a9d0..086d931e8 100644 --- a/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts +++ b/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts @@ -55,7 +55,6 @@ export class SearchPointerSummaryDirective new EntityStore([]); private lastTimeoutRequest; private store$$: Subscription; - private layers$$: Subscription; private reverseSearch$$: Subscription[] = []; private hasPointerReverseSearchSource = false; @@ -157,7 +156,6 @@ export class SearchPointerSummaryDirective this.unlistenToMapPointerMove(); this.unsubscribeToPointerStore(); this.unsubscribeReverseSearch(); - this.layers$$?.unsubscribe(); } /** diff --git a/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts b/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts index faf6ef7c2..108e7173c 100644 --- a/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts +++ b/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts @@ -221,7 +221,7 @@ export class EditionWorkspaceService { } as WFSoptions }) .subscribe((workspaceLayer: VectorLayer) => { - map.addLayer(workspaceLayer); + map.layerController.add(workspaceLayer); layer.ol.setProperties( { linkedLayers: { diff --git a/packages/geo/src/lib/workspace/shared/edition-workspace.ts b/packages/geo/src/lib/workspace/shared/edition-workspace.ts index b2aa24034..e99ccff82 100644 --- a/packages/geo/src/lib/workspace/shared/edition-workspace.ts +++ b/packages/geo/src/lib/workspace/shared/edition-workspace.ts @@ -101,7 +101,7 @@ export class EditionWorkspace extends Workspace { this.drawControl.setGeometryType(this.geometryType.Point as any); if (this.olDrawingLayer) { - this.map.removeLayer(this.olDrawingLayer); + this.map.layerController.remove(this.olDrawingLayer); } this.olDrawingLayer = new VectorLayer({ @@ -329,7 +329,7 @@ export class EditionWorkspace extends Workspace { this.olDrawingLayer.dataSource.ol.clear(); this.olDrawingLayer.dataSource.ol.addFeature(featureOl); - this.map.addLayer(this.olDrawingLayer); + this.map.layerController.add(this.olDrawingLayer); this.deactivateDrawControl(); this.createModifyInteraction(featureOl, feature, workspace); @@ -340,7 +340,7 @@ export class EditionWorkspace extends Workspace { * Layer refresh will automatically add the new feature into the store. */ deleteDrawings() { - this.map.removeLayer(this.olDrawingLayer); + this.map.layerController.remove(this.olDrawingLayer); this.olDrawingLayerSource.clear(); this.map.ol.removeInteraction(this.modify); } diff --git a/packages/geo/src/lib/workspace/shared/wms-workspace.service.ts b/packages/geo/src/lib/workspace/shared/wms-workspace.service.ts index eaf1d2653..9da838495 100644 --- a/packages/geo/src/lib/workspace/shared/wms-workspace.service.ts +++ b/packages/geo/src/lib/workspace/shared/wms-workspace.service.ts @@ -191,7 +191,7 @@ export class WmsWorkspaceService { } as WFSoptions }) .subscribe((workspaceLayer: VectorLayer) => { - map.addLayer(workspaceLayer); + map.layerController.add(workspaceLayer); layer.ol.setProperties( { linkedLayers: { diff --git a/packages/geo/src/lib/workspace/shared/workspace.utils.ts b/packages/geo/src/lib/workspace/shared/workspace.utils.ts index 6620308c4..242dfd878 100644 --- a/packages/geo/src/lib/workspace/shared/workspace.utils.ts +++ b/packages/geo/src/lib/workspace/shared/workspace.utils.ts @@ -106,11 +106,13 @@ export function addOrRemoveLayer( return; } map.layersAddedByClick$.next([layer]); - map.addLayer(layer); + map.layerController.add(layer); }); } else if (action === 'remove') { const addedLayerId = generateIdFromSourceOptions(so.sourceOptions); - map.removeLayer(map.layerController.all.find((l) => l.id === addedLayerId)); + map.layerController.remove( + map.layerController.all.find((l) => l.id === addedLayerId) + ); } } diff --git a/packages/geo/src/locale/en.geo.json b/packages/geo/src/locale/en.geo.json index fd0cffe27..394a45127 100644 --- a/packages/geo/src/locale/en.geo.json +++ b/packages/geo/src/locale/en.geo.json @@ -541,9 +541,7 @@ "restArea": "Rest area", "cycleStop": "Cycle stop", "cultpatri": "Culture and heritage", - "unites": "Units (apartments, offices, etc.)", - "stations-partenaires": "Hydrometric stations (partenaires)", - "stations-publique": "Hydrometric stations (publique)" + "unites": "Units (apartments, offices, etc.)" }, "restrictExtent": { "map": "Map extent", @@ -649,7 +647,6 @@ "warning": "Warning", "freehandControl": "Freehand", "group": { - "aleas": "Hazards", "toponyme": "Toponym", "culture": "Culture", "education": "Education", @@ -708,9 +705,7 @@ "penitencier-fed": "Federal penitentiaries", "penitencier-prov": "Provincial penitentiaries", "polices": "Police station", - "unites": "Unit number", - "stations-hydro-partenaires": "Hydrometric stations (partenaires)", - "stations-hydro-publique": "Hydrometric stations (publique)" + "unites": "Unit number" }, "measure": { "dialog": { diff --git a/packages/geo/src/locale/fr.geo.json b/packages/geo/src/locale/fr.geo.json index 44723a707..809f2867c 100644 --- a/packages/geo/src/locale/fr.geo.json +++ b/packages/geo/src/locale/fr.geo.json @@ -540,9 +540,7 @@ "restArea": "Halte routière", "cycleStop": "Halte cyclable", "cultpatri": "Culture et patrimoine", - "unites": "Unités (appartements, bureaux, etc.)", - "stations-partenaires": "Stations hydrométriques (partenaires)", - "stations-publique": "Stations hydrométriques (publique)" + "unites": "Unités (appartements, bureaux, etc.)" }, "restrictExtent": { "map": "Étendue de la carte", @@ -649,7 +647,6 @@ "warning": "Avertissement", "freehandControl": "À main levée", "group": { - "aleas": "Aléas", "toponyme": "Toponyme", "culture": "Culture", "education": "Éducation", @@ -708,9 +705,7 @@ "penitencier-fed": "Pénitenciers fédéraux", "penitencier-prov": "Pénitenciers provinciaux", "polices": "Poste de police", - "unites": "Numéro d'unite", - "stations-hydro-partenaires": "Stations hydrométriques (partenaires)", - "stations-hydro-publique": "Stations hydrométriques (publique)" + "unites": "Numéro d'unite" }, "measure": { "dialog": { diff --git a/packages/integration/src/lib/directions/directions.state.ts b/packages/integration/src/lib/directions/directions.state.ts index cab6a6f32..879bf1109 100644 --- a/packages/integration/src/lib/directions/directions.state.ts +++ b/packages/integration/src/lib/directions/directions.state.ts @@ -53,11 +53,15 @@ export class DirectionState { }); this.mapState.map.layerController.all$.subscribe(() => { - if (!this.mapState.map.getLayerById('igo-direction-stops-layer')) { + if ( + !this.mapState.map.layerController.getById('igo-direction-stops-layer') + ) { this.stopsStore.deleteMany(this.stopsStore.all()); this.stopsFeatureStore.deleteMany(this.stopsFeatureStore.all()); // not necessary } - if (!this.mapState.map.getLayerById('igo-direction-route-layer')) { + if ( + !this.mapState.map.layerController.getById('igo-direction-route-layer') + ) { this.routesFeatureStore.deleteMany(this.routesFeatureStore.all()); } }); diff --git a/packages/integration/src/lib/draw/draw.state.ts b/packages/integration/src/lib/draw/draw.state.ts index 59ccd7a30..76304e83e 100644 --- a/packages/integration/src/lib/draw/draw.state.ts +++ b/packages/integration/src/lib/draw/draw.state.ts @@ -24,7 +24,7 @@ export class DrawState { constructor(private mapState: MapState) { this.mapState.map.layerController.all$.subscribe(() => { this.layersID.forEach((layerId) => { - if (!this.mapState.map.getLayerById(layerId)) { + if (!this.mapState.map.layerController.getById(layerId)) { const deletedStore = this.stores.find( (store) => store.layer.id === layerId ); diff --git a/packages/integration/src/lib/filter/active-time-filter-tool/active-time-filter-tool.component.ts b/packages/integration/src/lib/filter/active-time-filter-tool/active-time-filter-tool.component.ts index 4690df847..013280f3b 100644 --- a/packages/integration/src/lib/filter/active-time-filter-tool/active-time-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/active-time-filter-tool/active-time-filter-tool.component.ts @@ -1,13 +1,7 @@ import { Component } from '@angular/core'; import { ToolComponent } from '@igo2/common/tool'; -import { - IgoMap, - Layer, - LayerController, - TimeFilterItemComponent, - isLayerItem -} from '@igo2/geo'; +import { IgoMap, Layer, TimeFilterItemComponent, isLayerItem } from '@igo2/geo'; import { MapState } from '../../map/map.state'; import { toolSlideInOut } from './active-time-filter-tool.animation'; @@ -29,13 +23,10 @@ export class ActiveTimeFilterToolComponent { get map(): IgoMap { return this.mapState.map; } - get layerController(): LayerController { - return this.map.layerController; - } get layer(): Layer { - for (const lay of this.layerController.all) { - if (isLayerItem(lay) && this.layerController.isSelected(lay)) { + for (const lay of this.map.layerController.all) { + if (isLayerItem(lay) && this.map.layerController.isSelected(lay)) { return lay; } } diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index ef489c5d7..5d38f3125 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -405,7 +405,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { this.activeLayers = []; const index = this.layers.indexOf(layer); this.layers.splice(index, 1); - this.map.removeLayer(layer); + this.map.layerController.remove(layer); } } } else { @@ -417,7 +417,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { ) { const index = this.layers.indexOf(layer); this.layers.splice(index, 1); - this.map.removeLayer(layer); + this.map.layerController.remove(layer); } } } @@ -495,7 +495,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { ol.addFeatures(featuresOl); layer.ol.setStyle(this.defaultStyle); - this.map.addLayer(layer); + this.map.layerController.add(layer); this.layers.push(layer); this.activeLayers.push(layer); @@ -563,7 +563,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { (prevLayer) => prevLayer.id === layer.id ); if (previousLayer) { - this.map.removeLayer(previousLayer); + this.map.layerController.remove(previousLayer); i = i - 1; layer.title = (features[0].meta.title + ' ' + @@ -575,7 +575,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { layer.options.title = layer.title; } this.iterator = i; - this.map.addLayer(layer); + this.map.layerController.add(layer); this.layers.push(layer); this.pushLayer(layer); this.cdRef.detectChanges(); @@ -644,7 +644,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { (prevLayer) => prevLayer.id === layer.id ); if (previousLayer) { - this.map.removeLayer(previousLayer); + this.map.layerController.remove(previousLayer); i = i - 1; layer.title = (features[0].meta.title + ' ' + @@ -655,7 +655,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { )) as string; layer.options.title = layer.title; } - this.map.addLayer(layer); + this.map.layerController.add(layer); this.layers.push(layer); this.pushLayer(layer); this.cdRef.detectChanges(); diff --git a/packages/utils/src/lib/tree/tree.ts b/packages/utils/src/lib/tree/tree.ts index ce468a6ca..fc1b3bb5b 100644 --- a/packages/utils/src/lib/tree/tree.ts +++ b/packages/utils/src/lib/tree/tree.ts @@ -25,11 +25,11 @@ export class Tree { this._data = this.sortDeep(initialData); } - get data(): ReadonlyArray { + get data(): readonly T[] { return this._data; } - get flattened(): ReadonlyArray { + get flattened(): readonly T[] { return this.flatten([...this.data]); } diff --git a/projects/demo/src/app/geo/catalog/catalog.component.ts b/projects/demo/src/app/geo/catalog/catalog.component.ts index 24f953749..29d7cbc93 100644 --- a/projects/demo/src/app/geo/catalog/catalog.component.ts +++ b/projects/demo/src/app/geo/catalog/catalog.component.ts @@ -77,7 +77,7 @@ export class AppCatalogComponent implements OnInit { this.layerService .createLayers(layers) - .subscribe((layers) => this.map.addLayer(...layers)); + .subscribe((layers) => this.map.layerController.add(...layers)); this.loadCatalogs(); diff --git a/projects/demo/src/app/geo/directions/directions.component.ts b/projects/demo/src/app/geo/directions/directions.component.ts index 6688ebe18..a94213e29 100644 --- a/projects/demo/src/app/geo/directions/directions.component.ts +++ b/projects/demo/src/app/geo/directions/directions.component.ts @@ -95,6 +95,6 @@ export class AppDirectionsComponent { this.layerService .createLayers(layers) - .subscribe((layers) => this.map.addLayer(...layers)); + .subscribe((layers) => this.map.layerController.add(...layers)); } } diff --git a/projects/demo/src/app/geo/draw/draw.component.ts b/projects/demo/src/app/geo/draw/draw.component.ts index 8a439fbca..ebf8e0a0b 100644 --- a/projects/demo/src/app/geo/draw/draw.component.ts +++ b/projects/demo/src/app/geo/draw/draw.component.ts @@ -66,6 +66,6 @@ export class AppDrawComponent { this.layerService .createLayers(layers) - .subscribe((layers) => this.map.addLayer(...layers)); + .subscribe((layers) => this.map.layerController.add(...layers)); } } diff --git a/projects/demo/src/app/geo/feature/feature.component.ts b/projects/demo/src/app/geo/feature/feature.component.ts index e0110ec36..36685213c 100644 --- a/projects/demo/src/app/geo/feature/feature.component.ts +++ b/projects/demo/src/app/geo/feature/feature.component.ts @@ -177,7 +177,7 @@ export class AppFeatureComponent implements OnInit, OnDestroy { } satisfies OSMDataSourceOptions }) .subscribe((layer) => { - this.map.addLayer(layer); + this.map.layerController.add(layer); }); this.layerService @@ -197,7 +197,7 @@ export class AppFeatureComponent implements OnInit, OnDestroy { } }) .subscribe((layer: VectorLayer) => { - this.map.addLayer(layer); + this.map.layerController.add(layer); this.store.bindLayer(layer); loadingStrategy.activate(); selectionStrategy.activate(); diff --git a/projects/demo/src/app/geo/geometry/geometry.component.ts b/projects/demo/src/app/geo/geometry/geometry.component.ts index e17bd36ef..ced7d0397 100644 --- a/projects/demo/src/app/geo/geometry/geometry.component.ts +++ b/projects/demo/src/app/geo/geometry/geometry.component.ts @@ -80,7 +80,7 @@ export class AppGeometryComponent implements OnInit, OnDestroy { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, diff --git a/projects/demo/src/app/geo/hover/hover.component.ts b/projects/demo/src/app/geo/hover/hover.component.ts index b1b814151..da32c8f7f 100644 --- a/projects/demo/src/app/geo/hover/hover.component.ts +++ b/projects/demo/src/app/geo/hover/hover.component.ts @@ -65,7 +65,7 @@ export class AppHoverComponent { url: 'https://geoegl.msp.gouv.qc.ca/carto/tms/1.0.0/carte_gouv_qc_public@EPSG_3857/{z}/{x}/{-y}.png' } } satisfies TileLayerOptions) - .subscribe((layer: TileLayer) => this.map.addLayer(layer)); + .subscribe((layer: TileLayer) => this.map.layerController.add(layer)); const wfsDatasourcePoint: WFSDataSourceOptions = { type: 'wfs', @@ -128,7 +128,9 @@ export class AppHoverComponent { } } }; - this.map.addLayer(this.layerService.createLayer(layerOptions)); + this.map.layerController.add( + this.layerService.createLayer(layerOptions) + ); }); } } diff --git a/projects/demo/src/app/geo/import-export/import-export.component.ts b/projects/demo/src/app/geo/import-export/import-export.component.ts index 9850a5fbd..61c47a82a 100644 --- a/projects/demo/src/app/geo/import-export/import-export.component.ts +++ b/projects/demo/src/app/geo/import-export/import-export.component.ts @@ -54,6 +54,6 @@ export class AppImportExportComponent { type: 'osm' } } satisfies LayerOptions) - .subscribe((layer: TileLayer) => this.map.addLayer(layer)); + .subscribe((layer: TileLayer) => this.map.layerController.add(layer)); } } diff --git a/projects/demo/src/app/geo/layer/layer.component.ts b/projects/demo/src/app/geo/layer/layer.component.ts index ed659e297..09eb36f76 100644 --- a/projects/demo/src/app/geo/layer/layer.component.ts +++ b/projects/demo/src/app/geo/layer/layer.component.ts @@ -201,6 +201,6 @@ export class AppLayerComponent { this.layerService .createLayers(layers) - .subscribe((layers) => this.map.addLayer(...layers)); + .subscribe((layers) => this.map.layerController.add(...layers)); } } diff --git a/projects/demo/src/app/geo/legend/legend.component.ts b/projects/demo/src/app/geo/legend/legend.component.ts index 97dd1b49e..af02db0c5 100644 --- a/projects/demo/src/app/geo/legend/legend.component.ts +++ b/projects/demo/src/app/geo/legend/legend.component.ts @@ -57,7 +57,7 @@ export class AppLegendComponent { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', visible: true, @@ -82,7 +82,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -99,7 +99,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -116,7 +116,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -130,7 +130,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -144,7 +144,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -158,7 +158,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -172,7 +172,7 @@ export class AppLegendComponent { } } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); const datasource: WMSDataSourceOptions = { type: 'wms', @@ -199,7 +199,9 @@ export class AppLegendComponent { extern: true } }; - this.map.addLayer(this.layerService.createLayer(layerOptions)); + this.map.layerController.add( + this.layerService.createLayer(layerOptions) + ); }); } } diff --git a/projects/demo/src/app/geo/measure/measure.component.ts b/projects/demo/src/app/geo/measure/measure.component.ts index 5eedb995a..cbd31bec2 100644 --- a/projects/demo/src/app/geo/measure/measure.component.ts +++ b/projects/demo/src/app/geo/measure/measure.component.ts @@ -60,7 +60,7 @@ export class AppMeasureComponent { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, diff --git a/projects/demo/src/app/geo/ogc-filter/ogc-filter.component.ts b/projects/demo/src/app/geo/ogc-filter/ogc-filter.component.ts index 450154f5a..f32fab170 100644 --- a/projects/demo/src/app/geo/ogc-filter/ogc-filter.component.ts +++ b/projects/demo/src/app/geo/ogc-filter/ogc-filter.component.ts @@ -68,7 +68,7 @@ export class AppOgcFilterComponent { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, @@ -135,7 +135,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasource) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (PropertyIsEqualTo OR Intersects polygon)', source: dataSource, @@ -185,7 +185,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceDuringFilter) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (During, Step: P2D)', id: '1', @@ -243,7 +243,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceDuringFilterTime) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (During, Step: PT4H)', id: '2', @@ -302,7 +302,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceDuringFilterTimeMonth) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (During, Step: P1M)', id: '3', @@ -361,7 +361,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceDuringFilterTimeYear) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (During, Step: P1Y)', id: '4', @@ -419,7 +419,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceDuringFilterTimeInterval) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (During, Interval from Now, Step: P1D)', id: '5', @@ -477,7 +477,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceDuringFilterTimeRestrictedToStep) .subscribe((dataSource: WFSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles (During, RestrictToStep, Step: P1M)', id: '6', @@ -529,7 +529,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(wmsOgcFilterOptions) .subscribe((dataSource: WMSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Inondations (During)', source: dataSource @@ -682,7 +682,7 @@ export class AppOgcFilterComponent { this.dataSourceService .createAsyncDataSource(filterableWMSwithPushButtons) .subscribe((dataSource: WMSDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Filterable WMS layers with predefined filters (push buttons)', diff --git a/projects/demo/src/app/geo/overlay/overlay.component.ts b/projects/demo/src/app/geo/overlay/overlay.component.ts index e52a82c4e..b2c322176 100644 --- a/projects/demo/src/app/geo/overlay/overlay.component.ts +++ b/projects/demo/src/app/geo/overlay/overlay.component.ts @@ -50,7 +50,7 @@ export class AppOverlayComponent implements OnInit, AfterViewInit { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, diff --git a/projects/demo/src/app/geo/print/print.component.ts b/projects/demo/src/app/geo/print/print.component.ts index 355960de0..dacacb0bb 100644 --- a/projects/demo/src/app/geo/print/print.component.ts +++ b/projects/demo/src/app/geo/print/print.component.ts @@ -55,7 +55,7 @@ export class AppPrintComponent { crossOrigin: 'anonymous' } } satisfies TileLayerOptions) - .subscribe((layer: TileLayer) => this.map.addLayer(layer)); + .subscribe((layer: TileLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -70,7 +70,7 @@ export class AppPrintComponent { crossOrigin: 'anonymous' } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -85,7 +85,7 @@ export class AppPrintComponent { crossOrigin: 'anonymous' } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.layerService .createAsyncLayer({ @@ -100,6 +100,6 @@ export class AppPrintComponent { crossOrigin: 'anonymous' } } satisfies ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); } } diff --git a/projects/demo/src/app/geo/query/query.component.ts b/projects/demo/src/app/geo/query/query.component.ts index 376b09715..56e167e00 100644 --- a/projects/demo/src/app/geo/query/query.component.ts +++ b/projects/demo/src/app/geo/query/query.component.ts @@ -85,7 +85,7 @@ export class AppQueryComponent { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, @@ -106,7 +106,7 @@ export class AppQueryComponent { } } as QueryableDataSourceOptions) .subscribe((dataSource: DataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'WMS', source: dataSource @@ -127,7 +127,7 @@ export class AppQueryComponent { } } as QueryableDataSourceOptions) .subscribe((dataSource: DataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'WMS html with a pre call in GML', source: dataSource @@ -156,7 +156,7 @@ export class AppQueryComponent { } } } as ImageLayerOptions) - .subscribe((layer: ImageLayer) => this.map.addLayer(layer)); + .subscribe((layer: ImageLayer) => this.map.layerController.add(layer)); this.dataSourceService .createAsyncDataSource({ @@ -168,7 +168,7 @@ export class AppQueryComponent { ] } as FeatureDataSourceOptions) .subscribe((dataSource: FeatureDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Vector layer', source: dataSource @@ -198,7 +198,9 @@ export class AppQueryComponent { source: 'ahocevar' } } as VectorTileLayerOptions) - .subscribe((layer: VectorTileLayer) => this.map.addLayer(layer)); + .subscribe((layer: VectorTileLayer) => + this.map.layerController.add(layer) + ); } addFeatures(dataSource: FeatureDataSource): void { diff --git a/projects/demo/src/app/geo/search/search.component.ts b/projects/demo/src/app/geo/search/search.component.ts index d3ef1ef19..4db72b8b1 100644 --- a/projects/demo/src/app/geo/search/search.component.ts +++ b/projects/demo/src/app/geo/search/search.component.ts @@ -134,7 +134,7 @@ export class AppSearchComponent implements OnInit, OnDestroy { type: 'osm' } } satisfies LayerOptions) - .subscribe((layer) => this.map.addLayer(layer)); + .subscribe((layer) => this.map.layerController.add(layer)); this.igoReverseSearchCoordsFormatEnabled = Boolean(this.storageService.get('reverseSearchCoordsFormatEnabled')) || diff --git a/projects/demo/src/app/geo/simple-map/simple-map.component.ts b/projects/demo/src/app/geo/simple-map/simple-map.component.ts index b3557a6d8..2c48c2064 100644 --- a/projects/demo/src/app/geo/simple-map/simple-map.component.ts +++ b/projects/demo/src/app/geo/simple-map/simple-map.component.ts @@ -59,7 +59,7 @@ export class AppSimpleMapComponent { baseLayer: true }) .subscribe((layer) => { - this.map.addLayer(layer); + this.map.layerController.add(layer); }); } diff --git a/projects/demo/src/app/geo/spatial-filter/spatial-filter.component.ts b/projects/demo/src/app/geo/spatial-filter/spatial-filter.component.ts index af9b26d7c..ecdeaa460 100644 --- a/projects/demo/src/app/geo/spatial-filter/spatial-filter.component.ts +++ b/projects/demo/src/app/geo/spatial-filter/spatial-filter.component.ts @@ -140,7 +140,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, @@ -215,7 +215,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { } clearMap(): void { - this.map.removeLayer(...this.layers); + this.map.layerController.remove(...this.layers); this.layers = []; this.activeLayers = []; this.thematicLength = 0; @@ -352,7 +352,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { this.activeLayers = []; const index: number = this.layers.indexOf(layer); this.layers.splice(index, 1); - this.map.removeLayer(layer); + this.map.layerController.remove(layer); } } } else { @@ -364,7 +364,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { ) { const index: number = this.layers.indexOf(layer); this.layers.splice(index, 1); - this.map.removeLayer(layer); + this.map.layerController.remove(layer); } } } @@ -438,7 +438,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { const ol = dataSource.ol as olSourceVector | olSourceCluster; ol.addFeatures(featuresOl); olLayer.ol.setStyle(this.defaultStyle); - this.map.addLayer(olLayer); + this.map.layerController.add(olLayer); this.layers.push(olLayer); this.activeLayers.push(olLayer); this.cdRef.detectChanges(); @@ -501,7 +501,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { const ol: olSourceCluster = dataSource.ol; ol.getSource().addFeatures(featuresOl); if (this.layers.find((layer) => layer.id === olLayer.id)) { - this.map.removeLayer( + this.map.layerController.remove( this.layers.find((layer) => layer.id === olLayer.id) ); i = i - 1; @@ -515,7 +515,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { olLayer.options.title = olLayer.title; } this.iterator = i; - this.map.addLayer(olLayer); + this.map.layerController.add(olLayer); this.layers.push(olLayer); this.pushLayer(olLayer); this.cdRef.detectChanges(); @@ -582,7 +582,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { const ol = dataSource.ol as olSourceVector; ol.addFeatures(featuresOl); if (this.layers.find((layer) => layer.id === olLayer.id)) { - this.map.removeLayer( + this.map.layerController.remove( this.layers.find((layer) => layer.id === olLayer.id) ); i = i - 1; @@ -595,7 +595,7 @@ export class AppSpatialFilterComponent implements OnInit, OnDestroy { )) satisfies string; olLayer.options.title = olLayer.title; } - this.map.addLayer(olLayer); + this.map.layerController.add(olLayer); this.layers.push(olLayer); this.pushLayer(olLayer); this.cdRef.detectChanges(); diff --git a/projects/demo/src/app/geo/time-filter/time-filter.component.ts b/projects/demo/src/app/geo/time-filter/time-filter.component.ts index 3d07d0300..ff2ba9725 100644 --- a/projects/demo/src/app/geo/time-filter/time-filter.component.ts +++ b/projects/demo/src/app/geo/time-filter/time-filter.component.ts @@ -58,7 +58,7 @@ export class AppTimeFilterComponent { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', baseLayer: true, @@ -89,7 +89,7 @@ export class AppTimeFilterComponent { this.dataSourceService .createAsyncDataSource(datasourceYear) .subscribe((dataSource: TimeFilterableDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'Embâcles', source: dataSource diff --git a/projects/demo/src/app/geo/workspace/workspace.component.ts b/projects/demo/src/app/geo/workspace/workspace.component.ts index 3cc34b2b2..d93f98d60 100644 --- a/projects/demo/src/app/geo/workspace/workspace.component.ts +++ b/projects/demo/src/app/geo/workspace/workspace.component.ts @@ -127,7 +127,7 @@ export class AppWorkspaceComponent implements OnInit { type: 'osm' } satisfies OSMDataSourceOptions) .subscribe((dataSource: OSMDataSource) => { - this.map.addLayer( + this.map.layerController.add( this.layerService.createLayer({ title: 'OSM', source: dataSource, @@ -162,7 +162,9 @@ export class AppWorkspaceComponent implements OnInit { visible: true, source: dataSource }; - this.map.addLayer(this.layerService.createLayer(layerOptions)); + this.map.layerController.add( + this.layerService.createLayer(layerOptions) + ); }); } From e6cadaace7aeefcc4315d9de702e894a6cc8058f Mon Sep 17 00:00:00 2001 From: Alexandre Caron Date: Wed, 6 Nov 2024 14:37:29 -0500 Subject: [PATCH 2/2] fix: map service type --- packages/geo/src/lib/map/shared/map.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/geo/src/lib/map/shared/map.service.ts b/packages/geo/src/lib/map/shared/map.service.ts index cf09917d8..cc3011ec8 100644 --- a/packages/geo/src/lib/map/shared/map.service.ts +++ b/packages/geo/src/lib/map/shared/map.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; -import { MapBase } from './map.abstract'; +import type { IgoMap } from './map'; /** * MapService @@ -15,13 +15,13 @@ import { MapBase } from './map.abstract'; providedIn: 'root' }) export class MapService { - private map: MapBase; + private map: IgoMap; - getMap(): MapBase { + getMap(): IgoMap { return this.map; } - setMap(map: MapBase) { + setMap(map: IgoMap) { this.map = map; } }