Skip to content

Commit

Permalink
feat(strategy): add a method to set a strategy's feature motion
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget authored and mbarbeau committed Aug 7, 2020
1 parent 395d3ad commit bb6be2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/geo/src/lib/feature/shared/strategies/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export class FeatureStoreLoadingStrategy extends EntityStoreStrategy {
*/
private stores$$ = new Map<FeatureStore, Subscription>();

private motion: FeatureMotion;

constructor(protected options: FeatureStoreLoadingStrategyOptions) {
super(options);
this.setMotion(options.motion);
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion packages/geo/src/lib/feature/shared/strategies/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy {
*/
private stores$$: Subscription;

private motion: FeatureMotion;

/**
* The map the layers belong to
*/
Expand All @@ -65,6 +67,7 @@ export class FeatureStoreSelectionStrategy extends EntityStoreStrategy {

constructor(protected options: FeatureStoreSelectionStrategyOptions) {
super(options);
this.setMotion(options.motion);
this._overlayStore = this.createOverlayStore();
}

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bb6be2d

Please sign in to comment.