Coverage for gws-app/gws/plugin/tile_layer/provider.py: 0%
29 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1"""Tile provider."""
3from typing import Optional, cast
5import gws
6import gws.base.layer
7import gws.config.util
8import gws.gis.crs
9import gws.gis.extent
10import gws.gis.zoom
11import gws.lib.metadata
12import gws.lib.net
15class Config(gws.Config):
16 maxRequests: int = 0
17 """max concurrent requests to this source"""
18 url: gws.Url
19 """rest url with placeholders {x}, {y} and {z}"""
20 grid: Optional[gws.base.layer.GridConfig]
21 """source grid"""
24class Object(gws.Node):
25 url: gws.Url
26 grid: Optional[gws.TileGrid]
27 maxRequests: int
29 def configure(self):
30 self.url = self.cfg('url')
31 self.maxRequests = self.cfg('maxRequests')
33 p = self.cfg('grid', default=gws.Config())
34 self.grid = gws.TileGrid(
35 origin=p.origin or gws.Origin.nw,
36 tileSize=p.tileSize or 256,
37 )
38 crs = p.crs or gws.gis.crs.WEBMERCATOR
39 extent = p.extent or (gws.gis.crs.WEBMERCATOR_SQUARE if crs == gws.gis.crs.WEBMERCATOR else crs.extent)
40 self.grid.bounds = gws.Bounds(crs=crs, extent=extent)
41 self.grid.resolutions = (
42 p.resolutions or
43 gws.gis.zoom.resolutions_from_bounds(self.grid.bounds, self.grid.tileSize))