@dereekb/dbx-web 9.24.41 → 9.24.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,8 @@ import { Injectable, Host, Optional, Inject, Component, ChangeDetectionStrategy,
3
3
  import * as i2 from '@dereekb/dbx-core';
4
4
  import { safeMarkForCheck, safeDetectChanges, AbstractSubscriptionDirective, DbxInjectionComponentModule } from '@dereekb/dbx-core';
5
5
  import { asObservable, cleanup, filterMaybe, onTrueToFalse, SubscriptionObject, distinctUntilMapHasDifferentKeys } from '@dereekb/rxjs';
6
- import { distinctUntilChanged, switchMap, map, combineLatestWith, shareReplay, NEVER, defaultIfEmpty, tap, EMPTY, of, combineLatest, filter, first, startWith, interval, Subject, merge, throttleTime, BehaviorSubject } from 'rxjs';
7
- import { LAT_LONG_10M_PRECISION, latLngPointFunction, roundNumberToStepFunction, latLngBoundFunction, latLngBoundFromInput, filterUndefinedValues, isSameLatLngPoint, isSameVector, isDefaultLatLngPoint, swMostLatLngPoint, neMostLatLngPoint, isSameLatLngBound, diffLatLngBoundPoints, latLngBoundWrapsMap, isWithinLatLngBoundFunction, overlapsLatLngBoundFunction, latLngBoundCenterPoint, addLatLngPoints, vectorMinimumSizeResizeFunction, latLngPoint, DestroyFunctionObject, getValueFromGetter } from '@dereekb/util';
6
+ import { distinctUntilChanged, switchMap, map, combineLatestWith, shareReplay, NEVER, defaultIfEmpty, tap, EMPTY, of, combineLatest, filter, first, startWith, throttleTime, interval, Subject, merge, BehaviorSubject } from 'rxjs';
7
+ import { LAT_LONG_10M_PRECISION, latLngPointFunction, roundNumberToStepFunction, latLngBoundFunction, latLngBoundFromInput, filterUndefinedValues, isSameLatLngPoint, isSameVector, isSameLatLngBound, isDefaultLatLngPoint, swMostLatLngPoint, neMostLatLngPoint, diffLatLngBoundPoints, latLngBoundWrapsMap, isWithinLatLngBoundFunction, overlapsLatLngBoundFunction, latLngBoundCenterPoint, addLatLngPoints, vectorMinimumSizeResizeFunction, latLngPoint, DestroyFunctionObject, getValueFromGetter } from '@dereekb/util';
8
8
  import { ComponentStore } from '@ngrx/component-store';
9
9
  import * as MapboxGl from 'mapbox-gl';
10
10
  import { bounds } from '@mapbox/geo-viewport';
@@ -168,7 +168,11 @@ class DbxMapboxMapStore extends ComponentStore {
168
168
  zoomState: 'init',
169
169
  rotateState: 'init',
170
170
  retainContent: true,
171
- useVirtualBound: true
171
+ useVirtualBound: true,
172
+ boundRefreshSettings: {
173
+ throttle: 300,
174
+ refreshType: 'always'
175
+ }
172
176
  });
173
177
  this.dbxMapboxService = dbxMapboxService;
174
178
  this.safeLatLngPoint = latLngPointFunction({ wrap: true });
@@ -424,6 +428,7 @@ class DbxMapboxMapStore extends ComponentStore {
424
428
  }
425
429
  }), distinctUntilChanged(), shareReplay(1));
426
430
  this.mapInstance$ = this.currentMapInstance$.pipe(filterMaybe());
431
+ this.boundRefreshSettings$ = this.state$.pipe(map((x) => x.boundRefreshSettings), shareReplay(1));
427
432
  this.moveState$ = this.state$.pipe(map((x) => x.moveState), distinctUntilChanged(), shareReplay(1));
428
433
  this.lifecycleState$ = this.state$.pipe(map((x) => x.lifecycleState), distinctUntilChanged(), shareReplay(1));
429
434
  this.zoomState$ = this.state$.pipe(map((x) => x.zoomState), distinctUntilChanged(), shareReplay(1));
@@ -474,11 +479,24 @@ class DbxMapboxMapStore extends ComponentStore {
474
479
  }
475
480
  }), shareReplay(1));
476
481
  this.virtualBound$ = this.viewportBoundFunction$.pipe(switchMap((fn) => {
477
- return combineLatest([this.center$, this.zoom$]).pipe(map(([center, zoom]) => fn({
478
- center,
479
- zoom
480
- })));
481
- }), shareReplay(1));
482
+ return this.boundRefreshSettings$.pipe(switchMap((settings) => {
483
+ const { throttle: throttleMs, refreshType } = settings;
484
+ let obs;
485
+ switch (refreshType) {
486
+ case 'always':
487
+ obs = combineLatest([this.centerNow$, this.zoomNow$]);
488
+ break;
489
+ case 'when_not_rendering':
490
+ case 'only_after_render_finishes':
491
+ obs = this.bound$.pipe(switchMap(() => combineLatest([this.centerNow$, this.zoomNow$]))); // refresh whenever the bound refreshes
492
+ break;
493
+ }
494
+ return obs.pipe(throttleTime(throttleMs, undefined, { leading: true, trailing: true }), map(([center, zoom]) => fn({
495
+ center,
496
+ zoom
497
+ })));
498
+ }));
499
+ }), distinctUntilChanged(isSameLatLngBound), shareReplay(1));
482
500
  this.margin$ = this.state$.pipe(map((x) => x.margin), distinctUntilChanged((a, b) => a != null && b != null && a.fullWidth === b.fullWidth && a.leftMargin === b.leftMargin && a.rightMargin === b.rightMargin), shareReplay(1));
483
501
  this.reverseMargin$ = this.margin$.pipe(map((x) => {
484
502
  if (x) {
@@ -505,17 +523,32 @@ class DbxMapboxMapStore extends ComponentStore {
505
523
  const sw = isDefaultLatLngPoint(boundSw) ? swMostLatLngPoint() : { lat: boundSw.lat, lng: boundSw.lng };
506
524
  const ne = isDefaultLatLngPoint(boundNe) ? neMostLatLngPoint() : { lat: boundNe.lat, lng: boundNe.lng };
507
525
  return this.latLngBound(sw, ne);
508
- }))), shareReplay(1))));
526
+ }))))), distinctUntilChanged(isSameLatLngBound), shareReplay(1));
509
527
  this.rawBound$ = this.whenInitialized$.pipe(switchMap(() => {
510
- return this.isRendering$.pipe(onTrueToFalse(), startWith(undefined), switchMap((x) => this.rawBoundNow$.pipe(first())), distinctUntilChanged(isSameLatLngBound), shareReplay(1));
511
- }));
528
+ return this.boundRefreshSettings$.pipe(switchMap((settings) => {
529
+ const { throttle: throttleMs, refreshType } = settings;
530
+ let obs;
531
+ switch (refreshType) {
532
+ case 'always':
533
+ obs = this.rawBoundNow$;
534
+ break;
535
+ case 'when_not_rendering':
536
+ obs = this.isRendering$.pipe(switchMap((x) => (x ? EMPTY : this.rawBoundNow$)));
537
+ break;
538
+ case 'only_after_render_finishes':
539
+ obs = this.isRendering$.pipe(onTrueToFalse(), switchMap((x) => this.rawBoundNow$.pipe(first())));
540
+ break;
541
+ }
542
+ return obs.pipe(throttleTime(throttleMs, undefined, { leading: true, trailing: true }));
543
+ }));
544
+ }), distinctUntilChanged(isSameLatLngBound), shareReplay(1));
512
545
  this.useVirtualBound$ = this.state$.pipe(map((x) => x.useVirtualBound), distinctUntilChanged(), shareReplay(1));
513
546
  this.bound$ = this.useVirtualBound$.pipe(switchMap((useVirtualBound) => {
514
547
  if (useVirtualBound) {
515
548
  return this.virtualBound$;
516
549
  }
517
550
  else {
518
- return this.bound$;
551
+ return this.rawBound$;
519
552
  }
520
553
  }), shareReplay(1));
521
554
  this.boundSizing$ = this.bound$.pipe(map((x) => diffLatLngBoundPoints(x)), shareReplay(1));
@@ -543,7 +576,8 @@ class DbxMapboxMapStore extends ComponentStore {
543
576
  this.setMargin = this.updater((state, margin) => (Object.assign(Object.assign({}, state), { margin: margin && (margin.rightMargin !== 0 || margin.leftMargin !== 0) ? margin : undefined })));
544
577
  this.setMinimumVirtualViewportSize = this.updater((state, minimumVirtualViewportSize) => (Object.assign(Object.assign({}, state), { minimumVirtualViewportSize })));
545
578
  this.setUseVirtualBound = this.updater((state, useVirtualBound) => (Object.assign(Object.assign({}, state), { useVirtualBound })));
546
- this._setMapService = this.updater((state, mapService) => ({ mapService, moveState: 'init', lifecycleState: 'init', zoomState: 'init', rotateState: 'init', retainContent: state.retainContent, content: state.retainContent ? state.content : undefined, useVirtualBound: state.useVirtualBound }));
579
+ this.setBoundRefreshSettings = this.updater((state, boundRefreshSettings) => (Object.assign(Object.assign({}, state), { boundRefreshSettings: Object.assign(Object.assign({}, state.boundRefreshSettings), boundRefreshSettings) })));
580
+ this._setMapService = this.updater((state, mapService) => ({ mapService, moveState: 'init', lifecycleState: 'init', zoomState: 'init', rotateState: 'init', retainContent: state.retainContent, content: state.retainContent ? state.content : undefined, useVirtualBound: state.useVirtualBound, boundRefreshSettings: state.boundRefreshSettings }));
547
581
  this._setLifecycleState = this.updater((state, lifecycleState) => (Object.assign(Object.assign({}, state), { lifecycleState })));
548
582
  this._setMoveState = this.updater((state, moveState) => (Object.assign(Object.assign({}, state), { moveState })));
549
583
  this._setZoomState = this.updater((state, zoomState) => (Object.assign(Object.assign({}, state), { zoomState })));