From f327c87f2a676ad8287f744e412b9b711cbd0f53 Mon Sep 17 00:00:00 2001 From: ange_lu Date: Wed, 7 Feb 2024 16:07:32 +0100 Subject: [PATCH] Feat: adding viewAngle and rotation. #216 --- .../src/lib/map-state.service.spec.ts | 3 +++ .../services-map-state/src/lib/map-state.service.ts | 6 +++--- .../services-map-state/src/lib/types/map-state.ts | 12 +++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/projects/services-map-state/src/lib/map-state.service.spec.ts b/projects/services-map-state/src/lib/map-state.service.spec.ts index 2d799b2bb..1cbb7dc9d 100644 --- a/projects/services-map-state/src/lib/map-state.service.spec.ts +++ b/projects/services-map-state/src/lib/map-state.service.spec.ts @@ -26,6 +26,7 @@ describe('MapStateService', () => { const stateTime = new Date().toISOString(); // this is passed on new MapState() const state = new MapState(4, { lat: 48, lon: 11 }); state.time = stateTime; + state.rotation = 20; service.setMapState(state); @@ -34,6 +35,8 @@ describe('MapStateService', () => { expect(sta.center.lon).toEqual(11); expect(sta.zoom).toEqual(4); expect(sta.time).toEqual(stateTime); + expect(sta.rotation).toEqual(20); + expect(sta.viewAngle).toEqual(0); }); })); diff --git a/projects/services-map-state/src/lib/map-state.service.ts b/projects/services-map-state/src/lib/map-state.service.ts index b95afd18d..c35fa7520 100644 --- a/projects/services-map-state/src/lib/map-state.service.ts +++ b/projects/services-map-state/src/lib/map-state.service.ts @@ -24,11 +24,11 @@ export class MapStateService { } this.lastAction.next('setState'); if (state instanceof MapState) { - const newState = new MapState(state.zoom, state.center, state.options, state.extent, state.time); + const newState = new MapState(state.zoom, state.center, state.options, state.extent, state.time, state.viewAngle, state.rotation); this.mapState.next(newState); } else { const stateOptions: IMapStateOptions = { ...{ notifier: 'user' }, ...state.options }; - const newState = new MapState(state.zoom, state.center, stateOptions, state.extent, state.time); + const newState = new MapState(state.zoom, state.center, stateOptions, state.extent, state.time, state.viewAngle, state.rotation); this.mapState.next(newState); } } @@ -44,7 +44,7 @@ export class MapStateService { this.lastAction.next('setExtent'); const state = this.getMapState().getValue(); state.options.notifier = notifier; - const newState = new MapState(state.zoom, state.center, state.options, extent, state.time); + const newState = new MapState(state.zoom, state.center, state.options, extent, state.time, state.viewAngle, state.rotation); this.mapState.next(newState); } diff --git a/projects/services-map-state/src/lib/types/map-state.ts b/projects/services-map-state/src/lib/types/map-state.ts index ede508290..04cf351d0 100644 --- a/projects/services-map-state/src/lib/types/map-state.ts +++ b/projects/services-map-state/src/lib/types/map-state.ts @@ -16,6 +16,10 @@ export interface IMapState { extent?: TGeoExtent; /** iso 8601 Datestring */ time?: string; + /** from nadir in degrees */ + viewAngle?: number; + /** from north in degrees */ + rotation?: number; } /** @@ -33,8 +37,12 @@ export class MapState implements IMapState { extent: TGeoExtent; /** iso 8601 Datestring */ time: string; + /** from nadir in degrees */ + viewAngle: number; + /** from north in degrees */ + rotation: number; - constructor(zoom: number, center: IMapCenter, options?: IMapStateOptions, extent: TGeoExtent = [-180.0, -90.0, 180.0, 90.0], time: string = new Date().toISOString()) { + constructor(zoom: number, center: IMapCenter, options?: IMapStateOptions, extent: TGeoExtent = [-180.0, -90.0, 180.0, 90.0], time: string = new Date().toISOString(), viewAngle: number = 0, rotation: number = 0) { const defaultOptions = { maxzoom: 0, minzoom: 0, @@ -44,6 +52,8 @@ export class MapState implements IMapState { this.center = center; this.extent = extent; this.time = time; + this.viewAngle = viewAngle; + this.rotation = rotation; this.options = Object.assign(defaultOptions, options); }