import { HsConfig } from '../../config.service' ; import { HsEventBusService } from './event-bus.service' ; import { HsLayoutService } from '../layout/layout.service' ; import { HsLogService } from '../../common/log/log.service' ; import { HsMapService } from '../map/map.service' ; import { HsUtilsService } from '../utils/utils.service' ; import { Injectable } from '@angular/core' ; import { TranslateService } from '@ngx-translate/core' ; @ Injectable ( { providedIn : 'root' , } ) export class HsCoreService { public embeddedEnabled = true ; language = 'en' ; config : any ; _puremapApp = false ; initCalled : boolean ; missingLRFunctionsWarned : any ; constructor ( public HsMapService , public HsConfig , public HsLayoutService , public HsUtilsService , private log , public HsEventBusService , private translate ) { public type { object } this . config = HsConfig ; if ( window . innerWidth < 767 || this . HsConfig . sidebarClosed ) { this . HsLayoutService . sidebarExpanded = false ; this . HsLayoutService . sidebarLabels = false ; } else { this . HsLayoutService . sidebarExpanded = true ; } const languages = this . HsConfig . enabledLanguages ? this . HsConfig . enabledLanguages . split ( ',' ) . map ( ( lang ) => lang . trim ( ) ) : [ 'cs' , 'lv' ] ; this . translate . addLangs ( languages ) ; this . translate . setDefaultLang ( 'en' ) ; if ( this . HsConfig . language ) { this . translate . use ( this . HsConfig . language ) ; } this . HsEventBusService . layoutLoads . subscribe ( ( { element , innerElement } ) => { this . init ( ) ; } ) ; } public init ( ) { if ( this . initCalled ) { return ; } this . HsMapService . loaded ( ) . then ( ( ) => { this . initSizeListeners ( ) ; setTimeout ( ( ) => { this . updateVH ( ) ; this . updateMapSize ( ) ; } , 750 ) ; this . initCalled = true ; } ) ; } private private updateVH ( ) { if ( this . HsUtilsService . runningInBrowser ( ) ) { const vh = window . innerHeight * 0.01 ; document . body . style . setProperty ( '--vh' , `${ vh }px` ) ; if ( window . matchMedia ( '(orientation: portrait)' ) . matches ) { document . getElementsByTagName ( 'html' ) [ 0 ] . style . height = '100vh' ; setTimeout ( ( ) => { document . getElementsByTagName ( 'html' ) [ 0 ] . style . height = '100%' ; } , 500 ) ; } } } public initSizeListeners ( ) { window . addEventListener ( 'resize' , ( ) => { this . HsUtilsService . debounce ( function ( ) { this . updateVH ( ) ; this . updateMapSize ( ) ; this . HsEventBusService . layoutResizes . next ( ) ; } , 300 , false , this ) ( ) ; } ) ; } public updateMapSize ( ) { const map = this . HsLayoutService . contentWrapper . querySelector ( '.hs-ol-map' ) ; if ( map === null ) { return ; } if ( this . HsMapService . map ) { this . HsMapService . map . updateSize ( ) ; if ( window . innerWidth < 767 || this . HsLayoutService . mainpanel != '' ) { this . HsLayoutService . smallWidth = true ; this . HsLayoutService . sidebarLabels = false ; } else { this . HsLayoutService . smallWidth = false ; this . HsLayoutService . sidebarLabels = true ; } } else { console . log ( 'Map not yet initialized!' ) ; } const neededSize = { width : map . offsetWidth , height : map . offsetHeight , } ; this . HsEventBusService . sizeChanges . next ( neededSize ) ; } public returns isAuthorized ( ) { if ( window [ 'getLRUser' ] === undefined && ! this . missingLRFunctionsWarned ) { this . log . warn ( 'window.getLRUser function needs to be defined, which usually comes from Liferay.' ) ; this . missingLRFunctionsWarned = true ; } if ( window [ 'getLRUser' ] && window [ 'getLRUser' ] ( ) != 'guest' ) { return true ; } return false ; } public resetMap ( ) { this . HsMapService . reset ( ) ; this . HsEventBusService . mapResets . next ( ) ; } public returns isMobile ( ) { if ( window [ 'cordova' ] ) { return 'mobile' ; } else { return '' ; } } public get puremapApp ( ) { return this . _puremapApp ; } set puremapApp ( value ) { this . _puremapApp = value ; if ( value ) { this . HsConfig . componentsEnabled . guiOverlay = false ; this . HsMapService . removeAllInteractions ( ) ; this . HsMapService . removeAllControls ( ) ; this . HsLayoutService . sidebarVisible ( false ) ; } } }