File

components/control-panel/control-panel.component.ts

Description

Form fields for turning on and off different map layers.

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(service: AppService, destroyRef: DestroyRef)
Parameters :
Name Type Optional
service AppService No
destroyRef DestroyRef No

Methods

ngOnInit
ngOnInit()
Returns : void
Private onEartquakesToggle
onEartquakesToggle()
Returns : void
Private onFeaturePolygonToggle
onFeaturePolygonToggle(checked: boolean, featureType: FeatureType)
Parameters :
Name Type Optional
checked boolean No
featureType FeatureType No
Returns : void
Private onFeaturesToggle
onFeaturesToggle(checked: boolean, featureType: FeatureType)

Call features service when toggled.

Parameters :
Name Type Optional Description
checked boolean No

Whether toggle is checked

featureType FeatureType No

The feature type

Returns : void
Private onHazardTileYear
onHazardTileYear()
Returns : void
Private onHazardToggle
onHazardToggle()
Returns : void
Private onModelChange
onModelChange()
Returns : void
Private onNshmBoundaryToggle
onNshmBoundaryToggle()

Call map service when toggled.

Returns : void
Private onTestSitesToggle
onTestSitesToggle()

Call test sites service when toggled.

Returns : void

Properties

FeatureType
Default value : FeatureType

Earthquake feature type

formGroup
Default value : this.service.formGroup

Form field state

imts
Type : Set<Imt>
Default value : new Set()

Available IMTs for hazard map tiles

LatestEarthquakeTime
Default value : LatestEarthquakeTime
returnPeriods
Type : Set<ReturnPeriod>
Default value : new Set()

Available return periods for hazard map tiles

Public service
Type : AppService
years
Type : Set<number>
Default value : new Set()

Available years for hazard map tiles

import {Component, DestroyRef, OnInit} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {ReactiveFormsModule} from '@angular/forms';
import {MatOption} from '@angular/material/core';
import {MatFormField, MatLabel} from '@angular/material/form-field';
import {MatIconModule} from '@angular/material/icon';
import {MatSelect, MatSelectModule} from '@angular/material/select';
import {MatSlideToggle} from '@angular/material/slide-toggle';
import {MatSliderModule} from '@angular/material/slider';
import Layer from '@arcgis/core/layers/Layer';
import {NshmpHazardModelFormComponent} from '@ghsc/nshmp-lib-ng/hazard';
import {NshmpSectionComponent, ReturnPeriod} from '@ghsc/nshmp-lib-ng/nshmp';
import {FeatureType} from '@ghsc/nshmp-utils-ts/libs/nshmp-haz/www/features-service';
import {Imt} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/gmm';
import {nshmYear} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/nshm';

import {LatestEarthquakeTime} from '../../models/control-form.model';
import {AppService} from '../../services/app.service';

/**
 * Form fields for turning on and off different map layers.
 */
@Component({
  imports: [
    NshmpHazardModelFormComponent,
    MatLabel,
    MatSlideToggle,
    MatFormField,
    MatSelect,
    MatOption,
    ReactiveFormsModule,
    MatIconModule,
    MatSelectModule,
    MatSliderModule,
    NshmpSectionComponent,
  ],
  selector: 'app-control-panel',
  styleUrl: './control-panel.component.scss',
  templateUrl: './control-panel.component.html',
})
export class ControlPanelComponent implements OnInit {
  /** Earthquake feature type */
  FeatureType = FeatureType;
  LatestEarthquakeTime = LatestEarthquakeTime;

  /** Form field state */
  formGroup = this.service.formGroup;

  /** Available IMTs for hazard map tiles */
  imts: Set<Imt> = new Set();

  /** Available return periods for hazard map tiles */
  returnPeriods: Set<ReturnPeriod> = new Set();

  /** Available years for hazard map tiles */
  years: Set<number> = new Set();

  constructor(
    public service: AppService,
    private destroyRef: DestroyRef,
  ) {}

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

    controls.model.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.onModelChange());
    controls.hasNshmBoundaryLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.onNshmBoundaryToggle());
    controls.hazardTileImt.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.service.createHazardLayer());
    controls.hazardTileReturnPeriod.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.service.createHazardLayer());
    controls.hazardTileYear.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.onHazardTileYear());
    controls.hasHazardTiles.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.onHazardToggle());
    controls.overlayOpacity.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.service.createHazardLayer());
    controls.latestEarthquakeTime.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.service.callEarthquakesService());
    controls.hasTestSitesLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.onTestSitesToggle());
    controls.hasDecollementLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(checked => this.onFeaturesToggle(checked, FeatureType.DECOLLEMENT));
    controls.hasFaultSectionLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(checked => this.onFeaturesToggle(checked, FeatureType.FAULT));
    controls.hasInterfaceSectionsLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(checked => this.onFeaturesToggle(checked, FeatureType.INTERFACE));
    controls.hasZoneSourcesLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(checked => this.onFeaturesToggle(checked, FeatureType.ZONE));
    controls.hasEarthquakesLayer.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() => this.onEartquakesToggle());

    controls.hasTracesOnlyFaultSections.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() =>
        this.onFeaturePolygonToggle(
          this.formGroup.getRawValue().hasFaultSectionLayer,
          FeatureType.FAULT,
        ),
      );

    controls.hasTracesOnlyInterfaceSections.valueChanges
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(() =>
        this.onFeaturePolygonToggle(
          this.formGroup.getRawValue().hasInterfaceSectionsLayer,
          FeatureType.INTERFACE,
        ),
      );
  }

  private onEartquakesToggle(): void {
    const layer = this.service.layers().earthquakesLayer;
    this.service.callEarthquakesService(layer);
  }

  private onFeaturePolygonToggle(checked: boolean, featureType: FeatureType): void {
    this.service.callFeaturesService(featureType, undefined, checked);
  }

  /**
   * Call features service when toggled.
   *
   * @param checked Whether toggle is checked
   * @param featureType The feature type
   */
  private onFeaturesToggle(checked: boolean, featureType: FeatureType): void {
    switch (featureType) {
      case FeatureType.FAULT: {
        const control = this.formGroup.controls.hasTracesOnlyFaultSections;
        if (checked) {
          control.enable();
        } else {
          control.disable();
        }
        break;
      }
      case FeatureType.INTERFACE: {
        const control = this.formGroup.controls.hasTracesOnlyInterfaceSections;
        if (checked) {
          control.enable();
        } else {
          control.disable();
        }
        break;
      }
      default: {
        const layers = Object.values(this.service.layers()) as Layer[];
        const layer = layers.find(layer => layer?.id === featureType.toString());
        this.service.callFeaturesService(featureType, layer, checked);
      }
    }
  }

  private onHazardTileYear(): void {
    this.imts = new Set(
      this.service
        .filterTilesByYear(this.service.hazardTiles(), this.formGroup.getRawValue())
        .map(tile => tile.imt),
    );
    this.returnPeriods = new Set(
      this.service
        .filterTilesByImt(this.service.hazardTiles(), this.formGroup.getRawValue())
        .map(tile => tile.returnPeriod),
    );

    this.service.createHazardLayer();
  }

  private onHazardToggle(): void {
    const layer = this.service.layers().hazardLayer;
    this.service.createHazardLayer(layer);
  }

  private onModelChange(): void {
    this.years = new Set(
      this.service
        .filterTilesByRegion(this.service.hazardTiles(), this.formGroup.getRawValue())
        .map(tile => nshmYear(tile.nshm)),
    );
    this.service.resetState();
  }

  /**
   * Call map service when toggled.
   *
   * @param checked Wether toggle is checked
   */
  private onNshmBoundaryToggle(): void {
    const layers = this.service.layers();
    this.service.callService(layers.nshmBoundaryLayer);
  }

  /**
   * Call test sites service when toggled.
   * @param checked Whether toggle is checked
   */
  private onTestSitesToggle(): void {
    const layer = this.service.layers().testSitesLayer;
    this.service.callTestSitesService(layer);
  }
}
<form [formGroup]="formGroup" class="height-full overflow-auto">
  <nshmp-section label="Model Layers">
    <mat-form-field class="grid-col-12 padding-top-1">
      <mat-label>Map Style</mat-label>
      <mat-select class="map-style-select" [formControl]="formGroup.controls.mapStyle">
        <mat-option value="2d">2D</mat-option>
        <mat-option value="3d">3D</mat-option>
      </mat-select>
    </mat-form-field>

    <nshmp-hazard-model-form
      [modelControl]="formGroup.controls.model"
      [models]="service.availableModels()"
    />

    <!-- NSHM boundary layer toggle -->
    <div class="grid-col-12 nshm-boundary-toggle">
      <mat-slide-toggle [formControl]="formGroup.controls.hasNshmBoundaryLayer">
        NSHM Border
        <hr size="20" color="black" />
      </mat-slide-toggle>
    </div>

    <!-- Test sites layer toggle -->
    <div class="grid-col-12 layer-toggle test-sites">
      <mat-slide-toggle [formControl]="formGroup.controls.hasTestSitesLayer">
        Test Sites
        <mat-icon class="mat-icon-20">location_on</mat-icon>
      </mat-slide-toggle>
    </div>

    <!-- Decollement layer toggle -->
    <div class="grid-col-12 layer-toggle decollement-sections">
      <mat-slide-toggle [formControl]="formGroup.controls.hasDecollementLayer">
        Décollement Sections
        <hr size="20" color="purple" />
      </mat-slide-toggle>
    </div>

    <!-- Fault sections layer toggle -->
    <div class="grid-col-12 layer-toggle fault-sections">
      <mat-slide-toggle [formControl]="formGroup.controls.hasFaultSectionLayer">
        Fault Sections
        <hr size="20" color="red" />
      </mat-slide-toggle>
    </div>

    <div class="grid-col-12 polygon-toggle">
      <mat-slide-toggle [formControl]="formGroup.controls.hasTracesOnlyFaultSections">
        Traces only
      </mat-slide-toggle>
    </div>

    <!-- Interface sections layer toggle -->
    <div class="grid-col-12 layer-toggle interface-sections">
      <mat-slide-toggle [formControl]="formGroup.controls.hasInterfaceSectionsLayer">
        Interface Sections
        <hr size="20" color="green" />
      </mat-slide-toggle>
    </div>

    <div class="grid-col-12 polygon-toggle">
      <mat-slide-toggle [formControl]="formGroup.controls.hasTracesOnlyInterfaceSections">
        Traces only
      </mat-slide-toggle>
    </div>

    <!-- Zone sources layer toggle -->
    <div class="grid-col-12 layer-toggle zone-sources">
      <mat-slide-toggle [formControl]="formGroup.controls.hasZoneSourcesLayer">
        Zone Sources
        <hr size="20" color="blue" />
      </mat-slide-toggle>
    </div>

    <!-- Earthquakes layer toggle -->
    <div>
      <div class="grid-col-12 layer-toggle earthquakes">
        <mat-slide-toggle [formControl]="formGroup.controls.hasEarthquakesLayer">
          Latest Earthquakes
          <span class="earthquake-marker">
            <svg height="12" width="12">
              <circle
                r="5"
                cx="6"
                cy="6"
                fill="orange"
                stroke="black"
                stroke-width="1"
                opacity="0.7"
              />
            </svg>
          </span>
        </mat-slide-toggle>
      </div>

      <div class="margin-left-4">
        <!-- Latest earthquake time -->
        <div class="grid-col-12">
          <mat-form-field>
            <mat-label>Time Frame</mat-label>
            <mat-select [formControl]="formGroup.controls.latestEarthquakeTime">
              <mat-option [value]="LatestEarthquakeTime.DAY"> 1 Day </mat-option>
              <mat-option [value]="LatestEarthquakeTime.WEEK"> 7 Days </mat-option>
              <mat-option [value]="LatestEarthquakeTime.MONTH"> 30 Days </mat-option>
            </mat-select>
          </mat-form-field>
        </div>
      </div>
    </div>

    <!-- Hazard map layer toggle -->
    @if (service.formGroup.controls.hasHazardTiles.enabled) {
      <div>
        <div class="grid-col-12 layer-toggle hazard-layer">
          <mat-slide-toggle [formControl]="formGroup.controls.hasHazardTiles">
            Hazard Map
          </mat-slide-toggle>
        </div>

        <div class="margin-left-4">
          <!-- Hazard map year -->
          <div class="grid-col-12">
            <mat-form-field>
              <mat-label>Year</mat-label>
              <mat-select [formControl]="formGroup.controls.hazardTileYear">
                @for (year of years; track year) {
                  <mat-option [value]="year">
                    {{ year }}
                  </mat-option>
                }
              </mat-select>
            </mat-form-field>
          </div>

          <!-- Hazard map imt -->
          <div class="grid-col-12">
            <mat-form-field>
              <mat-label>IMT</mat-label>
              <mat-select [formControl]="formGroup.controls.hazardTileImt">
                @for (imt of imts; track imt) {
                  <mat-option [value]="imt">
                    {{ imt }}
                  </mat-option>
                }
              </mat-select>
            </mat-form-field>
          </div>

          <!-- Hazard map return period -->
          <div class="grid-col-12">
            <mat-form-field>
              <mat-label>Return Period</mat-label>
              <mat-select [formControl]="formGroup.controls.hazardTileReturnPeriod">
                @for (returnPeriod of returnPeriods; track returnPeriod) {
                  <mat-option [value]="returnPeriod">
                    {{ returnPeriod }}
                  </mat-option>
                }
              </mat-select>
            </mat-form-field>

            <div>
              <mat-label>Hazard Map Opacity</mat-label>
              <mat-slider discrete min="0" max="100">
                <input matSliderThumb [formControl]="formGroup.controls.overlayOpacity" />
              </mat-slider>
            </div>
          </div>
        </div>
      </div>
    }
  </nshmp-section>
</form>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""