import { Injectable } from '@angular/core' ; import VectorLayer from 'ol/layer/Vector' ; import VectorSource from 'ol/source/Vector' ; import { Feature } from 'ol' ; import { Fill , Stroke , Style } from 'ol/style' ; import { Geometry } from 'ol/geom' ; import { Vector } from 'ol/source' ; import { transform } from 'ol/proj' ; import { HsCommonEndpointsService } from '../../../common/endpoints/endpoints.service' ; import { HsLayerUtilsService } from '../../utils/layer-utils.service' ; import { HsLogService } from '../../../common/log/log.service' ; import { HsMapService } from '../../map/map.service' ; import { HsSaveMapService } from '../../save-map/save-map.service' ; import { getHighlighted , setHighlighted , } from '../../../common/feature-extensions' ; @ Injectable ( { providedIn : 'root' , } ) export class HsAddDataCatalogueMapService { extentLayer : VectorLayer < VectorSource < Geometry > > = new VectorLayer ( { source : new Vector ( ) , properties : { title : 'Datasources extents' , showInLayerManager : false , removable : false , } , style : function ( feature , resolution ) { return [ new Style ( { stroke : new Stroke ( { color : '#005CB6' , width : getHighlighted ( feature as Feature < Geometry > ) ? 4 : 1 , } ) , fill : new Fill ( { color : 'rgba(0, 0, 255, 0.01)' , } ) , } ) , ] ; } , } ) ; constructor ( public hsMapService , public hsLogService , private hsSaveMapService , public hsLayerUtilsService , private hsCommonEndpointsService ) { this . hsMapService . loaded ( ) . then ( ( map ) => this . init ( map ) ) ; } param evt mapPointerMoved ( evt ) { const featuresUnderMouse = this . extentLayer . getSource ( ) . getFeaturesAtCoordinate ( evt . coordinate ) ; for ( const endpoint of this . hsCommonEndpointsService . endpoints . filter ( ( ep ) => ep . layers ) ) { this . hsLayerUtilsService . highlightFeatures ( featuresUnderMouse , this . extentLayer , endpoint . layers ) ; } } param map init ( map ) { map . on ( 'pointermove' , ( evt ) => this . mapPointerMoved ( evt ) ) ; map . addLayer ( this . extentLayer ) ; this . hsSaveMapService . internalLayers . push ( this . extentLayer ) ; } clearExtentLayer ( ) { this . extentLayer . getSource ( ) . clear ( ) ; } param dataset clearDatasetFeatures ( dataset ) { if ( dataset . layers ) { dataset . layers . forEach ( ( val ) => { try { if ( val ) { this . extentLayer . getSource ( ) . clear ( ) ; } } catch ( ex ) { this . hsLogService . warn ( ex ) ; } } ) ; } } param layer returns isZoomable ( layer ) { return layer . bbox !== undefined ; } param extentFeature addExtentFeature ( extentFeature ) { this . extentLayer . getSource ( ) . addFeatures ( [ extentFeature ] ) ; } highlightLayer ( composition , state ) { if ( composition . featureId !== undefined ) { const found = this . extentLayer . getSource ( ) . getFeatureById ( composition . featureId ) ; if ( found ) { setHighlighted ( found , state ) ; } } } param bbox zoomTo ( bbox ) { if ( bbox === undefined ) { return ; } let b = null ; if ( typeof bbox === 'string' ) { b = bbox . split ( ' ' ) ; } else if ( Array . isArray ( bbox ) ) { b = bbox ; } let first_pair = [ parseFloat ( b [ 0 ] ) , parseFloat ( b [ 1 ] ) ] ; let second_pair = [ parseFloat ( b [ 2 ] ) , parseFloat ( b [ 3 ] ) ] ; first_pair = transform ( first_pair , 'EPSG:4326' , this . hsMapService . map . getView ( ) . getProjection ( ) ) ; second_pair = transform ( second_pair , 'EPSG:4326' , this . hsMapService . map . getView ( ) . getProjection ( ) ) ; if ( isNaN ( first_pair [ 0 ] ) || isNaN ( first_pair [ 1 ] ) || isNaN ( second_pair [ 0 ] ) || isNaN ( second_pair [ 1 ] ) ) { return ; } const extent = [ first_pair [ 0 ] , first_pair [ 1 ] , second_pair [ 0 ] , second_pair [ 1 ] , ] ; this . hsMapService . fitExtent ( extent ) ; } }