File

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

Description

Control panel with form fields to call hazard service.

Metadata

Index

Properties
Methods

Methods

onReturnPeriodChange
onReturnPeriodChange()
Returns : void
onSubmit
onSubmit()

On form submit.

Returns : void
setLocation
setLocation(location: Location)
Parameters :
Name Type Optional
location Location No
Returns : void

Properties

formGroup
Default value : this.service.formGroup

Form field state

Private nshmpService
Default value : inject(NshmpService)
selectSiteData
Type : Signal<SelectSiteDialogData>
Default value : computed(() => { const usage = this.service.usage(); const nshmService = this.service.nshmService(); if (usage === null || nshmService === undefined) { return; } const services = environment.webServices.nshmpHazWs.services.curveServices; return { faultSectionsUrl: `${nshmService.url}${services.features}/FAULT?polygons=false&raw=true`, mapUrl: `${nshmService.url}${services.map}?raw=true`, sitesUrl: `${nshmService.url}${services.sites}?raw=true`, }; })

Data for select site component

service
Default value : inject(AppService)
siteClasses
Default value : computed(() => this.service.usage()?.response?.model.siteClasses)

List of site class Parameters

import {ChangeDetectionStrategy, Component, computed, inject, Signal} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {
  NshmpHazardLocationFormComponent,
  NshmpHazardMaxDirectionFormComponent,
  NshmpHazardModelFormComponent,
  NshmpHazardReturnPeriodFormComponent,
  NshmpHazardSiteClassFormComponent,
  NshmpHazardTruncationFormComponent,
} from '@ghsc/nshmp-lib-ng/hazard';
import {NshmpMapSelectSiteComponent, SelectSiteDialogData} from '@ghsc/nshmp-lib-ng/map';
import {
  NshmpControlPanelButtonsComponent,
  NshmpSectionComponent,
  NshmpService,
} from '@ghsc/nshmp-lib-ng/nshmp';
import {Location} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/geo';

import {environment} from '../../../../../environments/environment';
import {AppService} from '../../services/app.service';

/**
 * Control panel with form fields to call hazard service.
 */
@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {id: 'hazard-dynamic-control-panel'},
  imports: [
    NshmpHazardModelFormComponent,
    NshmpHazardLocationFormComponent,
    NshmpMapSelectSiteComponent,
    NshmpHazardSiteClassFormComponent,
    NshmpSectionComponent,
    NshmpHazardReturnPeriodFormComponent,
    NshmpHazardTruncationFormComponent,
    NshmpHazardMaxDirectionFormComponent,
    NshmpControlPanelButtonsComponent,
    ReactiveFormsModule,
  ],
  selector: 'app-control-panel',
  styleUrl: './control-panel.component.scss',
  templateUrl: './control-panel.component.html',
})
export class ControlPanelComponent {
  service = inject(AppService);
  private nshmpService = inject(NshmpService);

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

  /** List of site class `Parameter`s */
  siteClasses = computed(() => this.service.usage()?.response?.model.siteClasses);

  /** Data for select site component */
  selectSiteData: Signal<SelectSiteDialogData> = computed(() => {
    const usage = this.service.usage();
    const nshmService = this.service.nshmService();

    if (usage === null || nshmService === undefined) {
      return;
    }

    const services = environment.webServices.nshmpHazWs.services.curveServices;

    return {
      faultSectionsUrl: `${nshmService.url}${services.features}/FAULT?polygons=false&raw=true`,
      mapUrl: `${nshmService.url}${services.map}?raw=true`,
      sitesUrl: `${nshmService.url}${services.sites}?raw=true`,
    };
  });

  onReturnPeriodChange(): void {
    this.service.createHazardPlot();
    this.service.createSpectraPlot();
  }

  /**
   * On form submit.
   */
  onSubmit(): void {
    this.nshmpService.selectPlotControl();
    this.service.callService();
  }

  setLocation(location: Location): void {
    this.formGroup.patchValue({
      latitude: location.latitude,
      longitude: location.longitude,
    });
  }
}
<!-- Control Panel -->
<form class="height-full overflow-auto" [formGroup]="formGroup" (submit)="onSubmit()">
  <!-- Model -->
  <nshmp-hazard-model-form
    [modelControl]="formGroup.controls.model"
    [models]="service.availableModels()"
    [latitudeBounds]="service.usage()?.response?.latitude"
    [latitudeControl]="formGroup.controls.latitude"
    [longitudeBounds]="service.usage()?.response?.longitude"
    [longitudeControl]="formGroup.controls.longitude"
    (modelChange)="service.resetState()"
  />

  <!-- Latitude -->
  <nshmp-hazard-location-form
    class="latitude-input"
    [locationControl]="formGroup.controls.latitude"
    label="Latitude"
    [bounds]="service.usage()?.response?.latitude"
  />

  <!-- Longitude -->
  <nshmp-hazard-location-form
    class="longitude-input"
    [locationControl]="formGroup.controls.longitude"
    label="Longitude"
    [bounds]="service.usage()?.response?.longitude"
  />

  <!-- Select site -->
  <nshmp-map-select-site [data]="selectSiteData()" (siteSelect)="setLocation($event)" />

  <!-- Site Class -->
  <nshmp-hazard-site-class-form
    label="Site Class Presets"
    [siteClassControl]="formGroup.controls.siteClass"
    [siteClasses]="siteClasses()"
    [modelControl]="formGroup.controls.model"
    [vs30Control]="formGroup.controls.vs30"
    [vs30Bounds]="service.usage()?.response?.vs30"
    (vs30Change)="service.resetState()"
  />

  <nshmp-section label="Plot Options">
    <!-- Return Period Controls -->
    <nshmp-hazard-return-period-form
      [returnPeriodControl]="formGroup.controls.returnPeriod"
      [commonReturnPeriodControl]="formGroup.controls.commonReturnPeriods"
      (returnPeriodChange)="onReturnPeriodChange()"
    />

    <!-- Truncation -->
    <nshmp-hazard-truncation-form
      [truncationControl]="formGroup.controls.truncate"
      (truncationChange)="service.createPlots()"
    />

    <!-- Max Direction -->
    <nshmp-hazard-max-direction-form
      [maxDirectionControl]="formGroup.controls.maxDirection"
      (maxDirectionChange)="service.createPlots()"
    />
  </nshmp-section>

  <nshmp-control-panel-buttons
    [plotDisabled]="formGroup.invalid"
    [serviceCallInfo]="service.serviceCallInfo()"
    [resetDisabled]="formGroup.pristine"
    (resetClick)="service.resetControlPanel()"
  />
</form>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""