File

components/map/map.component.ts

Description

ArcGIS map with layers showing NSHM boundary, fault sections, and test sites.

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor()

Methods

Private goTo
goTo(layer: GeoJSONLayer)
Parameters :
Name Type Optional
layer GeoJSONLayer No
Returns : void
ngOnInit
ngOnInit()
Returns : void
viewReady
viewReady(view: ___esri.MapView | ___esri.SceneView)
Parameters :
Name Type Optional
view ___esri.MapView | ___esri.SceneView No
Returns : void

Properties

Private destroyRef
Default value : inject(DestroyRef)
Private init
Default value : false
mapOptions
Default value : signal<ArcgisMapOptions>({})
mapStyle
Default value : this.service.formGroup.controls.mapStyle
service
Default value : inject(AppService)
Private view
Type : MapView | SceneView
import '@arcgis/map-components/dist/components/arcgis-placement';

import {NgTemplateOutlet} from '@angular/common';
import {
  Component,
  CUSTOM_ELEMENTS_SCHEMA,
  DestroyRef,
  effect,
  inject,
  OnInit,
  signal,
  ViewEncapsulation,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {MatButtonModule} from '@angular/material/button';
import {MatIcon} from '@angular/material/icon';
import {MatMenuModule} from '@angular/material/menu';
import GeoJSONLayer from '@arcgis/core/layers/GeoJSONLayer';
import MapView from '@arcgis/core/views/MapView';
import SceneView from '@arcgis/core/views/SceneView';
import {
  ArcgisMapOptions,
  NshmpMapArcgis3dComponent,
  NshmpMapArcgisComponent,
} from '@ghsc/nshmp-lib-ng/map';
import {from} from 'rxjs';

import {AppService} from '../../services/app.service';
import {LegendComponent} from '../legend/legend.component';

/**
 * ArcGIS map with layers showing NSHM boundary, fault sections, and test sites.
 */
@Component({
  encapsulation: ViewEncapsulation.None,
  imports: [
    LegendComponent,
    NshmpMapArcgisComponent,
    NshmpMapArcgis3dComponent,
    MatButtonModule,
    MatMenuModule,
    NgTemplateOutlet,
    MatIcon,
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  selector: 'app-map',
  styleUrl: './map.component.scss',
  templateUrl: './map.component.html',
})
export class MapComponent implements OnInit {
  service = inject(AppService);
  private destroyRef = inject(DestroyRef);

  mapStyle = this.service.formGroup.controls.mapStyle;

  mapOptions = signal<ArcgisMapOptions>({});

  private view: MapView | SceneView;
  private init = false;

  constructor() {
    effect(() => {
      const layer = this.service.layers().nshmBoundaryLayer;
      this.goTo(layer);
    });
  }

  ngOnInit(): void {
    const {mapStyle, model} = this.service.formGroup.controls;

    mapStyle.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(mapStyle => this.service.onMapStyleChange(mapStyle));

    model.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(model => {
      if (model !== null || model !== undefined) {
        const title = this.service.sourceFeaturesUsage().response.model.name;

        this.mapOptions.set({
          print: {
            dpi: 200,
            title,
          },
        });
      }
    });
  }

  viewReady(view: __esri.MapView | __esri.SceneView): void {
    this.view = view;

    if (this.init) {
      this.service.onMapViewChange();
      const layer = this.service.layers().nshmBoundaryLayer;
      this.goTo(layer);
    }

    this.init = true;
  }

  private goTo(layer: GeoJSONLayer): void {
    if (this.view && layer) {
      from(layer.when())
        .pipe(takeUntilDestroyed(this.destroyRef))
        .subscribe(() => {
          from(this.view.goTo(layer.fullExtent))
            .pipe(takeUntilDestroyed(this.destroyRef))
            .subscribe();
        });
    }
  }
}
@if (mapStyle.getRawValue() === '2d') {
  <nshmp-map-arcgis
    [map]="service.map2d"
    [mapOptions]="mapOptions()"
    (viewReady)="viewReady($event.view)"
  >
    <ng-container *ngTemplateOutlet="legend" />
  </nshmp-map-arcgis>
} @else {
  <nshmp-map-arcgis-3d [map]="service.map3d" (viewReady)="viewReady($event.view)">
    <ng-container *ngTemplateOutlet="legend" />
  </nshmp-map-arcgis-3d>
}

<ng-template #legend>
  <arcgis-placement position="top-right">
    <div class="legend">
      <button mat-fab [matMenuTriggerFor]="menu" #menuTrigger="matMenuTrigger">
        <mat-icon>vpn_key</mat-icon>
      </button>

      <mat-menu
        #menu="matMenu"
        xPosition="before"
        [hasBackdrop]="false"
        panelClass="panel-class"
        overlayPanelClass="overlay-panel-class"
        backdropClass="backdrop-class"
      >
        <div (click)="$event.stopPropagation()" class="model-maps-legend">
          <div class="padding-2">
            <button mat-raised-button (click)="menuTrigger.closeMenu()" class="grid-col-12">
              Close
            </button>
          </div>

          <app-legend />
        </div>
      </mat-menu>
    </div>
  </arcgis-placement>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""