Skip to content

Commit

Permalink
refactor: added filterByViewportBound() to DbxMapboxMapStore
Browse files Browse the repository at this point in the history
  • Loading branch information
dereekb committed May 28, 2023
1 parent 6f1cf5b commit bb30123
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/dbx-web/mapbox/src/lib/mapbox.rxjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { combineLatestWith, map, Observable, OperatorFunction, switchMap, shareR
import { MapboxZoomLevel } from './mapbox';
import { MapboxViewportBoundFunction } from './mapbox.util';

export type FilterMapboxBoundReadItemValueFunction<T> = (value: T) => MapboxViewportBoundFunctionItemValue;

export interface FilterMapboxBoundConfig<T> {
boundFunctionObs: ObservableOrValue<MapboxViewportBoundFunction>;
boundDecisionObs: ObservableOrValue<LatLngBoundCheckFunction>;
/**
* Reads the value from the input item.
*/
readValue: (value: T) => MapboxViewportBoundFunctionItemValue;
readValue: FilterMapboxBoundReadItemValueFunction<T>;
/**
* Minimum precision to retain. Defaults to LAT_LONG_10M_PRECISION
*/
Expand Down
13 changes: 12 additions & 1 deletion packages/dbx-web/mapbox/src/lib/mapbox.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { Inject, Injectable, OnDestroy } from '@angular/core';
import { isSameLatLngBound, isSameLatLngPoint, IsWithinLatLngBoundFunction, isWithinLatLngBoundFunction, LatLngBound, latLngBoundFunction, LatLngPointInput, LatLngPoint, latLngPointFunction, Maybe, OverlapsLatLngBoundFunction, overlapsLatLngBoundFunction, diffLatLngBoundPoints, latLngBoundCenterPoint, addLatLngPoints, isDefaultLatLngPoint, swMostLatLngPoint, neMostLatLngPoint, latLngBoundWrapsMap, Vector, vectorsAreEqual, filterUndefinedValues, latLngBoundFromInput } from '@dereekb/util';
import { ComponentStore } from '@ngrx/component-store';
import { MapService } from 'ngx-mapbox-gl';
import { defaultIfEmpty, distinctUntilChanged, filter, map, shareReplay, switchMap, tap, NEVER, Observable, of, Subscription, startWith, interval, first, combineLatest, EMPTY } from 'rxjs';
import { defaultIfEmpty, distinctUntilChanged, filter, map, shareReplay, switchMap, tap, NEVER, Observable, of, Subscription, startWith, interval, first, combineLatest, EMPTY, OperatorFunction } from 'rxjs';
import * as MapboxGl from 'mapbox-gl';
import { DbxMapboxClickEvent, KnownMapboxStyle, MapboxBearing, MapboxEaseTo, MapboxFitBounds, MapboxFitPositions, MapboxFlyTo, MapboxJumpTo, MapboxResetNorth, MapboxResetNorthPitch, MapboxRotateTo, MapboxSnapToNorth, MapboxStyleConfig, MapboxZoomLevel, MapboxZoomLevelRange } from './mapbox';
import { DbxMapboxService } from './mapbox.service';
import { DbxInjectionComponentConfig } from '@dereekb/dbx-core';
import { mapboxViewportBoundFunction, MapboxViewportBoundFunction } from './mapbox.util';
import { FilterMapboxBoundConfig, FilterMapboxBoundReadItemValueFunction, filterByMapboxViewportBound } from './mapbox.rxjs';

export type MapboxMapLifecycleState = 'init' | 'load' | 'render' | 'idle';
export type MapboxMapMoveState = 'init' | 'idle' | 'moving';
Expand Down Expand Up @@ -522,6 +523,16 @@ export class DbxMapboxMapStore extends ComponentStore<DbxMapboxStoreState> imple
);
}

filterByViewportBound<T>(input: FilterMapboxBoundReadItemValueFunction<T> | Omit<FilterMapboxBoundConfig<T>, 'boundFunctionObs' | 'boundDecisionObs'>): OperatorFunction<T[], T[]> {
const config = typeof input === 'function' ? { readValue: input } : input;

return filterByMapboxViewportBound({
...config,
boundFunctionObs: this.viewportBoundFunction$,
boundDecisionObs: this.overlapsBoundFunction$
});
}

readonly currentMapService$ = this.state$.pipe(
map((x) => x.mapService),
distinctUntilChanged(),
Expand Down

0 comments on commit bb30123

Please sign in to comment.