2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  Map  as  MLMap ,  RasterSourceSpecification ,  VectorTileSource  }  from  "maplibre-gl"  
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  Store ,  Stores ,  UIEventSource  }  from  "../../Logic/UIEventSource"  
						 
					
						
							
								
									
										
										
										
											2024-10-08 13:18:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  RasterLayerPolygon  }  from  "../../Models/RasterLayers"  
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  RasterLayerProperties  }  from  "../../Models/RasterLayerProperties"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  Utils  }  from  "../../Utils"  
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  VectorSourceSpecification  }  from  "@maplibre/maplibre-gl-style-spec"  
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  SingleBackgroundHandler  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Value between 0 and 1.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  opacity  =  new  UIEventSource < number > ( 0.0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  _map : Store < MLMap > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  _background : UIEventSource < RasterLayerPolygon  |  undefined > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  readonly  _targetLayer : RasterLayerPolygon 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  _deactivationTime : Date  =  undefined 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  Deactivate  a  layer  after  60  seconds 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  static  readonly  DEACTIVATE_AFTER  =  60 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  fadeStep  =  0.1 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    constructor ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        map : Store < MLMap > , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        targetLayer : RasterLayerPolygon , 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-14 13:53:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        background : UIEventSource < RasterLayerPolygon  |  undefined > 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . _targetLayer  =  targetLayer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . _map  =  map 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . _background  =  background 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        background . addCallback ( async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await  this . update ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        map . addCallbackAndRunD ( async  ( map )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            map . on ( "load" ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                await  this . update ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await  this . update ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            map . on ( "moveend" ,  ( )  = >  this . onMove ( map ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            map . on ( "zoomend" ,  ( )  = >  this . onMove ( map ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  onMove ( map : MLMap )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! this . _deactivationTime )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // in seconds
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  timeSinceDeactivation  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ( new  Date ( ) . getTime ( )  -  this . _deactivationTime . getTime ( ) )  /  1000 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( timeSinceDeactivation  <  SingleBackgroundHandler . DEACTIVATE_AFTER )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        console . debug ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "Removing raster layer" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . _targetLayer . properties . id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "map moved and not been used for" , 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-14 13:53:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            SingleBackgroundHandler . DEACTIVATE_AFTER 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-11 16:27:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( map . getLayer ( < string > this . _targetLayer . properties . id ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                map . removeLayer ( < string > this . _targetLayer . properties . id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            console . warn ( "Could not (try to) remove the raster layer" ,  e ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  async  update() { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  newTarget : RasterLayerPolygon  |  undefined  =  this . _background . data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  targetLayer  =  this . _targetLayer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( newTarget ? . properties ? . id  !==  targetLayer . properties . id )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . _deactivationTime  =  new  Date ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await  this . awaitStyleIsLoaded ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . fadeOut ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . _deactivationTime  =  undefined 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 18:47:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            await  this . enable ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            this . fadeIn ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    private  async  awaitStyleIsLoaded ( ) :  Promise < void >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  map  =  this . _map . data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! map )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        while  ( ! map ? . isStyleLoaded ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-08 13:18:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            await  Utils . waitFor ( 100 ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    private  async  enable() { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 18:47:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        let  ttl  =  15 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await  this . awaitStyleIsLoaded ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        while  ( ! this . tryEnable ( )  &&  ttl  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ttl -- 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 18:47:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            await  Utils . waitFor ( 250 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  Returns  'false'  if  should  be  attempted  again 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @private 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  tryEnable ( ) :  boolean  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        const  map : MLMap  =  this . _map . data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! map )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 18:47:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            return  true 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  background  =  this . _targetLayer . properties 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        console . debug ( "Enabling" ,  background . id ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        let  addLayerBeforeId  =  "transit_pier"  // this is the first non-landuse item in the stylesheet, we add the raster layer before the roads but above the landuse
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! map . getLayer ( addLayerBeforeId ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-20 04:21:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            console . warn ( "Layer" ,  addLayerBeforeId ,  "not found" ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            addLayerBeforeId  =  undefined 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        if  ( background . category  ===  "osmbasedmap"  ||  background . category  ===  "map" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // The background layer is already an OSM-based map or another map, so we don't want anything from the baselayer
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            addLayerBeforeId  =  undefined 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        if  ( ! map . getSource ( background . id ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 16:43:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            try  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                map . addSource ( background . id ,  RasterLayerHandler . prepareSource ( background ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 16:43:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  catch  ( e )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 18:47:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                return  false 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 16:43:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! map . getLayer ( background . id ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            addLayerBeforeId  ? ? =  map 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . getStyle ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . layers . find ( ( l )  = >  l . id . startsWith ( "mapcomplete_" ) ) ? . id 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( background . type  ===  "vector" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-30 13:07:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                const  styleToSet  =  background . style  ? ?  background . url 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                map . setStyle ( styleToSet ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                map . addLayer ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        id : background.id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        type :  "raster" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        source : background.id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        paint :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            "raster-opacity" :  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        } , 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    } , 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-14 13:53:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    addLayerBeforeId 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . opacity . addCallbackAndRun ( ( o )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    try  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 15:50:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        map . setPaintProperty ( background . id ,  "raster-opacity" ,  o ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    }  catch  ( e )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 15:50:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        console . debug ( "Could not set raster-opacity of" ,  background . id ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 22:04:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        return  true  // This layer probably doesn't exist anymore, so we unregister
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 15:50:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 18:47:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  true 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  fadeOut() { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Stores . Chronic ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            8 , 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-14 13:53:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ( )  = >  this . opacity . data  >  0  &&  this . _deactivationTime  !==  undefined 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        ) . addCallback ( ( _ )  = >  this . opacity . setData ( Math . max ( 0 ,  this . opacity . data  -  this . fadeStep ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  fadeIn() { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Stores . Chronic ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            8 , 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-14 13:53:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ( )  = >  this . opacity . data  <  1.0  &&  this . _deactivationTime  ===  undefined 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        ) . addCallback ( ( _ )  = >  this . opacity . setData ( Math . min ( 1.0 ,  this . opacity . data  +  this . fadeStep ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  default  class  RasterLayerHandler  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  _singleLayerHandlers : Record < string ,  SingleBackgroundHandler >  =  { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( map : Store < MLMap > ,  background : UIEventSource < RasterLayerPolygon  |  undefined > )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        background . addCallbackAndRunD ( ( l )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  key  =  l . properties . id 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! this . _singleLayerHandlers [ key ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . _singleLayerHandlers [ key ]  =  new  SingleBackgroundHandler ( map ,  l ,  background ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  static  prepareSource ( 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-14 13:53:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        layer : RasterLayerProperties 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) :  RasterSourceSpecification  |  VectorSourceSpecification  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( layer . type  ===  "vector" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  vs : VectorSourceSpecification  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                type :  "vector" , 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                url : layer.url , 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 12:16:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  vs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            type :  "raster" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // use the tiles option to specify a 256WMS tile source URL
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // https://maplibre.org/maplibre-gl-js-docs/style-spec/sources/
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tiles :  [ RasterLayerHandler . prepareWmsURL ( layer . url ,  layer [ "tile-size" ]  ? ?  256 ) ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tileSize : layer [ "tile-size" ]  ? ?  256 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            minzoom : layer [ "min_zoom" ]  ? ?  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            maxzoom : layer [ "max_zoom" ]  ? ?  25 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Bit of a hack, but seems to work
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            scheme : layer.url.includes ( "{-y}" )  ?  "tms"  :  "xyz" , 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  static  prepareWmsURL ( url : string ,  size : number  =  256 ) :  string  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ELI:  LAYERS=OGWRGB13_15VL&STYLES=&FORMAT=image/jpeg&CRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // PROD: SERVICE=WMS&REQUEST=GetMap&LAYERS=OGWRGB13_15VL&STYLES=&FORMAT=image/jpeg&TRANSPARENT=false&VERSION=1.3.0&WIDTH=256&HEIGHT=256&CRS=EPSG:3857&BBOX=488585.4847988467,6590094.830634755,489196.9810251281,6590706.32686104
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  toReplace  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "{bbox}" :  "{bbox-epsg-3857}" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "{proj}" :  "EPSG:3857" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "{width}" :  ""  +  size , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "{height}" :  ""  +  size , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "{zoom}" :  "{z}" , 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            "{-y}" :  "{y}" , 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 00:04:24 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  key  in  toReplace )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            url  =  url . replace ( new  RegExp ( key ) ,  toReplace [ key ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  subdomains  =  url . match ( /\{switch:([a-zA-Z0-9,]*)}/ ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( subdomains  !==  null )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  options  =  subdomains [ 1 ] . split ( "," ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  option  =  options [ Math . floor ( Math . random ( )  *  options . length ) ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            url  =  url . replace ( subdomains [ 0 ] ,  option ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  url 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}