@dereekb/dbx-web 9.6.1 → 9.6.2

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,12 +3,14 @@ import { Injectable, Optional, Inject, Directive, Host, Component, ElementRef, V
3
3
  import * as i2$1 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import { cleanup, filterMaybe, onTrueToFalse, SubscriptionObject } from '@dereekb/rxjs';
6
- import { latLngPointFunction, latLngBoundFunction, isSameLatLngPoint, isSameLatLngBound, isWithinLatLngBoundFunction, overlapsLatLngBoundFunction, diffLatLngBoundPoints, latLngBoundCenterPoint, addLatLngPoints, latLngPoint, DestroyFunctionObject } from '@dereekb/util';
6
+ import { latLngPointFunction, latLngBoundFunction, isSameLatLngPoint, isDefaultLatLngPoint, swMostLatLngPoint, neMostLatLngPoint, isSameLatLngBound, latLngBoundWrapsMap, isWithinLatLngBoundFunction, overlapsLatLngBoundFunction, diffLatLngBoundPoints, latLngBoundCenterPoint, addLatLngPoints, latLngPoint, DestroyFunctionObject, getValueFromGetter } from '@dereekb/util';
7
7
  import { ComponentStore } from '@ngrx/component-store';
8
- import { switchMap, NEVER, defaultIfEmpty, map, tap, distinctUntilChanged, shareReplay, of, combineLatest, filter, first, startWith, interval, Subject, BehaviorSubject, throttleTime, skip } from 'rxjs';
8
+ import { switchMap, NEVER, defaultIfEmpty, map, tap, distinctUntilChanged, shareReplay, of, combineLatest, filter, first, startWith, interval, Subject, BehaviorSubject, throttleTime } from 'rxjs';
9
9
  import * as MapboxGl from 'mapbox-gl';
10
10
  import * as i1 from 'ngx-mapbox-gl';
11
- import { dbxColorBackground, disableRightClickInCdkBackdrop } from '@dereekb/dbx-web';
11
+ import { NgxMapboxGLModule } from 'ngx-mapbox-gl';
12
+ import * as i3$1 from '@dereekb/dbx-web';
13
+ import { dbxColorBackground, disableRightClickInCdkBackdrop, DbxRouterAnchorModule } from '@dereekb/dbx-web';
12
14
  import * as i3 from '@angular/material/sidenav';
13
15
  import { MatDrawerContainer, MatSidenavModule } from '@angular/material/sidenav';
14
16
  import * as i4 from '@angular/material/button';
@@ -25,7 +27,7 @@ class DbxMapboxConfig {
25
27
  }
26
28
  const DEFAULT_MAPBOX_STYLE = 'mapbox://styles/mapbox/streets-v11';
27
29
  const DEFAULT_MAPBOX_CENTER = [30.2690138665, -97.7408297965];
28
- const DEFAULT_MAPBOX_ZOOM = 12;
30
+ const DEFAULT_MAPBOX_ZOOM = 8;
29
31
  const DEFAULT_MAPBOX_MAP_STORE_TIMER_REFRESH_PERIOD = 200;
30
32
  class DbxMapboxService {
31
33
  constructor(config) {
@@ -69,7 +71,7 @@ class DbxMapboxMapStore extends ComponentStore {
69
71
  });
70
72
  this.dbxMapboxService = dbxMapboxService;
71
73
  this.latLngPoint = latLngPointFunction();
72
- this.latLngBound = latLngBoundFunction();
74
+ this.latLngBound = latLngBoundFunction({ pointFunction: latLngPointFunction({ wrap: false, validate: false }) });
73
75
  // MARK: Effects
74
76
  this.setMapService = this.effect((input) => {
75
77
  return input.pipe(switchMap((service) => {
@@ -310,17 +312,41 @@ class DbxMapboxMapStore extends ComponentStore {
310
312
  this.isRotating$ = this.whenInitialized$.pipe(switchMap(() => this.rotateState$.pipe(map((x) => x === 'rotating'), distinctUntilChanged(), shareReplay())));
311
313
  this._movingTimer = this.movingTimer();
312
314
  this._renderingTimer = this.lifecycleRenderTimer();
313
- this.centerNow$ = this.whenInitialized$.pipe(switchMap(() => this.mapInstance$.pipe(switchMap((x) => this._movingTimer.pipe(map(() => this.latLngPoint(x.getCenter())))), shareReplay(1))));
315
+ this.centerNow$ = this.whenInitialized$.pipe(switchMap(() => this.mapInstance$.pipe(switchMap((x) => this._movingTimer.pipe(map(() => this.latLngPoint(x.getCenter())))), shareReplay(1))), shareReplay(1));
314
316
  this.center$ = this.whenInitialized$.pipe(switchMap(() => {
315
317
  return this.isMoving$.pipe(onTrueToFalse(), startWith(undefined), switchMap(() => this.centerNow$.pipe(first())), distinctUntilChanged(isSameLatLngPoint), shareReplay(1));
318
+ }), shareReplay(1));
319
+ 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));
320
+ this.reverseMargin$ = this.margin$.pipe(map((x) => {
321
+ if (x) {
322
+ return { leftMargin: -x.leftMargin, rightMargin: -x.rightMargin, fullWidth: x.fullWidth };
323
+ }
324
+ else {
325
+ return x;
326
+ }
316
327
  }));
328
+ this.centerGivenMargin$ = this.whenInitialized$.pipe(switchMap(() => {
329
+ return this.reverseMargin$.pipe(switchMap((x) => {
330
+ if (x) {
331
+ return this.center$.pipe(switchMap((_) => this.calculateNextCenterOffsetWithScreenMarginChange(x)));
332
+ }
333
+ else {
334
+ return this.isMoving$.pipe(filter((x) => !x), switchMap(() => this.center$));
335
+ }
336
+ }));
337
+ }), shareReplay(1));
317
338
  this.boundNow$ = this.whenInitialized$.pipe(switchMap(() => this.mapInstance$.pipe(switchMap((x) => this._renderingTimer.pipe(map(() => {
318
339
  const bound = x.getBounds();
319
- return this.latLngBound([bound.getSouthWest(), bound.getNorthEast()]);
340
+ const boundSw = bound.getSouthWest();
341
+ const boundNe = bound.getNorthEast();
342
+ const sw = isDefaultLatLngPoint(boundSw) ? swMostLatLngPoint() : boundSw;
343
+ const ne = isDefaultLatLngPoint(boundNe) ? neMostLatLngPoint() : boundNe;
344
+ return this.latLngBound(sw, ne);
320
345
  }))), shareReplay(1))));
321
346
  this.bound$ = this.whenInitialized$.pipe(switchMap(() => {
322
347
  return this.isRendering$.pipe(onTrueToFalse(), startWith(undefined), switchMap((x) => this.boundNow$.pipe(first())), distinctUntilChanged(isSameLatLngBound), shareReplay(1));
323
348
  }));
349
+ this.boundWrapsAroundWorld$ = this.bound$.pipe(map((x) => latLngBoundWrapsMap(x)), distinctUntilChanged(), shareReplay(1));
324
350
  this.isWithinBoundFunction$ = this.bound$.pipe(map((x) => isWithinLatLngBoundFunction(x)), shareReplay(1));
325
351
  this.overlapsBoundFunction$ = this.bound$.pipe(map((x) => overlapsLatLngBoundFunction(x)), shareReplay(1));
326
352
  this.zoomNow$ = this.whenInitialized$.pipe(switchMap(() => this.mapInstance$.pipe(switchMap((x) => this._renderingTimer.pipe(map(() => x.getZoom()))), shareReplay(1))));
@@ -341,6 +367,7 @@ class DbxMapboxMapStore extends ComponentStore {
341
367
  this.doubleClickEvent$ = this.state$.pipe(map((x) => x.doubleClickEvent), distinctUntilChanged(), shareReplay(1));
342
368
  this.rightClickEvent$ = this.state$.pipe(map((x) => x.rightClickEvent), distinctUntilChanged(), shareReplay(1));
343
369
  // MARK: State Changes
370
+ this.setMargin = this.updater((state, margin) => ({ ...state, margin: margin && (margin.rightMargin !== 0 || margin.leftMargin !== 0) ? margin : undefined }));
344
371
  this._setMapService = this.updater((state, mapService) => ({ mapService, moveState: 'init', lifecycleState: 'init', zoomState: 'init', rotateState: 'init', retainContent: state.retainContent, content: state.retainContent ? state.content : undefined }));
345
372
  this._setLifecycleState = this.updater((state, lifecycleState) => ({ ...state, lifecycleState }));
346
373
  this._setMoveState = this.updater((state, moveState) => ({ ...state, moveState }));
@@ -391,23 +418,22 @@ class DbxMapboxMapStore extends ComponentStore {
391
418
  }))));
392
419
  }
393
420
  calculateNextCenterOffsetWithScreenMarginChange(sizing) {
394
- return this.atNextIdle().pipe(switchMap(() => this.bound$.pipe((first(),
395
- map((bounds) => {
396
- const diff = diffLatLngBoundPoints(bounds);
397
- const center = latLngBoundCenterPoint(bounds);
398
- const offsetWidth = sizing.leftMargin + sizing.rightMargin; // 300 + 0
399
- const newWidth = sizing.fullWidth - offsetWidth; // 1000 - 300 - 0
400
- const newWidthRatio = newWidth / sizing.fullWidth; // 700 / 1000
401
- const newCenterLongitudeWidth = diff.lng * newWidthRatio; // 70% offset
402
- const effectiveOffset = {
403
- lat: 0,
404
- lng: newCenterLongitudeWidth / 2
405
- };
406
- const newCenter = addLatLngPoints(bounds.sw, effectiveOffset);
407
- newCenter.lat = center.lat; // retain center position
408
- // console.log({ sizing, bounds, effectiveOffset, newWidth, offsetWidth, diff, center, newCenter });
409
- return newCenter;
410
- })))));
421
+ return this.atNextIdle().pipe(switchMap(() => this.bound$.pipe(first(), map((bounds) => {
422
+ const diff = diffLatLngBoundPoints(bounds);
423
+ const center = latLngBoundCenterPoint(bounds);
424
+ const offsetWidth = sizing.leftMargin + sizing.rightMargin; // 300 + 0
425
+ const newWidth = sizing.fullWidth - offsetWidth; // 1000 - 300 - 0
426
+ const newWidthRatio = newWidth / sizing.fullWidth; // 700 / 1000
427
+ const newCenterLongitudeWidth = diff.lng * newWidthRatio; // 70% offset
428
+ const effectiveOffset = {
429
+ lat: 0,
430
+ lng: newCenterLongitudeWidth / 2
431
+ };
432
+ const newCenter = addLatLngPoints(bounds.sw, effectiveOffset);
433
+ newCenter.lat = center.lat; // retain center position
434
+ // console.log({ sizing, bounds, effectiveOffset, newWidth, offsetWidth, diff, center, newCenter });
435
+ return newCenter;
436
+ }))));
411
437
  }
412
438
  }
413
439
  DbxMapboxMapStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxMapboxMapStore, deps: [{ token: DbxMapboxService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -522,7 +548,8 @@ class DbxMapboxLayoutComponent extends SubscriptionObject {
522
548
  }
523
549
  });
524
550
  });
525
- this._toggleSub.subscription = combineLatest([this.opened$.pipe(distinctUntilChanged(), skip(1)), this._updateMargins]).subscribe(([opened]) => {
551
+ let init = false;
552
+ this._toggleSub.subscription = combineLatest([this.opened$.pipe(distinctUntilChanged()), this._updateMargins]).subscribe(([opened]) => {
526
553
  let { right } = this.container._contentMargins;
527
554
  this.container.updateContentMargins();
528
555
  setTimeout(() => {
@@ -533,14 +560,19 @@ class DbxMapboxLayoutComponent extends SubscriptionObject {
533
560
  right = (right || 0) * flip;
534
561
  const element = this.content.nativeElement;
535
562
  const width = element.clientWidth;
536
- const easeTo = this.dbxMapboxMapStore
537
- .calculateNextCenterOffsetWithScreenMarginChange({
563
+ const margin = {
538
564
  leftMargin: 0,
539
565
  rightMargin: right,
540
566
  fullWidth: width
541
- })
542
- .pipe(first(), map((center) => ({ to: { center, duration: 3200, essential: false } })));
543
- this.dbxMapboxMapStore.easeTo(easeTo);
567
+ };
568
+ const easeTo = this.dbxMapboxMapStore.calculateNextCenterOffsetWithScreenMarginChange(margin).pipe(first(), map((center) => ({ to: { center, duration: 3200, essential: false } })));
569
+ this.dbxMapboxMapStore.setMargin(opened ? margin : undefined);
570
+ if (!init) {
571
+ this.dbxMapboxMapStore.easeTo(easeTo);
572
+ }
573
+ else {
574
+ init = true;
575
+ }
544
576
  });
545
577
  });
546
578
  }
@@ -738,12 +770,103 @@ function provideMapboxStoreIfParentIsUnavailable() {
738
770
  };
739
771
  }
740
772
 
773
+ class DbxMapboxMarkerComponent {
774
+ constructor() { }
775
+ get marker() {
776
+ return this._marker;
777
+ }
778
+ set marker(marker) {
779
+ this._marker = marker;
780
+ }
781
+ get latLng() {
782
+ return this._marker?.latLng;
783
+ }
784
+ get anchor() {
785
+ return this._marker?.anchor;
786
+ }
787
+ get label() {
788
+ return this._marker?.label;
789
+ }
790
+ get icon() {
791
+ return this._marker?.icon;
792
+ }
793
+ get style() {
794
+ let width = 0;
795
+ let height = 0;
796
+ const size = this._marker?.size || 'medium';
797
+ if (typeof size === 'number') {
798
+ width = size;
799
+ }
800
+ else {
801
+ switch (size) {
802
+ case 'small':
803
+ width = 18;
804
+ break;
805
+ case 'medium':
806
+ width = 24;
807
+ break;
808
+ case 'large':
809
+ width = 32;
810
+ break;
811
+ case 'tall':
812
+ width = 24;
813
+ height = 32;
814
+ break;
815
+ }
816
+ }
817
+ if (!height) {
818
+ height = width;
819
+ }
820
+ const imageInput = this._marker?.image;
821
+ const image = imageInput ? (typeof imageInput === 'string' ? imageInput : getValueFromGetter(imageInput, width)) : undefined;
822
+ let style = {
823
+ ...this._marker?.style,
824
+ width: width + 'px',
825
+ height: height + 'px',
826
+ 'font-size': width + 'px',
827
+ 'background-image': image
828
+ };
829
+ return style;
830
+ }
831
+ }
832
+ DbxMapboxMarkerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxMapboxMarkerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
833
+ DbxMapboxMarkerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.2", type: DbxMapboxMarkerComponent, selector: "dbx-mapbox-marker", inputs: { marker: "marker" }, ngImport: i0, template: `
834
+ <mgl-marker *ngIf="marker" [lngLat]="latLng">
835
+ <dbx-anchor [anchor]="anchor">
836
+ <div class="dbx-mapbox-marker">
837
+ <div class="dbx-mapbox-marker-content" [ngStyle]="style">
838
+ <mat-icon *ngIf="icon">{{ icon }}</mat-icon>
839
+ </div>
840
+ <div class="dbx-mapbox-marker-label" *ngIf="label">{{ label }}</div>
841
+ </div>
842
+ </dbx-anchor>
843
+ </mgl-marker>
844
+ `, isInline: true, styles: [".dbx-mapbox-marker{display:flex;align-items:center;flex-direction:column;font-weight:700}.dbx-mapbox-marker .dbx-mapbox-marker-content{display:flex;align-items:center;justify-content:center}.dbx-mapbox-marker .dbx-mapbox-marker-content mat-icon{width:100%;height:100%;font-size:inherit}\n"], dependencies: [{ kind: "directive", type: i2$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2$1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i3$1.DbxAnchorComponent, selector: "dbx-anchor, [dbx-anchor]", inputs: ["block"] }, { kind: "component", type: i1.MarkerComponent, selector: "mgl-marker", inputs: ["offset", "anchor", "clickTolerance", "feature", "lngLat", "draggable", "popupShown", "className", "pitchAlignment", "rotationAlignment"], outputs: ["markerDragStart", "markerDragEnd", "markerDrag", "dragStart", "dragEnd", "drag"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
845
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxMapboxMarkerComponent, decorators: [{
846
+ type: Component,
847
+ args: [{ selector: 'dbx-mapbox-marker', template: `
848
+ <mgl-marker *ngIf="marker" [lngLat]="latLng">
849
+ <dbx-anchor [anchor]="anchor">
850
+ <div class="dbx-mapbox-marker">
851
+ <div class="dbx-mapbox-marker-content" [ngStyle]="style">
852
+ <mat-icon *ngIf="icon">{{ icon }}</mat-icon>
853
+ </div>
854
+ <div class="dbx-mapbox-marker-label" *ngIf="label">{{ label }}</div>
855
+ </div>
856
+ </dbx-anchor>
857
+ </mgl-marker>
858
+ `, changeDetection: ChangeDetectionStrategy.OnPush, styles: [".dbx-mapbox-marker{display:flex;align-items:center;flex-direction:column;font-weight:700}.dbx-mapbox-marker .dbx-mapbox-marker-content{display:flex;align-items:center;justify-content:center}.dbx-mapbox-marker .dbx-mapbox-marker-content mat-icon{width:100%;height:100%;font-size:inherit}\n"] }]
859
+ }], ctorParameters: function () { return []; }, propDecorators: { marker: [{
860
+ type: Input
861
+ }] } });
862
+
741
863
  const declarations = [
742
864
  //
743
865
  DbxMapboxMapDirective,
744
866
  DbxMapboxLayoutComponent,
745
867
  DbxMapboxLayoutDrawerComponent,
746
868
  DbxMapboxMenuComponent,
869
+ DbxMapboxMarkerComponent,
747
870
  DbxMapboxMapStoreInjectionBlockDirective
748
871
  ];
749
872
  class DbxMapboxModule {
@@ -766,6 +889,7 @@ DbxMapboxModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version
766
889
  DbxMapboxLayoutComponent,
767
890
  DbxMapboxLayoutDrawerComponent,
768
891
  DbxMapboxMenuComponent,
892
+ DbxMapboxMarkerComponent,
769
893
  DbxMapboxMapStoreInjectionBlockDirective], imports: [
770
894
  //
771
895
  CommonModule,
@@ -773,12 +897,15 @@ DbxMapboxModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version
773
897
  DbxInjectionComponentModule,
774
898
  MatButtonModule,
775
899
  MatIconModule,
776
- AngularResizeEventModule], exports: [
900
+ AngularResizeEventModule,
901
+ DbxRouterAnchorModule,
902
+ NgxMapboxGLModule], exports: [
777
903
  //
778
904
  DbxMapboxMapDirective,
779
905
  DbxMapboxLayoutComponent,
780
906
  DbxMapboxLayoutDrawerComponent,
781
907
  DbxMapboxMenuComponent,
908
+ DbxMapboxMarkerComponent,
782
909
  DbxMapboxMapStoreInjectionBlockDirective] });
783
910
  DbxMapboxModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxMapboxModule, imports: [
784
911
  //
@@ -787,7 +914,9 @@ DbxMapboxModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version
787
914
  DbxInjectionComponentModule,
788
915
  MatButtonModule,
789
916
  MatIconModule,
790
- AngularResizeEventModule] });
917
+ AngularResizeEventModule,
918
+ DbxRouterAnchorModule,
919
+ NgxMapboxGLModule] });
791
920
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxMapboxModule, decorators: [{
792
921
  type: NgModule,
793
922
  args: [{
@@ -798,7 +927,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImpor
798
927
  DbxInjectionComponentModule,
799
928
  MatButtonModule,
800
929
  MatIconModule,
801
- AngularResizeEventModule
930
+ AngularResizeEventModule,
931
+ DbxRouterAnchorModule,
932
+ NgxMapboxGLModule
802
933
  ],
803
934
  declarations,
804
935
  exports: declarations
@@ -826,5 +957,5 @@ function mapboxZoomLevel(input) {
826
957
  * Generated bundle index. Do not edit.
827
958
  */
828
959
 
829
- export { DEFAULT_MAPBOX_CENTER, DEFAULT_MAPBOX_MAP_STORE_TIMER_REFRESH_PERIOD, DEFAULT_MAPBOX_STYLE, DEFAULT_MAPBOX_ZOOM, DbxMapboxConfig, DbxMapboxLayoutComponent, DbxMapboxLayoutDrawerComponent, DbxMapboxMapDirective, DbxMapboxMapStore, DbxMapboxMapStoreInjectionBlockDirective, DbxMapboxMapStoreProviderBlock, DbxMapboxMenuComponent, DbxMapboxModule, DbxMapboxService, KNOWN_MAPBOX_STYLES, MAPBOX_MAX_ZOOM_LEVEL, MAPBOX_MIN_ZOOM_LEVEL, mapboxZoomLevel, provideMapboxStoreIfParentIsUnavailable };
960
+ export { DEFAULT_MAPBOX_CENTER, DEFAULT_MAPBOX_MAP_STORE_TIMER_REFRESH_PERIOD, DEFAULT_MAPBOX_STYLE, DEFAULT_MAPBOX_ZOOM, DbxMapboxConfig, DbxMapboxLayoutComponent, DbxMapboxLayoutDrawerComponent, DbxMapboxMapDirective, DbxMapboxMapStore, DbxMapboxMapStoreInjectionBlockDirective, DbxMapboxMapStoreProviderBlock, DbxMapboxMarkerComponent, DbxMapboxMenuComponent, DbxMapboxModule, DbxMapboxService, KNOWN_MAPBOX_STYLES, MAPBOX_MAX_ZOOM_LEVEL, MAPBOX_MIN_ZOOM_LEVEL, mapboxZoomLevel, provideMapboxStoreIfParentIsUnavailable };
830
961
  //# sourceMappingURL=dereekb-dbx-web-mapbox.mjs.map