import { Component , Input } from '@angular/core' ; import VectorLayer from 'ol/layer/Vector' ; import VectorSource from 'ol/source/Vector' ; import { Geometry } from 'ol/geom' ; import { Layer } from 'ol/layer' ; import { Source } from 'ol/source' ; import { HsClusterWidgetComponent } from '../widgets/cluster-widget.component' ; import { HsConfirmDialogComponent } from './../../../common/confirm/confirm-dialog.component' ; import { HsCopyLayerDialogComponent } from '../dialogs/copy-layer-dialog.component' ; import { HsDialogContainerService } from '../../layout/dialogs/dialog-container.service' ; import { HsDimensionTimeService } from '../../../common/get-capabilities/dimension-time.service' ; import { HsDrawService } from '../../draw/draw.service' ; import { HsEventBusService } from '../../core/event-bus.service' ; import { HsLanguageService } from './../../language/language.service' ; import { HsLayerDescriptor } from './../layer-descriptor.interface' ; import { HsLayerEditorDimensionsComponent } from '../dimensions/layer-editor-dimensions.component' ; import { HsLayerEditorService } from './layer-editor.service' ; import { HsLayerEditorSublayerService } from './layer-editor.sub-layer.service' ; import { HsLayerEditorWidgetContainerService } from '../widgets/layer-editor-widget-container.service' ; import { HsLayerManagerRemoveLayerDialogComponent } from '../dialogs/remove-layer-dialog.component' ; import { HsLayerManagerService } from '../layermanager.service' ; import { HsLayerUtilsService } from '../../utils/layer-utils.service' ; import { HsLayoutService } from '../../layout/layout.service' ; import { HsLegendWidgetComponent } from '../widgets/legend-widget.component' ; import { HsMapService } from '../../map/map.service' ; import { HsMetadataWidgetComponent } from '../widgets/metadata-widget.component' ; import { HsOpacityWidgetComponent } from '../widgets/opacity-widget.component' ; import { HsScaleWidgetComponent } from '../widgets/scale-widget.component' ; import { HsStylerService } from '../../styles/styler.service' ; import { HsTypeWidgetComponent } from '../widgets/type-widget.component' ; import { getBase , getCachedCapabilities , getRemovable , getTitle , setTitle , } from '../../../common/layer-extensions' ; @ Component ( { selector : 'hs-layer-editor' , templateUrl : './layer-editor.html' , } ) export class HsLayerEditorComponent { _currentLayer : HsLayerDescriptor ; @ Input ( 'current-layer' ) set currentLayer ( value ) { this . _currentLayer = value ; this . tmpTitle = undefined ; this . layer_renamer_visible = false ; } get currentLayer ( ) : HsLayerDescriptor { return this . _currentLayer ; } layer_renamer_visible = false ; getBase = getBase ; tmpTitle : string = undefined ; constructor ( public HsLayerUtilsService , public HsDimensionTimeService , public HsStylerService , public HsMapService , public HsLayerManagerService , public HsLayoutService , public HsLayerEditorSublayerService , public HsLayerEditorService , public HsDrawService , public HsEventBusService , public HsDialogContainerService , public HsLanguageService , public hsLayerEditorWidgetContainerService ) { this . hsLayerEditorWidgetContainerService . create ( HsTypeWidgetComponent , { } ) ; this . hsLayerEditorWidgetContainerService . create ( HsMetadataWidgetComponent , { } ) ; this . hsLayerEditorWidgetContainerService . create ( HsScaleWidgetComponent , { } ) ; this . hsLayerEditorWidgetContainerService . create ( HsClusterWidgetComponent , { } ) ; this . hsLayerEditorWidgetContainerService . create ( HsLegendWidgetComponent , { } ) ; this . hsLayerEditorWidgetContainerService . create ( HsLayerEditorDimensionsComponent , { } ) ; this . hsLayerEditorWidgetContainerService . create ( HsOpacityWidgetComponent , { } ) ; } returns async createSaveDialog ( ) { const dialog = this . HsDialogContainerService . create ( HsConfirmDialogComponent , { message : this . HsLanguageService . getTranslation ( 'LAYERMANAGER.layerEditor.savegeojson' ) + '?' , title : this . HsLanguageService . getTranslation ( 'COMMON.confirm' ) , } ) ; const confirmed = await dialog . waitResult ( ) ; if ( confirmed == 'yes' ) { return this . HsLayerManagerService . saveGeoJson ( ) ; } } layerIsWmsT ( ) { return this . HsDimensionTimeService . layerIsWmsT ( this . currentLayer ) ; } returns zoomToLayer ( ) { return this . HsLayerEditorService . zoomToLayer ( this . olLayer ( ) ) ; } /**
     * Display styler panel for selected layer, so user can change its style
     */ styleLayer ( ) { const layer = this . olLayer ( ) ; this . HsStylerService . layer = layer as VectorLayer < VectorSource < Geometry > > ; this . HsLayoutService . setMainPanel ( 'styler' ) ; } /**
     * Toogle layer rename control on panel (through layer rename variable)
     */ toggleLayerRename ( ) { this . tmpTitle = undefined ; this . layer_renamer_visible = ! this . layer_renamer_visible ; } /**
     * Determines if selected layer has BoundingBox defined as
     * its metadata or is a Vector layer. Used for setting visibility
     * of 'Zoom to ' button
     */ layerIsZoomable ( ) { return this . HsLayerUtilsService . layerIsZoomable ( this . olLayer ( ) ) ; } /**
     * Determines if selected layer is a Vector layer and
     * styleable. Used for allowing styling
     */ layerIsStyleable ( ) { return this . HsLayerUtilsService . layerIsStyleable ( this . olLayer ( ) ) ; } /**
     * Check if layer can be removed based on 'removable'
     * layer attribute
     */ isLayerRemovable ( ) { const layer = this . olLayer ( ) ; return ( ! layer || getRemovable ( layer ) == undefined || getRemovable ( layer ) == true ) ; } removeLayer ( ) { this . HsDialogContainerService . create ( HsLayerManagerRemoveLayerDialogComponent , { olLayer : this . olLayer ( ) } ) ; } olLayer ( ) { if ( ! this . currentLayer ) { return undefined ; } return this . currentLayer . layer ; } param newTitle set title ( newTitle ) { this . tmpTitle = newTitle . trim ( ) ; } get title ( ) : string { const layer = this . olLayer ( ) ; if ( layer == undefined ) { return ; } if ( this . tmpTitle == undefined ) { this . tmpTitle = getTitle ( layer ) ; } return this . tmpTitle ; } saveTitle ( ) { const layer = this . olLayer ( ) ; if ( layer == undefined ) { return ; } this . HsLayerEditorService . layerTitleChange . next ( { newTitle : this . tmpTitle , oldTitle : getTitle ( layer ) , layer , } ) ; setTitle ( layer , this . tmpTitle ) ; this . HsEventBusService . layerManagerUpdates . next ( ) ; this . toggleLayerRename ( ) ; } titleUnsaved ( ) { return this . tmpTitle != getTitle ( this . olLayer ( ) ) ; } hasSubLayers ( ) { if ( this . currentLayer === null ) { return ; } const subLayers = getCachedCapabilities ( this . currentLayer . layer ) ?. Layer ; return subLayers != undefined && subLayers . length > 0 ; } getSubLayers ( ) { return this . HsLayerEditorSublayerService . getSubLayers ( ) ; } async copyLayer ( ) { const dialog = this . HsDialogContainerService . create ( HsCopyLayerDialogComponent , { message : this . HsLanguageService . getTranslation ( 'LAYERMANAGER.layerEditor.copyLayer' ) + '?' , title : this . HsLanguageService . getTranslation ( 'COMMON.copyLayer' ) , layerTitle : getTitle ( this . currentLayer . layer ) , } ) ; const result = await dialog . waitResult ( ) ; if ( result . confirmed == 'yes' ) { return this . HsLayerManagerService . copyLayer ( result . layerTitle ) ; } } }