Coverage for gws-app/gws/plugin/tile_layer/provider.py: 0%

29 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-16 22:59 +0200

1"""Tile provider.""" 

2 

3from typing import Optional, cast 

4 

5import gws 

6import gws.base.layer 

7import gws.config.util 

8import gws.lib.crs 

9import gws.lib.extent 

10import gws.gis.zoom 

11import gws.base.metadata 

12import gws.lib.net 

13 

14 

15class Config(gws.Config): 

16 """Tile provider configuration.""" 

17 

18 maxRequests: int = 0 

19 """Max concurrent requests to this source.""" 

20 url: gws.Url 

21 """Rest url with placeholders {x}, {y} and {z}.""" 

22 grid: Optional[gws.base.layer.GridConfig] 

23 """Source grid.""" 

24 

25 

26class Object(gws.Node): 

27 url: gws.Url 

28 grid: Optional[gws.TileGrid] 

29 maxRequests: int 

30 

31 def configure(self): 

32 self.url = self.cfg('url') 

33 self.maxRequests = self.cfg('maxRequests') 

34 

35 p = self.cfg('grid', default=gws.Config()) 

36 self.grid = gws.TileGrid( 

37 origin=p.origin or gws.Origin.nw, 

38 tileSize=p.tileSize or 256, 

39 ) 

40 crs = p.crs or gws.lib.crs.WEBMERCATOR 

41 extent = p.extent or (gws.lib.crs.WEBMERCATOR_SQUARE if crs == gws.lib.crs.WEBMERCATOR else crs.extent) 

42 self.grid.bounds = gws.Bounds(crs=crs, extent=extent) 

43 self.grid.resolutions = ( 

44 p.resolutions or 

45 gws.gis.zoom.resolutions_from_bounds(self.grid.bounds, self.grid.tileSize))