import { Component , Input , OnInit } from '@angular/core' ; import { DomSanitizer , SafeHtml , SafeResourceUrl , } from '@angular/platform-browser' ; import { getLegends } from '../../../common/layer-extensions' ; @ Component ( { selector : 'hs-legend-layer-static' , templateUrl : './legend-layer-static.component.html' , } ) export class HsLegendLayerStaticComponent implements OnInit { @ Input ( ) layer : any ; lastLegendImage : any ; legendType : string ; svgContent : SafeHtml ; legendImage : SafeResourceUrl ; constructor ( private sanitizer ) { } fillContent ( ) { let legendImage = getLegends ( this . layer . lyr ) ; if ( Array . isArray ( legendImage ) ) { legendImage = legendImage [ 0 ] ; } if ( legendImage ) { this . lastLegendImage = legendImage ; if ( legendImage . indexOf ( '<svg' ) > - 1 ) { this . legendType = 'svg' ; this . svgContent = this . sanitizer . bypassSecurityTrustHtml ( legendImage ) ; } else { this . legendType = 'image' ; this . legendImage = this . sanitizer . bypassSecurityTrustResourceUrl ( legendImage ) ; } } } ngOnInit ( ) { if ( getLegends ( this . layer . lyr ) ) { this . fillContent ( ) ; } this . layer . lyr . on ( 'change' , ( e ) => { if ( getLegends ( this . layer . lyr ) != this . lastLegendImage ) { this . fillContent ( ) ; } } ) ; } }