From bb6be2db4a9e8fbf74b7038fd0c3f8c9d733f8b0 Mon Sep 17 00:00:00 2001 From: cbourget Date: Fri, 22 Nov 2019 16:01:35 -0500 Subject: [PATCH] feat(strategy): add a method to set a strategy's feature motion --- .../src/lib/feature/shared/strategies/loading.ts | 13 ++++++++++++- .../src/lib/feature/shared/strategies/selection.ts | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/feature/shared/strategies/loading.ts b/packages/geo/src/lib/feature/shared/strategies/loading.ts index 59a5ed5307..747e56e501 100644 --- a/packages/geo/src/lib/feature/shared/strategies/loading.ts +++ b/packages/geo/src/lib/feature/shared/strategies/loading.ts @@ -21,8 +21,11 @@ export class FeatureStoreLoadingStrategy extends EntityStoreStrategy { */ private stores$$ = new Map(); + private motion: FeatureMotion; + constructor(protected options: FeatureStoreLoadingStrategyOptions) { super(options); + this.setMotion(options.motion); } /** @@ -47,6 +50,14 @@ export class FeatureStoreLoadingStrategy extends EntityStoreStrategy { } } + /** + * Define the motion to apply on load + * @param motion Feature motion + */ + setMotion(motion: FeatureMotion) { + this.motion = motion; + } + /** * Start watching all stores already bound to that strategy at once. * @internal @@ -127,7 +138,7 @@ export class FeatureStoreLoadingStrategy extends EntityStoreStrategy { * @returns The motion selected */ private selectMotion(store: FeatureStore) { - if (this.options.motion !== undefined) { return this.options.motion; } + if (this.motion !== undefined) { return this.motion; } if (store.pristine === true) { // If features have just been loaded into the store, move/zoom on them diff --git a/packages/geo/src/lib/feature/shared/strategies/selection.ts b/packages/geo/src/lib/feature/shared/strategies/selection.ts index de6afcd63a..cc58533e2f 100644 --- a/packages/geo/src/lib/feature/shared/strategies/selection.ts +++ b/packages/geo/src/lib/feature/shared/strategies/selection.ts @@ -51,6 +51,8 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy { */ private stores$$: Subscription; + private motion: FeatureMotion; + /** * The map the layers belong to */ @@ -65,6 +67,7 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy { constructor(protected options: FeatureStoreSelectionStrategyOptions) { super(options); + this.setMotion(options.motion); this._overlayStore = this.createOverlayStore(); } @@ -94,6 +97,14 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy { } } + /** + * Define the motion to apply on select + * @param motion Feature motion + */ + setMotion(motion: FeatureMotion) { + this.motion = motion; + } + /** * Unselect all entities, from all stores */ @@ -274,7 +285,7 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy { * @param features Store features */ private onSelectFromStore(features: Feature[]) { - const motion = this.options ? this.options.motion : undefined; + const motion = this.motion const olOverlayFeatures = this.overlayStore.layer.ol.getSource().getFeatures(); const overlayFeaturesKeys = olOverlayFeatures.map((olFeature: OlFeature) => olFeature.getId()); const featuresKeys = features.map(this.overlayStore.getKey);