Skip to content

Commit

Permalink
feat(feature-datasource): add a preload options on vector source (#1231)
Browse files Browse the repository at this point in the history
* feat(feature-datasource): add a preload options on vector source

* wip

* wip
  • Loading branch information
pelord authored May 3, 2023
1 parent f7bc3d8 commit c303d57
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ export interface FeatureDataSourceOptions extends DataSourceOptions {
format?: olFormatFeature;
url?: string;
pathOffline?: string;
preload?: PreloadOptions;
excludeAttribute?: Array<string>;
excludeAttributeOffline?: Array<string>;

ol?: olSourceVector<OlGeometry> | olSource;
}

export interface PreloadOptions {
bypassVisible?: boolean;
bypassResolution?: boolean;
}
38 changes: 37 additions & 1 deletion packages/geo/src/lib/layer/shared/layers/vector-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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:
Expand Down Expand Up @@ -69,6 +70,24 @@ export class VectorLayer extends Layer {
}

protected createOlLayer(): olLayerVector<olSourceVector<OlGeometry>> {
const initialOpacityValue = this.options.opacity || 1;
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;
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 && !initialVisibleValue) {
this.options.visible = true;
}
}
}

const olOptions = Object.assign({}, this.options, {
source: this.options.source.ol as olSourceVector<OlGeometry>
});
Expand All @@ -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);
}
Expand Down

0 comments on commit c303d57

Please sign in to comment.