Skip to content

Commit

Permalink
feat(feature): improve the featuire store loading strategy motion beh…
Browse files Browse the repository at this point in the history
…avior
  • Loading branch information
cbourget committed Mar 4, 2019
1 parent abe36df commit a3e3e04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/geo/src/lib/feature/shared/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ export class FeatureStore<T extends Feature = Feature> extends EntityStore<T> {
this.addOlFeaturesToLayer(olFeaturesToAdd);
}

// Determine the move action to take
if (olFeaturesToAdd.length > 0) {
// If features are added, do a motion toward the newly added features
moveToFeatures(this.map, olFeaturesToAdd, motion);
} else if (olFeaturesToRemove.length > 0) {
// Do nothing
} else if (olFeatures.length > 0) {
// Else, do a motion toward all the features
moveToFeatures(this.map, olFeatures, motion);
}
}
Expand Down
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 @@ -106,7 +106,18 @@ export class FeatureStoreLoadingStrategy extends FeatureStoreStrategy {
if (features.length === 0) {
store.clearLayer();
} else {
store.setLayerFeatures(features, FeatureMotion.None);
let motion;
if (store.pristine === true) {
// If features have just been loaded into the store, move/zoom on them
motion = FeatureMotion.Default;
} else if (store.count > store.view.count) {
// If features have been filtered, move/zoom on the remaining ones
motion = FeatureMotion.Default;
} else {
// On insert, update or delete, do nothing
motion = FeatureMotion.None;
}
store.setLayerFeatures(features, motion);
}
}
}

0 comments on commit a3e3e04

Please sign in to comment.