Skip to content

Commit

Permalink
fix(geo): store strategy in-map-extent revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alecarn committed Oct 26, 2023
1 parent 168ab6b commit 54027da
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions packages/geo/src/lib/feature/shared/strategies/in-map-extent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { EntityStoreStrategy } from '@igo2/common';

import * as olextent from 'ol/extent';

import { Subscription } from 'rxjs';
import { debounceTime, skipWhile } from 'rxjs/operators';

import { FeatureStoreInMapExtentStrategyOptions } from '../feature.interfaces';
import { MapExtent } from '../../../map';
import {
Feature,
FeatureStoreInMapExtentStrategyOptions
} from '../feature.interfaces';
import { FeatureStore } from '../store';

/**
Expand Down Expand Up @@ -84,20 +90,32 @@ export class FeatureStoreInMapExtentStrategy extends EntityStoreStrategy {
if (store?.layer?.map?.viewController) {
store.state.updateAll({ inMapExtent: false });
const mapExtent = store.layer.map.viewController.getExtent();
let entitiesInMapExtent = store.layer.ol
.getSource()
.getFeaturesInExtent(mapExtent)
.map((f) => store.get(f.getId()));
if (entitiesInMapExtent) {
store.state.updateMany(
entitiesInMapExtent,
{ inMapExtent: true },
false
);
}
const features = store.entities$.value;
const entitiesInMapExtent = this.getFeaturesInExtent(features, mapExtent);
store.state.updateMany(entitiesInMapExtent, { inMapExtent: true }, false);
}
}

private getFeaturesInExtent(
features: Feature<any>[],
extent: MapExtent
): Feature[] {
return features.reduce((acc, feature) => {
const geom = feature.ol?.getGeometry();
if (geom) {
const featureExtent = geom.getExtent();

if (olextent.intersects(featureExtent, extent)) {
acc.push(feature);
}
} else {
// By default, keep entity with no geometry
acc.push(feature);
}
return acc;
}, []);
}

/**
* Stop watching for a store's OL source changes
* @param store Feature store
Expand Down

0 comments on commit 54027da

Please sign in to comment.