import { Component , Input , OnInit } from '@angular/core' ; import Feature from 'ol/Feature' ; import { Geometry } from 'ol/geom' ; import { HsFeatureTableService } from './feature-table.service' ; import { HsLanguageService } from './../language/language.service' ; import { HsLayerUtilsService } from '../utils/layer-utils.service' ; import { HsMapService } from '../map/map.service' ; import { HsUtilsService } from '../utils/utils.service' ; type Operation = { action : 'zoom to' | 'delete' | 'custom action' ; feature : Feature < Geometry > ; customActionName ? : string ; customAction ? : any ; } ; @ Component ( { selector : 'hs-layer-features' , templateUrl : './partials/layer-features.html' , styles : [ `
      td,
      th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 6px;
        font-size: 14px;
      }
      .tdbreak {
        overflow-wrap: break-word;
        word-break: break-word;
      }
    ` , ] , } ) export class HsLayerFeaturesComponent implements OnInit { @ Input ( 'layer' ) layer : any ; showFeatureStats = false ; searchedFeatures = '' ; constructor ( public HsFeatureTableService , public HsUtilsService , public HsMapService , public HsLanguageService , public HsLayerUtilsService ) { } public description ngOnInit ( ) { const olLayer = this . layer . lyr ; const source = this . HsLayerUtilsService . isLayerClustered ( olLayer ) ? olLayer . getSource ( ) . getSource ( ) : olLayer . getSource ( ) ; if ( source ) { this . HsFeatureTableService . fillFeatureList ( olLayer ) ; source . on ( 'changefeature' , ( e ) => { this . HsFeatureTableService . updateFeatureDescription ( e . feature ) ; } ) ; source . on ( 'addfeature' , ( e ) => { this . HsFeatureTableService . addFeatureDescription ( e . feature ) ; } ) ; source . on ( 'removefeature' , ( e ) => { this . HsFeatureTableService . removeFeatureDescription ( e . feature ) ; } ) ; } } param operation public description executeOperation ( operation ) { switch ( operation . action ) { case 'zoom to' : const extent = operation . feature . getGeometry ( ) . getExtent ( ) ; this . HsMapService . fitExtent ( extent ) ; break ; case 'custom action' : operation . customAction ( operation . feature ) ; break ; default : } } }