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(service: AppService, destroyRef: DestroyRef)
Parameters :
Name Type Optional
service AppService No
destroyRef DestroyRef No

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 init
Default value : false
mapStyle
Default value : this.service.formGroup.controls.mapStyle
Public service
Type : AppService
Private view
Type : MapView | SceneView
import '@arcgis/map-components/dist/components/arcgis-legend';
import '@arcgis/map-components/dist/components/arcgis-placement';

import {NgTemplateOutlet} from '@angular/common';
import {
  Component,
  CUSTOM_ELEMENTS_SCHEMA,
  DestroyRef,
  effect,
  OnInit,
  ViewEncapsulation,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {MatButtonModule} from '@angular/material/button';
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 {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,
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  selector: 'app-map',
  styleUrl: './map.component.scss',
  templateUrl: './map.component.html',
})
export class MapComponent implements OnInit {
  mapStyle = this.service.formGroup.controls.mapStyle;

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

  constructor(
    public service: AppService,
    private destroyRef: DestroyRef,
  ) {
    effect(() => {
      const layer = this.service.layers().nshmBoundaryLayer;
      this.goTo(layer);
    });
  }

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

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

  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" (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">
        <img src="assets/map/legend.png" />
      </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 ""