import * as olExtent from 'ol/extent' ; import { Component , OnInit } from '@angular/core' ; import { HsAttributionDialogComponent } from './attribution-dialog.component' ; import { HsConfig , HsLayerManagerService , HsMapService } from 'hslayers-ng' ; import { MatDialog } from '@angular/material/dialog' ; import { Vector as VectorLayer } from 'ol/layer' ; @ Component ( { selector : 'hs-mat-overlay' , templateUrl : './overlay.component.html' , } ) export class HsMatOverlayComponent implements OnInit { constructor ( public HsConfig , private HsMapService , private HsLayerManagerService , public dialog ) { } ngOnInit ( ) { this . HsConfig . componentsEnabled . mapControls = false ; this . HsConfig . componentsEnabled . defaultViewButton = false ; } openAttributionDialog ( event ) { this . dialog . open ( HsAttributionDialogComponent , { data : this . HsMapService . getLayersArray ( ) . filter ( ( layer ) => layer . getVisible ( ) ) . map ( ( layer ) => layer . getSource ( ) . getAttributions ( ) ) . filter ( ( f ) => f ) . map ( ( getAttributions ) => getAttributions ( undefined ) ) . reduce ( ( acc , item ) => { if ( Array . isArray ( item ) ) { return [ ... acc , ... item ] ; } return [ ... acc , item ] ; } , [ ] ) , } ) ; } canZoomOut ( ) { const mapView = this . HsMapService . map ?. getView ( ) ; return mapView ?. getZoom ( ) > mapView ?. getMinZoom ( ) ; } canZoomIn ( ) { const mapView = this . HsMapService . map ?. getView ( ) ; return mapView ?. getZoom ( ) < mapView ?. getMaxZoom ( ) ; } adjustZoom ( delta ) { const mapView = this . HsMapService . map ?. getView ( ) ; mapView . animate ( { zoom : mapView . getZoom ( ) + delta , duration : 300 } ) ; } defaultView ( ) { this . HsMapService . map ?. getView ( ) . animate ( { center : this . HsConfig . default_view . getCenter ( ) , zoom : this . HsConfig . default_view . getZoom ( ) , duration : 300 , } ) ; } maxView ( ) { const extent = olExtent . createEmpty ( ) ; if ( this . HsLayerManagerService . data . layers . length == 0 ) { return ; } this . HsLayerManagerService . data . layers . forEach ( ( layer ) => { if ( layer . visible && layer . layer instanceof VectorLayer ) { olExtent . extend ( extent , layer . layer . getSource ( ) . getExtent ( ) ) ; } } ) ; this . HsMapService . map ?. getView ( ) . fit ( extent , { size : this . HsMapService . map . getSize ( ) , padding : [ 50 , 50 , 50 , 50 ] , duration : 300 , } ) ; } }