import re
import math
import gws
import gws.common.layer
import gws.types as t
import gws.gis.source
import gws.tools.json2
_EPSG_3857_RADIUS = 6378137
_EPSG_3857_EXTENT = [
-(math.pi * _EPSG_3857_RADIUS),
-(math.pi * _EPSG_3857_RADIUS),
+(math.pi * _EPSG_3857_RADIUS),
+(math.pi * _EPSG_3857_RADIUS),
]
[docs]class ServiceConfig:
"""Tile service configuration"""
extent: t.Optional[t.Extent] #: service extent
crs: t.Crs = 'EPSG:3857' #: service CRS
origin: str = 'nw' #: position of the first tile (nw or sw)
tileSize: int = 256 #: tile size
[docs]class Config(gws.common.layer.ImageTileConfig):
"""Tile layer"""
maxRequests: int = 0 #: max concurrent requests to this source
service: t.Optional[ServiceConfig] = {} #: service configuration
url: t.Url #: rest url with placeholders {x}, {y} and {z}
[docs]class Object(gws.common.layer.ImageTile):
@property
def props(self):
if self.display == 'client':
return gws.merge(super().props, type='xyz', url=self.url)
return super().props
@property
def own_bounds(self):
return t.Bounds(
crs=self.service.crs,
extent=self.service.extent)
[docs] def mapproxy_config(self, mc, options=None):
# we use {x} like in Ol, mapproxy wants %(x)s
url = re.sub(
r'{([xyz])}',
r'%(\1)s',
self.url)
grid_uid = mc.grid(gws.compact({
'origin': self.service.origin,
'bbox': self.service.extent,
# 'res': res,
'srs': self.service.crs,
'tile_size': [self.service.tileSize, self.service.tileSize],
}))
src = self.mapproxy_back_cache_config(mc, url, grid_uid)
self.mapproxy_layer_config(mc, src)