From 12eeeb5b9b0035d0fe873bcb58c2fbaee7838876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 3 May 2023 09:42:52 -0400 Subject: [PATCH 1/3] feat(feature-datasource): add a preload options on vector source --- .../feature-datasource.interface.ts | 6 +++ .../lib/layer/shared/layers/vector-layer.ts | 38 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/geo/src/lib/datasource/shared/datasources/feature-datasource.interface.ts b/packages/geo/src/lib/datasource/shared/datasources/feature-datasource.interface.ts index 53840a1ba1..33b6a04293 100644 --- a/packages/geo/src/lib/datasource/shared/datasources/feature-datasource.interface.ts +++ b/packages/geo/src/lib/datasource/shared/datasources/feature-datasource.interface.ts @@ -16,8 +16,14 @@ export interface FeatureDataSourceOptions extends DataSourceOptions { format?: olFormatFeature; url?: string; pathOffline?: string; + preload?: PreloadOptions; excludeAttribute?: Array; excludeAttributeOffline?: Array; ol?: olSourceVector | olSource; } + +export interface PreloadOptions { + bypassVisible?: boolean; + bypassResolution?: boolean; +} diff --git a/packages/geo/src/lib/layer/shared/layers/vector-layer.ts b/packages/geo/src/lib/layer/shared/layers/vector-layer.ts index becf4f2d13..63c3c0b568 100644 --- a/packages/geo/src/lib/layer/shared/layers/vector-layer.ts +++ b/packages/geo/src/lib/layer/shared/layers/vector-layer.ts @@ -17,7 +17,7 @@ import { WebSocketDataSource } from '../../../datasource/shared/datasources/webs import { ClusterDataSource } from '../../../datasource/shared/datasources/cluster-datasource'; import { VectorWatcher } from '../../utils'; -import { IgoMap, MapExtent } from '../../../map'; +import { IgoMap, MapExtent, getResolutionFromScale } from '../../../map'; import { Layer } from './layer'; import { VectorLayerOptions } from './vector-layer.interface'; import { AuthInterceptor } from '@igo2/auth'; @@ -34,6 +34,7 @@ import { LayerDBService } from '../../../offline/layerDB/layerDB.service'; import { LayerDBData } from '../../../offline'; import BaseEvent from 'ol/events/Event'; import { olStyleToBasicIgoStyle } from '../../../style/shared/vector/conversion.utils'; +import { FeatureDataSourceOptions } from '../../../datasource/shared/datasources/feature-datasource.interface'; export class VectorLayer extends Layer { public dataSource: @@ -69,6 +70,24 @@ export class VectorLayer extends Layer { } protected createOlLayer(): olLayerVector> { + const initialOpacityValue = this.options.opacity || 1; + const initialVisibleValue = this.options.visible === true; + const initialMinResValue = this.options.minResolution || getResolutionFromScale(Number(this.options.minScaleDenom)); + const initialMaxResValue = this.options.maxResolution || getResolutionFromScale(Number(this.options.maxScaleDenom)); + const so = this.options.sourceOptions as FeatureDataSourceOptions; + if (this.dataSource instanceof FeatureDataSource) { + if (so?.preload?.bypassResolution || so?.preload?.bypassVisible) { + this.options.opacity = 0; + if (so.preload.bypassResolution && (this.options.minResolution || this.options.maxResolution)) { + this.options.minResolution = 0; + this.options.maxResolution = Infinity; + } + if (so.preload.bypassVisible && !this.options.visible) { + this.options.visible = true; + } + } + } + const olOptions = Object.assign({}, this.options, { source: this.options.source.ol as olSourceVector }); @@ -93,6 +112,23 @@ export class VectorLayer extends Layer { }); } + if ( + this.dataSource instanceof FeatureDataSource && + (so?.preload?.bypassResolution || so?.preload?.bypassVisible)) { + this.dataSource.ol.once('featuresloadend', () => { + if (initialOpacityValue) { + this.opacity = initialOpacityValue; + } + if (so.preload.bypassResolution) { + this.minResolution = initialMinResValue; + this.maxResolution = initialMaxResValue; + } + if (so.preload.bypassVisible) { + this.visible = initialVisibleValue; + } + }); + } + if (this.options.trackFeature) { this.enableTrackFeature(this.options.trackFeature); } From 6bb4bd5812b31bbcad66f5c7d3a8194b76f4c41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 3 May 2023 14:18:23 -0400 Subject: [PATCH 2/3] wip --- packages/geo/src/lib/layer/shared/layers/vector-layer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/geo/src/lib/layer/shared/layers/vector-layer.ts b/packages/geo/src/lib/layer/shared/layers/vector-layer.ts index 63c3c0b568..143f1c5abc 100644 --- a/packages/geo/src/lib/layer/shared/layers/vector-layer.ts +++ b/packages/geo/src/lib/layer/shared/layers/vector-layer.ts @@ -71,7 +71,7 @@ export class VectorLayer extends Layer { protected createOlLayer(): olLayerVector> { const initialOpacityValue = this.options.opacity || 1; - const initialVisibleValue = this.options.visible === true; + const initialVisibleValue = this.options.visible !== false; const initialMinResValue = this.options.minResolution || getResolutionFromScale(Number(this.options.minScaleDenom)); const initialMaxResValue = this.options.maxResolution || getResolutionFromScale(Number(this.options.maxScaleDenom)); const so = this.options.sourceOptions as FeatureDataSourceOptions; From 360c5063ec6e035ba4877479a5f1ec2e1e24e4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 3 May 2023 16:08:57 -0400 Subject: [PATCH 3/3] wip --- packages/geo/src/lib/layer/shared/layers/vector-layer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/geo/src/lib/layer/shared/layers/vector-layer.ts b/packages/geo/src/lib/layer/shared/layers/vector-layer.ts index 143f1c5abc..5a83a2ee87 100644 --- a/packages/geo/src/lib/layer/shared/layers/vector-layer.ts +++ b/packages/geo/src/lib/layer/shared/layers/vector-layer.ts @@ -82,7 +82,7 @@ export class VectorLayer extends Layer { this.options.minResolution = 0; this.options.maxResolution = Infinity; } - if (so.preload.bypassVisible && !this.options.visible) { + if (so.preload.bypassVisible && !initialVisibleValue) { this.options.visible = true; } }