From 1de795f9c158a64a8e3d4c61913766fb454e2baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Tue, 7 Jan 2020 17:05:08 -0500 Subject: [PATCH 1/3] in progress --- .../auth/src/lib/shared/auth.interceptor.ts | 18 ++- .../src/lib/catalog/shared/catalog.service.ts | 8 +- .../datasource/shared/capabilities.service.ts | 43 ++++--- .../src/lib/map/shared/controllers/view.ts | 108 +++++++++++++++--- .../catalog-browser-tool.component.ts | 12 +- proxy.conf.json | 2 +- 6 files changed, 150 insertions(+), 41 deletions(-) diff --git a/packages/auth/src/lib/shared/auth.interceptor.ts b/packages/auth/src/lib/shared/auth.interceptor.ts index 7e0e20bc8d..2b630af992 100644 --- a/packages/auth/src/lib/shared/auth.interceptor.ts +++ b/packages/auth/src/lib/shared/auth.interceptor.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; - import { HttpEvent, HttpInterceptor, @@ -8,6 +7,7 @@ import { HttpRequest } from '@angular/common/http'; import { Observable } from 'rxjs'; +import { Md5 } from 'ts-md5'; import { ConfigService } from '@igo2/core'; import { TokenService } from './token.service'; @@ -42,9 +42,23 @@ export class AuthInterceptor implements HttpInterceptor { } const authHeader = `Bearer ${token}`; - const authReq = req.clone({ + let authReq = req.clone({ headers: req.headers.set('Authorization', authHeader) }); + + const tokenDecoded: any = this.tokenService.decode(); + if ( + authReq.params.has('_i') && + tokenDecoded && + tokenDecoded.user && + tokenDecoded.user.sourceId + ) { + const hashUser = Md5.hashStr(tokenDecoded.user.sourceId) as string; + authReq = authReq.clone({ + params: authReq.params.set('_i', hashUser) + }); + } + return next.handle(authReq); } diff --git a/packages/geo/src/lib/catalog/shared/catalog.service.ts b/packages/geo/src/lib/catalog/shared/catalog.service.ts index dc2540dbd6..e492325092 100644 --- a/packages/geo/src/lib/catalog/shared/catalog.service.ts +++ b/packages/geo/src/lib/catalog/shared/catalog.service.ts @@ -68,7 +68,9 @@ export class CatalogService { const catalogsFromApi$ = this.http .get(`${apiUrl}/catalogs`) .pipe( - map(catalogs => catalogs.map((c: any) => Object.assign(c, c.options))), + map(catalogs => + catalogs.map((c: any) => Object.assign(c, c.options)) + ), catchError((response: HttpErrorResponse) => EMPTY) ); observables$.push(catalogsFromApi$); @@ -96,6 +98,7 @@ export class CatalogService { } loadCatalogItems(catalog: Catalog): Observable { + console.log('ici2'); if (catalog.type === 'baselayers') { return this.loadCatalogBaseLayerItems(catalog); } else if (catalog.type === 'wmts') { @@ -232,8 +235,7 @@ export class CatalogService { LAYERS: layer.Name, FEATURE_COUNT: catalog.count, VERSION: catalog.version || '1.3.0' - } as WMSDataSourceOptionsParams - ); + } as WMSDataSourceOptionsParams); const baseSourceOptions = { type: 'wms', url: catalog.url, diff --git a/packages/geo/src/lib/datasource/shared/capabilities.service.ts b/packages/geo/src/lib/datasource/shared/capabilities.service.ts index d30a3a1bb7..e8c84e8316 100644 --- a/packages/geo/src/lib/datasource/shared/capabilities.service.ts +++ b/packages/geo/src/lib/datasource/shared/capabilities.service.ts @@ -19,8 +19,14 @@ import { ArcGISRestDataSourceOptions, TileArcGISRestDataSourceOptions } from './datasources'; -import { LegendOptions, ItemStyleOptions } from '../../layer/shared/layers/layer.interface'; -import { TimeFilterType, TimeFilterStyle } from '../../filter/shared/time-filter.enum'; +import { + LegendOptions, + ItemStyleOptions +} from '../../layer/shared/layers/layer.interface'; +import { + TimeFilterType, + TimeFilterStyle +} from '../../filter/shared/time-filter.enum'; @Injectable({ providedIn: 'root' @@ -42,7 +48,9 @@ export class CapabilitiesService { return this.getCapabilities('wms', url, version).pipe( map((capabilities: any) => { - return capabilities ? this.parseWMSOptions(baseOptions, capabilities) : undefined; + return capabilities + ? this.parseWMSOptions(baseOptions, capabilities) + : undefined; }) ); } @@ -55,7 +63,9 @@ export class CapabilitiesService { const options = this.getCapabilities('wmts', url, version).pipe( map((capabilities: any) => { - return capabilities ? this.parseWMTSOptions(baseOptions, capabilities) : undefined; + return capabilities + ? this.parseWMTSOptions(baseOptions, capabilities) + : undefined; }) ); @@ -117,17 +127,19 @@ export class CapabilitiesService { ); } - @Cacheable() + // @Cacheable() getCapabilities( service: 'wms' | 'wmts', baseUrl: string, version?: string ): Observable { + console.log('ici'); const params = new HttpParams({ fromObject: { request: 'GetCapabilities', service, - version: version || '1.3.0' + version: version || '1.3.0', + _i: 'true' } }); @@ -173,8 +185,7 @@ export class CapabilitiesService { title: layer.Title, maxResolution: getResolutionFromScale(layer.MaxScaleDenominator) || Infinity, - minResolution: - getResolutionFromScale(layer.MinScaleDenominator) || 0, + minResolution: getResolutionFromScale(layer.MinScaleDenominator) || 0, metadata: { url: metadata ? metadata.OnlineResource : undefined, extern: metadata ? true : undefined, @@ -350,18 +361,22 @@ export class CapabilitiesService { } getStyle(Style): LegendOptions { - - const styleOptions: ItemStyleOptions[] = Style - .map((style) => { + const styleOptions: ItemStyleOptions[] = Style.map(style => { return { name: style.Name, title: style.Title }; }) - // Handle repeat the style "default" in output (MapServer or OpenLayer) - .filter((item, index, self) => self.findIndex((i: ItemStyleOptions) => i.name === item.name) === index); + // Handle repeat the style "default" in output (MapServer or OpenLayer) + .filter( + (item, index, self) => + self.findIndex((i: ItemStyleOptions) => i.name === item.name) === + index + ); - const legendOptions: LegendOptions = { stylesAvailable: styleOptions } as LegendOptions; + const legendOptions: LegendOptions = { + stylesAvailable: styleOptions + } as LegendOptions; return legendOptions; } diff --git a/packages/geo/src/lib/map/shared/controllers/view.ts b/packages/geo/src/lib/map/shared/controllers/view.ts index 336ef2c2b4..caec039e47 100644 --- a/packages/geo/src/lib/map/shared/controllers/view.ts +++ b/packages/geo/src/lib/map/shared/controllers/view.ts @@ -22,7 +22,6 @@ export interface MapViewControllerOptions { * Controller to handle map view interactions */ export class MapViewController extends MapController { - /** * Observable of the current resolution */ @@ -36,7 +35,7 @@ export class MapViewController extends MapController { /** * Extent stream */ - private extent$ = new Subject<{extent: MapExtent, action: MapViewAction}>(); + private extent$ = new Subject<{ extent: MapExtent; action: MapViewAction }>(); /** * Subscription to the movement stream @@ -63,7 +62,9 @@ export class MapViewController extends MapController { /** * OL View */ - get olView(): OlView { return this.olMap.getView(); } + get olView(): OlView { + return this.olMap.getView(); + } constructor(private options?: MapViewControllerOptions) { super(); @@ -90,7 +91,7 @@ export class MapViewController extends MapController { this.extent$$ = this.extent$ .pipe(debounceTime(25)) - .subscribe((value: {extent: MapExtent, action: MapViewAction}) => { + .subscribe((value: { extent: MapExtent; action: MapViewAction }) => { this.setExtent(value.extent, value.action); }); } @@ -135,7 +136,11 @@ export class MapViewController extends MapController { getExtent(projection?: string | OlProjection): MapExtent { let extent = this.olView.calculateExtent(this.olMap.getSize()); if (projection && extent) { - extent = olproj.transformExtent(extent, this.getOlProjection(), projection); + extent = olproj.transformExtent( + extent, + this.getOlProjection(), + projection + ); } return extent; } @@ -188,6 +193,7 @@ export class MapViewController extends MapController { * @param zoom Zoom level */ zoomTo(zoom: number) { + this.olView.cancelAnimations(); this.olView.animate({ zoom, duration: 250, @@ -201,7 +207,7 @@ export class MapViewController extends MapController { * @param extent Extent to move to */ moveToExtent(extent: [number, number, number, number]) { - this.extent$.next({extent, action: MapViewAction.Move}); + this.extent$.next({ extent, action: MapViewAction.Move }); } /** @@ -210,7 +216,7 @@ export class MapViewController extends MapController { * @param extent Extent to zoom to */ zoomToExtent(extent: [number, number, number, number]) { - this.extent$.next({extent, action: MapViewAction.Zoom}); + this.extent$.next({ extent, action: MapViewAction.Zoom }); } /** @@ -225,7 +231,7 @@ export class MapViewController extends MapController { * Reset the view rotation to 0 */ resetRotation() { - this.olView.animate({rotation: 0}); + this.olView.animate({ rotation: 0 }); } /** @@ -283,14 +289,85 @@ export class MapViewController extends MapController { * Move to the extent retrieved from the stream * @param extent Extent * @param action Either zoom or move + * @param animation With or without animation to the target extent. */ - private setExtent(extent: MapExtent, action: MapViewAction) { + private setExtent( + extent: MapExtent, + action: MapViewAction, + animation: boolean = true + ) { const olView = this.olView; - if (action === MapViewAction.Zoom) { - olView.fit(extent, {maxZoom: 17}); - } else if (action === MapViewAction.Move) { - olView.fit(extent, {maxZoom: olView.getZoom()}); - } + olView.cancelAnimations(); + const duration = animation ? 500 : 0; + const zoom = olView.getZoom(); + + // 1) Seulement pan si proche et même zoom (surement même code que 2) + // 2) Seulement pan + (dé)zoom si proche + // 3) Si loin, dézoomer + pan + zoom ? ou aucune animation ? + // Calculer la distance selon x fois l'extent courant ? + // olView.calculateExtent(); + // olView.getCenter(); + // olView.getZoom(); + const fromCenter = olView.getCenter(); + const toCenter = [ + extent[0] + (extent[2] - extent[0]) / 2, + extent[1] + (extent[3] - extent[1]) / 2 + ]; + const distCenter = Math.sqrt( + Math.pow(fromCenter[0] - toCenter[0], 2) + + Math.pow(fromCenter[1] - toCenter[1], 2) + ); + const fromExtent = olView.calculateExtent(); + const fromSize = Math.sqrt( + Math.pow(fromExtent[2] - fromExtent[0], 2) + + Math.pow(fromExtent[3] - fromExtent[1], 2) + ); + const toSize = Math.sqrt( + Math.pow(extent[2] - extent[0], 2) + Math.pow(extent[3] - extent[1], 2) + ); + const moySize = (toSize + fromSize) / 2; + const xSize = distCenter / moySize; + // console.log(xSize); + // console.log(olView); + // const size = this.olView.getSizeFromViewport_(); + // const xResolution = (extent[2] - extent[0]) / size[0]; + // const yResolution = (extent[3] - extent[1]) / size[1]; + // const resolution = Math.max(xResolution, yResolution); + // console.log(extent); + // console.log(resolution); + // let zoom2 = this.olView.getZoomForResolution(resolution); + // if (zoom2 > 17) { + // zoom2 = 17; + // } + // console.log(zoom2); + // console.log('-------------'); + // let zoomFly = 0; + // if (xSize) { + // zoomFly = Math.floor(9 / 4); + // } + // + // this.olView.animate({ + // center: toCenter, + // duration + // }); + // this.olView.animate( + // { + // zoom: zoom2 - zoomFly > 0 ? zoom2 - zoomFly : 1, + // duration: duration / 2 + // }, + // { + // zoom: zoom2, + // duration: duration / 2 + // } + // ); + + const maxZoom = action === MapViewAction.Move ? zoom : 17; + + olView.fit(extent, { + maxZoom, + padding: [0, 0, 250, 400], // TODO config mobile/desktop + duration: xSize > 4 ? 0 : duration + }); } /** @@ -332,7 +409,8 @@ export class MapViewController extends MapController { if (this.stateHistory === true) { const stateIndex = this.stateIndex; - const stateAtIndex = this.states.length === 0 ? undefined : this.states[stateIndex]; + const stateAtIndex = + this.states.length === 0 ? undefined : this.states[stateIndex]; if (!viewStatesAreEqual(state, stateAtIndex)) { this.states = this.states.slice(0, stateIndex + 1).concat([state]); this.stateIndex = this.states.length - 1; diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index ce175a1f93..607d08eed9 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -101,13 +101,13 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { * @param catalog Selected catalog */ private loadCatalogItems(catalog: Catalog) { - let store = this.catalogState.getCatalogItemsStore(catalog); - if (store !== undefined) { - this.store$.next(store); - return; - } + // let store = this.catalogState.getCatalogItemsStore(catalog); + // if (store !== undefined) { + // this.store$.next(store); + // return; + // } - store = new EntityStore([]); + const store = new EntityStore([]); this.catalogState.setCatalogItemsStore(catalog, store); this.catalogService .loadCatalogItems(catalog) diff --git a/proxy.conf.json b/proxy.conf.json index b823e6c77e..06087d314c 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -10,7 +10,7 @@ "changeOrigin": true }, "/apis/": { - "target": "https://geoegl.msp.gouv.qc.ca", + "target": "https://testgeoegl.msp.gouv.qc.ca", "secure": false, "changeOrigin": true }, From 6d415e6190bbd1a06739555485c71c995cc00046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Wed, 8 Jan 2020 12:34:03 -0500 Subject: [PATCH 2/3] in progress --- .../auth/src/lib/shared/auth.interceptor.ts | 6 +- packages/auth/src/lib/shared/auth.service.ts | 4 + .../src/lib/catalog/shared/catalog.service.ts | 8 +- .../datasource/shared/capabilities.service.ts | 4 +- .../src/lib/map/shared/controllers/view.ts | 108 +++--------------- .../catalog-browser-tool.component.ts | 28 +++-- .../src/lib/catalog/catalog.state.ts | 14 ++- 7 files changed, 63 insertions(+), 109 deletions(-) diff --git a/packages/auth/src/lib/shared/auth.interceptor.ts b/packages/auth/src/lib/shared/auth.interceptor.ts index 2b630af992..a7af3d0a5a 100644 --- a/packages/auth/src/lib/shared/auth.interceptor.ts +++ b/packages/auth/src/lib/shared/auth.interceptor.ts @@ -48,7 +48,7 @@ export class AuthInterceptor implements HttpInterceptor { const tokenDecoded: any = this.tokenService.decode(); if ( - authReq.params.has('_i') && + authReq.params.get('_i') === 'true' && tokenDecoded && tokenDecoded.user && tokenDecoded.user.sourceId @@ -57,6 +57,10 @@ export class AuthInterceptor implements HttpInterceptor { authReq = authReq.clone({ params: authReq.params.set('_i', hashUser) }); + } else if (authReq.params.get('_i') === 'true') { + authReq = authReq.clone({ + params: authReq.params.delete('_i') + }); } return next.handle(authReq); diff --git a/packages/auth/src/lib/shared/auth.service.ts b/packages/auth/src/lib/shared/auth.service.ts index 1fd26ef950..1c5422ec02 100644 --- a/packages/auth/src/lib/shared/auth.service.ts +++ b/packages/auth/src/lib/shared/auth.service.ts @@ -4,6 +4,7 @@ import { Router } from '@angular/router'; import { Observable, BehaviorSubject, of } from 'rxjs'; import { tap, catchError } from 'rxjs/operators'; +import { globalCacheBusterNotifier } from 'ngx-cacheable'; import { ConfigService, LanguageService, MessageService } from '@igo2/core'; import { Base64 } from '@igo2/utils'; @@ -28,6 +29,9 @@ export class AuthService { @Optional() private router: Router ) { this.authenticate$.next(this.authenticated); + this.authenticate$.subscribe(() => { + globalCacheBusterNotifier.next(); + }); } login(username: string, password: string): Observable { diff --git a/packages/geo/src/lib/catalog/shared/catalog.service.ts b/packages/geo/src/lib/catalog/shared/catalog.service.ts index e492325092..dc2540dbd6 100644 --- a/packages/geo/src/lib/catalog/shared/catalog.service.ts +++ b/packages/geo/src/lib/catalog/shared/catalog.service.ts @@ -68,9 +68,7 @@ export class CatalogService { const catalogsFromApi$ = this.http .get(`${apiUrl}/catalogs`) .pipe( - map(catalogs => - catalogs.map((c: any) => Object.assign(c, c.options)) - ), + map(catalogs => catalogs.map((c: any) => Object.assign(c, c.options))), catchError((response: HttpErrorResponse) => EMPTY) ); observables$.push(catalogsFromApi$); @@ -98,7 +96,6 @@ export class CatalogService { } loadCatalogItems(catalog: Catalog): Observable { - console.log('ici2'); if (catalog.type === 'baselayers') { return this.loadCatalogBaseLayerItems(catalog); } else if (catalog.type === 'wmts') { @@ -235,7 +232,8 @@ export class CatalogService { LAYERS: layer.Name, FEATURE_COUNT: catalog.count, VERSION: catalog.version || '1.3.0' - } as WMSDataSourceOptionsParams); + } as WMSDataSourceOptionsParams + ); const baseSourceOptions = { type: 'wms', url: catalog.url, diff --git a/packages/geo/src/lib/datasource/shared/capabilities.service.ts b/packages/geo/src/lib/datasource/shared/capabilities.service.ts index e8c84e8316..0c50bd945d 100644 --- a/packages/geo/src/lib/datasource/shared/capabilities.service.ts +++ b/packages/geo/src/lib/datasource/shared/capabilities.service.ts @@ -127,7 +127,9 @@ export class CapabilitiesService { ); } - // @Cacheable() + @Cacheable({ + maxCacheCount: 20 + }) getCapabilities( service: 'wms' | 'wmts', baseUrl: string, diff --git a/packages/geo/src/lib/map/shared/controllers/view.ts b/packages/geo/src/lib/map/shared/controllers/view.ts index caec039e47..336ef2c2b4 100644 --- a/packages/geo/src/lib/map/shared/controllers/view.ts +++ b/packages/geo/src/lib/map/shared/controllers/view.ts @@ -22,6 +22,7 @@ export interface MapViewControllerOptions { * Controller to handle map view interactions */ export class MapViewController extends MapController { + /** * Observable of the current resolution */ @@ -35,7 +36,7 @@ export class MapViewController extends MapController { /** * Extent stream */ - private extent$ = new Subject<{ extent: MapExtent; action: MapViewAction }>(); + private extent$ = new Subject<{extent: MapExtent, action: MapViewAction}>(); /** * Subscription to the movement stream @@ -62,9 +63,7 @@ export class MapViewController extends MapController { /** * OL View */ - get olView(): OlView { - return this.olMap.getView(); - } + get olView(): OlView { return this.olMap.getView(); } constructor(private options?: MapViewControllerOptions) { super(); @@ -91,7 +90,7 @@ export class MapViewController extends MapController { this.extent$$ = this.extent$ .pipe(debounceTime(25)) - .subscribe((value: { extent: MapExtent; action: MapViewAction }) => { + .subscribe((value: {extent: MapExtent, action: MapViewAction}) => { this.setExtent(value.extent, value.action); }); } @@ -136,11 +135,7 @@ export class MapViewController extends MapController { getExtent(projection?: string | OlProjection): MapExtent { let extent = this.olView.calculateExtent(this.olMap.getSize()); if (projection && extent) { - extent = olproj.transformExtent( - extent, - this.getOlProjection(), - projection - ); + extent = olproj.transformExtent(extent, this.getOlProjection(), projection); } return extent; } @@ -193,7 +188,6 @@ export class MapViewController extends MapController { * @param zoom Zoom level */ zoomTo(zoom: number) { - this.olView.cancelAnimations(); this.olView.animate({ zoom, duration: 250, @@ -207,7 +201,7 @@ export class MapViewController extends MapController { * @param extent Extent to move to */ moveToExtent(extent: [number, number, number, number]) { - this.extent$.next({ extent, action: MapViewAction.Move }); + this.extent$.next({extent, action: MapViewAction.Move}); } /** @@ -216,7 +210,7 @@ export class MapViewController extends MapController { * @param extent Extent to zoom to */ zoomToExtent(extent: [number, number, number, number]) { - this.extent$.next({ extent, action: MapViewAction.Zoom }); + this.extent$.next({extent, action: MapViewAction.Zoom}); } /** @@ -231,7 +225,7 @@ export class MapViewController extends MapController { * Reset the view rotation to 0 */ resetRotation() { - this.olView.animate({ rotation: 0 }); + this.olView.animate({rotation: 0}); } /** @@ -289,85 +283,14 @@ export class MapViewController extends MapController { * Move to the extent retrieved from the stream * @param extent Extent * @param action Either zoom or move - * @param animation With or without animation to the target extent. */ - private setExtent( - extent: MapExtent, - action: MapViewAction, - animation: boolean = true - ) { + private setExtent(extent: MapExtent, action: MapViewAction) { const olView = this.olView; - olView.cancelAnimations(); - const duration = animation ? 500 : 0; - const zoom = olView.getZoom(); - - // 1) Seulement pan si proche et même zoom (surement même code que 2) - // 2) Seulement pan + (dé)zoom si proche - // 3) Si loin, dézoomer + pan + zoom ? ou aucune animation ? - // Calculer la distance selon x fois l'extent courant ? - // olView.calculateExtent(); - // olView.getCenter(); - // olView.getZoom(); - const fromCenter = olView.getCenter(); - const toCenter = [ - extent[0] + (extent[2] - extent[0]) / 2, - extent[1] + (extent[3] - extent[1]) / 2 - ]; - const distCenter = Math.sqrt( - Math.pow(fromCenter[0] - toCenter[0], 2) + - Math.pow(fromCenter[1] - toCenter[1], 2) - ); - const fromExtent = olView.calculateExtent(); - const fromSize = Math.sqrt( - Math.pow(fromExtent[2] - fromExtent[0], 2) + - Math.pow(fromExtent[3] - fromExtent[1], 2) - ); - const toSize = Math.sqrt( - Math.pow(extent[2] - extent[0], 2) + Math.pow(extent[3] - extent[1], 2) - ); - const moySize = (toSize + fromSize) / 2; - const xSize = distCenter / moySize; - // console.log(xSize); - // console.log(olView); - // const size = this.olView.getSizeFromViewport_(); - // const xResolution = (extent[2] - extent[0]) / size[0]; - // const yResolution = (extent[3] - extent[1]) / size[1]; - // const resolution = Math.max(xResolution, yResolution); - // console.log(extent); - // console.log(resolution); - // let zoom2 = this.olView.getZoomForResolution(resolution); - // if (zoom2 > 17) { - // zoom2 = 17; - // } - // console.log(zoom2); - // console.log('-------------'); - // let zoomFly = 0; - // if (xSize) { - // zoomFly = Math.floor(9 / 4); - // } - // - // this.olView.animate({ - // center: toCenter, - // duration - // }); - // this.olView.animate( - // { - // zoom: zoom2 - zoomFly > 0 ? zoom2 - zoomFly : 1, - // duration: duration / 2 - // }, - // { - // zoom: zoom2, - // duration: duration / 2 - // } - // ); - - const maxZoom = action === MapViewAction.Move ? zoom : 17; - - olView.fit(extent, { - maxZoom, - padding: [0, 0, 250, 400], // TODO config mobile/desktop - duration: xSize > 4 ? 0 : duration - }); + if (action === MapViewAction.Zoom) { + olView.fit(extent, {maxZoom: 17}); + } else if (action === MapViewAction.Move) { + olView.fit(extent, {maxZoom: olView.getZoom()}); + } } /** @@ -409,8 +332,7 @@ export class MapViewController extends MapController { if (this.stateHistory === true) { const stateIndex = this.stateIndex; - const stateAtIndex = - this.states.length === 0 ? undefined : this.states[stateIndex]; + const stateAtIndex = this.states.length === 0 ? undefined : this.states[stateIndex]; if (!viewStatesAreEqual(state, stateAtIndex)) { this.states = this.states.slice(0, stateIndex + 1).concat([state]); this.stateIndex = this.states.length - 1; diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index 607d08eed9..ae851a5460 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -9,6 +9,7 @@ import { import { BehaviorSubject, Subscription } from 'rxjs'; import { EntityRecord, EntityStore, ToolComponent } from '@igo2/common'; +import { AuthService } from '@igo2/auth'; import { IgoMap, @@ -51,6 +52,11 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { */ private catalog$$: Subscription; + /** + * Subscription for authentication + */ + private authenticate$$: Subscription; + /** * Whether a group can be toggled when it's collapsed */ @@ -67,7 +73,8 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { constructor( private catalogService: CatalogService, private catalogState: CatalogState, - private mapState: MapState + private mapState: MapState, + private authService: AuthService ) {} /** @@ -83,9 +90,12 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { if (record && record.entity) { const catalog = record.entity; this.catalog = catalog; - this.loadCatalogItems(catalog); } }); + + this.authenticate$$ = this.authService.authenticate$.subscribe(() => { + this.loadCatalogItems(this.catalog); + }); } /** @@ -93,6 +103,7 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { */ ngOnDestroy() { this.catalog$$.unsubscribe(); + this.authenticate$$.unsubscribe(); } /** @@ -101,13 +112,14 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { * @param catalog Selected catalog */ private loadCatalogItems(catalog: Catalog) { - // let store = this.catalogState.getCatalogItemsStore(catalog); - // if (store !== undefined) { - // this.store$.next(store); - // return; - // } + let store = this.catalogState.getCatalogItemsStore(catalog); + if (store !== undefined) { + console.log('deja store'); + this.store$.next(store); + return; + } - const store = new EntityStore([]); + store = new EntityStore([]); this.catalogState.setCatalogItemsStore(catalog, store); this.catalogService .loadCatalogItems(catalog) diff --git a/packages/integration/src/lib/catalog/catalog.state.ts b/packages/integration/src/lib/catalog/catalog.state.ts index 849baa7f66..de80a6af9a 100644 --- a/packages/integration/src/lib/catalog/catalog.state.ts +++ b/packages/integration/src/lib/catalog/catalog.state.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; +import { AuthService } from '@igo2/auth'; import { EntityStore } from '@igo2/common'; import { Catalog, CatalogItem } from '@igo2/geo'; @@ -22,8 +23,12 @@ export class CatalogState { */ private catalogItemsStores = new Map>(); - constructor() { + constructor(authService: AuthService) { this._catalogStore = new EntityStore([]); + + authService.authenticate$.subscribe(() => { + this.clearCatalogItemsStores(); + }); } /** @@ -43,4 +48,11 @@ export class CatalogState { setCatalogItemsStore(catalog: Catalog, store: EntityStore) { this.catalogItemsStores.set(catalog.id as string, store); } + + /** + * Clear all catalog items stores + */ + clearCatalogItemsStores() { + this.catalogItemsStores.clear(); + } } From 2e2ca1036926017acd2330572baee1730cf0a6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Wed, 8 Jan 2020 14:15:21 -0500 Subject: [PATCH 3/3] lint --- .../context/src/lib/context-manager/shared/context.service.ts | 4 ++-- .../geo/src/lib/datasource/shared/capabilities.service.ts | 1 - .../catalog-browser-tool/catalog-browser-tool.component.ts | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) 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 d123d49d95..d107f5cbcf 100644 --- a/packages/context/src/lib/context-manager/shared/context.service.ts +++ b/packages/context/src/lib/context-manager/shared/context.service.ts @@ -94,7 +94,7 @@ export class ContextService { return this.http .get(url) .pipe(catchError(res => { - return this.handleError(res, id) + return this.handleError(res, id); })); } @@ -192,7 +192,7 @@ export class ContextService { return this.http.post(url, JSON.stringify(association)) .pipe(catchError(res => { - return [this.handleError(res, undefined, true)] + return [this.handleError(res, undefined, true)]; })); } diff --git a/packages/geo/src/lib/datasource/shared/capabilities.service.ts b/packages/geo/src/lib/datasource/shared/capabilities.service.ts index 0c50bd945d..a33fde7e29 100644 --- a/packages/geo/src/lib/datasource/shared/capabilities.service.ts +++ b/packages/geo/src/lib/datasource/shared/capabilities.service.ts @@ -135,7 +135,6 @@ export class CapabilitiesService { baseUrl: string, version?: string ): Observable { - console.log('ici'); const params = new HttpParams({ fromObject: { request: 'GetCapabilities', diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index ae851a5460..d09481c2d3 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -114,7 +114,6 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { private loadCatalogItems(catalog: Catalog) { let store = this.catalogState.getCatalogItemsStore(catalog); if (store !== undefined) { - console.log('deja store'); this.store$.next(store); return; }