From 3aee99beaa4ac506185649fd421af33b0a7e9e8f Mon Sep 17 00:00:00 2001 From: Dereck Lynch Date: Thu, 29 Aug 2019 10:08:29 -0400 Subject: [PATCH] feat(layer-item): layer's resolution change depending of the network state * remove excludeAttribute from mapOffline * add cluster datasource to offline sources * vector and cluster source don't change Url in offline mode --- .../cluster-datasource.interface.ts | 1 + .../layer/layer-item/layer-item.component.ts | 12 +++++++- .../lib/map/shared/mapOffline.directive.ts | 30 ++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/packages/geo/src/lib/datasource/shared/datasources/cluster-datasource.interface.ts b/packages/geo/src/lib/datasource/shared/datasources/cluster-datasource.interface.ts index 180147b9a3..979eb01499 100644 --- a/packages/geo/src/lib/datasource/shared/datasources/cluster-datasource.interface.ts +++ b/packages/geo/src/lib/datasource/shared/datasources/cluster-datasource.interface.ts @@ -8,4 +8,5 @@ export interface ClusterDataSourceOptions extends FeatureDataSourceOptions { distance?: number; source?: FeatureDataSource; ol?: olSourceVector; + pathOffline?: string; } diff --git a/packages/geo/src/lib/layer/layer-item/layer-item.component.ts b/packages/geo/src/lib/layer/layer-item/layer-item.component.ts index 82314da180..16f4094cdb 100644 --- a/packages/geo/src/lib/layer/layer-item/layer-item.component.ts +++ b/packages/geo/src/lib/layer/layer-item/layer-item.component.ts @@ -10,6 +10,7 @@ import { Subscription, BehaviorSubject } from 'rxjs'; import { MetadataLayerOptions } from '../../metadata/shared/metadata.interface'; import { layerIsQueryable } from '../../query/shared/query.utils'; import { Layer, TooltipType } from '../shared/layers'; +import { NetworkService, ConnectionState } from '@igo2/core'; @Component({ selector: 'igo-layer-item', @@ -29,6 +30,8 @@ export class LayerItemComponent implements OnInit, OnDestroy { private resolution$$: Subscription; + private state: ConnectionState; + @Input() layer: Layer; @Input() toggleLegendOnVisibilityChange: boolean = false; @@ -50,7 +53,9 @@ export class LayerItemComponent implements OnInit, OnDestroy { get opacity() { return this.layer.opacity * 100; } set opacity(opacity: number) { this.layer.opacity = opacity / 100; } - constructor() {} + constructor( + private networkService: NetworkService + ) {} ngOnInit() { const legend = this.layer.dataSource.options.legend || {}; @@ -66,6 +71,11 @@ export class LayerItemComponent implements OnInit, OnDestroy { this.onResolutionChange(); }); this.tooltipText = this.computeTooltip(); + + this.networkService.currentState().subscribe((state: ConnectionState) => { + this.state = state; + this.onResolutionChange(); + }); } ngOnDestroy() { diff --git a/packages/geo/src/lib/map/shared/mapOffline.directive.ts b/packages/geo/src/lib/map/shared/mapOffline.directive.ts index 1b15b4c785..f47b372d32 100644 --- a/packages/geo/src/lib/map/shared/mapOffline.directive.ts +++ b/packages/geo/src/lib/map/shared/mapOffline.directive.ts @@ -6,6 +6,7 @@ import { MapBrowserComponent } from '../map-browser/map-browser.component'; import { FeatureDataSourceOptions } from '../../datasource/shared/datasources/feature-datasource.interface'; import { XYZDataSourceOptions } from '../../datasource/shared/datasources/xyz-datasource.interface'; import { MVTDataSourceOptions } from '../../datasource/shared/datasources/mvt-datasource.interface'; +import { ClusterDataSourceOptions } from '../../datasource/shared/datasources/cluster-datasource.interface'; @Directive({ selector: '[igoMapOffline]' @@ -43,28 +44,41 @@ export class MapOfflineDirective implements AfterViewInit { layerList.forEach(layer => { if (layer.options.sourceOptions.type === 'mvt') { sourceOptions = (layer.options.sourceOptions as MVTDataSourceOptions); + layer.ol.getSource().clear(); } else if (layer.options.sourceOptions.type === 'xyz') { sourceOptions = (layer.options.sourceOptions as XYZDataSourceOptions); } else if (layer.options.sourceOptions.type === 'vector') { sourceOptions = (layer.options.sourceOptions as FeatureDataSourceOptions); + } else if (layer.options.sourceOptions.type === 'cluster') { + sourceOptions = (layer.options.sourceOptions as ClusterDataSourceOptions); } else { - return; + if (this.state.connection === false) { + layer.ol.setMaxResolution(0); + return; + } else if (this.state.connection === true) { + layer.ol.setMaxResolution(Infinity); + return; + } } + if (sourceOptions.pathOffline && this.state.connection === false) { - if (sourceOptions.excludeAttributeOffline) { - sourceOptions.excludeAttributeBackUp = sourceOptions.excludeAttribute; - sourceOptions.excludeAttribute = sourceOptions.excludeAttributeOffline; + if (sourceOptions.type === 'vector' || 'cluster') { + return; } - layer.ol.getSource().clear(); layer.ol.getSource().setUrl(sourceOptions.pathOffline); } else if (sourceOptions.pathOffline && this.state.connection === true) { - if (sourceOptions.excludeAttributeBackUp) { - sourceOptions.excludeAttribute = sourceOptions.excludeAttributeBackUp; + if (sourceOptions.type === 'vector' || 'cluster') { + return; } - layer.ol.getSource().clear(); layer.ol.getSource().setUrl(sourceOptions.url); + } else { + if (this.state.connection === false) { + layer.ol.setMaxResolution(0); + } else if (this.state.connection === true) { + layer.ol.setMaxResolution(Infinity); + } } }); }