From 3e9439ec882954d381885ab808533aa46e6fa4f3 Mon Sep 17 00:00:00 2001 From: aziz Date: Mon, 24 Jul 2023 21:01:21 +0200 Subject: [PATCH 1/7] feat(context): set map zoom level after importing context --- .../src/lib/context-manager/shared/layer-context.directive.ts | 4 ++++ 1 file changed, 4 insertions(+) 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 82deaa588b..4df9baff46 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 @@ -131,6 +131,10 @@ export class LayerContextDirective implements OnInit, OnDestroy { this.layerService.createAsyncIdbLayers(context.uri).pipe(debounceTime(500)) .subscribe((layers: Layer[]) => this.handleAddLayers(layers)); + if(context.map.view.keepCurrentView) { + this.map.setView(context.map.view); + } + } private handleAddLayers(layers: Layer[]) { From 034d00cd647a402e77f86deb7d59cc73c799ab9f Mon Sep 17 00:00:00 2001 From: aziz Date: Fri, 4 Aug 2023 21:24:22 +0200 Subject: [PATCH 2/7] map set view if import new context --- .../shared/layer-context.directive.ts | 4 ---- .../context-manager/shared/map-context.directive.ts | 13 +++++++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) 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 4df9baff46..82deaa588b 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 @@ -131,10 +131,6 @@ export class LayerContextDirective implements OnInit, OnDestroy { this.layerService.createAsyncIdbLayers(context.uri).pipe(debounceTime(500)) .subscribe((layers: Layer[]) => this.handleAddLayers(layers)); - if(context.map.view.keepCurrentView) { - this.map.setView(context.map.view); - } - } private handleAddLayers(layers: Layer[]) { diff --git a/packages/context/src/lib/context-manager/shared/map-context.directive.ts b/packages/context/src/lib/context-manager/shared/map-context.directive.ts index 35513c58b7..8a69e85e01 100644 --- a/packages/context/src/lib/context-manager/shared/map-context.directive.ts +++ b/packages/context/src/lib/context-manager/shared/map-context.directive.ts @@ -59,9 +59,18 @@ export class MapContextDirective implements OnInit, OnDestroy { // this.component.map.ol.setTarget(target); const viewContext: ContextMapView = context.map.view; - if (!this.component.view || viewContext.keepCurrentView !== true || context.map.view.projection !== this.map.projection) { - this.component.view = viewContext as MapViewOptions; + // set map view first load + if (!this.component.view) { + this.component.view = viewContext; + } else { + if ( + context.map.view.projection !== this.map.projection || + viewContext.keepCurrentView === true + ) { + this.component.map.setView(viewContext); + } } + if (this.component.map.geolocationController) { this.component.map.geolocationController.updateGeolocationOptions(viewContext); } From c56ab714095d7bf0668e8ccb3738c44cb37502d1 Mon Sep 17 00:00:00 2001 From: aziz Date: Fri, 4 Aug 2023 21:29:45 +0200 Subject: [PATCH 3/7] solve lint --- .../src/lib/context-manager/shared/map-context.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/context/src/lib/context-manager/shared/map-context.directive.ts b/packages/context/src/lib/context-manager/shared/map-context.directive.ts index 8a69e85e01..a0564286d9 100644 --- a/packages/context/src/lib/context-manager/shared/map-context.directive.ts +++ b/packages/context/src/lib/context-manager/shared/map-context.directive.ts @@ -3,7 +3,7 @@ import { Directive, OnInit, OnDestroy } from '@angular/core'; import { Subscription } from 'rxjs'; import { filter } from 'rxjs/operators'; -import { MapViewOptions, MapBrowserComponent, MapControlsOptions, MapScaleLineOptions } from '@igo2/geo'; +import { MapBrowserComponent, MapControlsOptions, MapScaleLineOptions } from '@igo2/geo'; import type { IgoMap } from '@igo2/geo'; import { ContextService } from './context.service'; From 64320c0eb657d5eb642df0381f6f504737c11d3f Mon Sep 17 00:00:00 2001 From: aziz Date: Thu, 10 Aug 2023 20:39:01 +0200 Subject: [PATCH 4/7] delete resolution from viewOptions before updateing map view --- .../context-manager/shared/map-context.directive.ts | 10 +--------- packages/geo/src/lib/map/shared/map.ts | 3 ++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/context/src/lib/context-manager/shared/map-context.directive.ts b/packages/context/src/lib/context-manager/shared/map-context.directive.ts index a0564286d9..346baf3176 100644 --- a/packages/context/src/lib/context-manager/shared/map-context.directive.ts +++ b/packages/context/src/lib/context-manager/shared/map-context.directive.ts @@ -59,16 +59,8 @@ export class MapContextDirective implements OnInit, OnDestroy { // this.component.map.ol.setTarget(target); const viewContext: ContextMapView = context.map.view; - // set map view first load - if (!this.component.view) { + if (!this.component.view || viewContext.keepCurrentView === true || context.map.view.projection !== this.map.projection) { this.component.view = viewContext; - } else { - if ( - context.map.view.projection !== this.map.projection || - viewContext.keepCurrentView === true - ) { - this.component.map.setView(viewContext); - } } if (this.component.map.geolocationController) { diff --git a/packages/geo/src/lib/map/shared/map.ts b/packages/geo/src/lib/map/shared/map.ts index be8d7b92ad..a3da946ed2 100644 --- a/packages/geo/src/lib/map/shared/map.ts +++ b/packages/geo/src/lib/map/shared/map.ts @@ -175,7 +175,8 @@ export class IgoMap { updateView(options: MapViewOptions) { const currentView = this.ol.getView(); - const viewOptions = Object.assign( + // to update the zoom we need to delete 'resolution' property + const {resolution, ...viewOptions} = Object.assign( { zoom: currentView.getZoom() }, From e65c119874dc16bd30984746e35ffbfbe2702baa Mon Sep 17 00:00:00 2001 From: aziz Date: Fri, 11 Aug 2023 21:42:58 +0200 Subject: [PATCH 5/7] check resolution befor keeping zoom level --- packages/geo/src/lib/map/shared/map.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/geo/src/lib/map/shared/map.ts b/packages/geo/src/lib/map/shared/map.ts index a3da946ed2..c47ae9e162 100644 --- a/packages/geo/src/lib/map/shared/map.ts +++ b/packages/geo/src/lib/map/shared/map.ts @@ -175,15 +175,16 @@ export class IgoMap { updateView(options: MapViewOptions) { const currentView = this.ol.getView(); - // to update the zoom we need to delete 'resolution' property - const {resolution, ...viewOptions} = Object.assign( - { - zoom: currentView.getZoom() - }, - currentView.getProperties() - ); + const viewOptions: MapViewOptions = { + ...currentView.getProperties(), + ...options + }; + + if (options.zoom && options.resolution === null) { + viewOptions.resolution = undefined; + } - this.setView(Object.assign(viewOptions, options)); + this.setView(viewOptions); if (options.maxZoomOnExtent) { this.viewController.maxZoomOnExtent = options.maxZoomOnExtent; } From 0d357321fec873416ced97d8a3ab353f351c2f75 Mon Sep 17 00:00:00 2001 From: aziz Date: Mon, 14 Aug 2023 16:06:07 +0200 Subject: [PATCH 6/7] change === by == --- packages/geo/src/lib/map/shared/map.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/geo/src/lib/map/shared/map.ts b/packages/geo/src/lib/map/shared/map.ts index c47ae9e162..2bc2f263f5 100644 --- a/packages/geo/src/lib/map/shared/map.ts +++ b/packages/geo/src/lib/map/shared/map.ts @@ -180,7 +180,7 @@ export class IgoMap { ...options }; - if (options.zoom && options.resolution === null) { + if (options.zoom && options.resolution == null) { viewOptions.resolution = undefined; } From eadfda847bbcb5e897aca78caade79325716a7cf Mon Sep 17 00:00:00 2001 From: aziz Date: Mon, 14 Aug 2023 16:09:33 +0200 Subject: [PATCH 7/7] change eqeqeq always to smart --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 53d7acf0c5..75c471607f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -24,7 +24,7 @@ ], "unused-imports/no-unused-imports": "error", "no-multi-spaces": "error", - "eqeqeq": ["error", "always"], + "eqeqeq": ["error", "smart"], "semi": ["error", "always"], "no-trailing-spaces": "error", "no-multiple-empty-lines": "error",