-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtile_layers.py
57 lines (42 loc) · 1.45 KB
/
tile_layers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Tile Layers
-----------
"""
from __future__ import annotations
import dataclasses
from dataclasses import dataclass
from typing import Union
import xyzservices
LeafletOption = Union[str, bool, int, float]
@dataclass
class RasterWebTile:
"""
A class for the background tile layer of Leaflet map that uses a raster
tile server as the source of the tiles.
The available options can be found at: https://leafletjs.com/reference.html#tilelayer
"""
url: str
options: dict[str, LeafletOption] | None = None
kind: str = "raster_web_tile"
@classmethod
def from_xyzservices(cls, provider: xyzservices.TileProvider) -> RasterWebTile:
"""
Create a RasterWebTile from an xyzservices TileProvider.
:param provider: The xyzservices TileProvider to use.
:return: A RasterWebTile instance.
"""
provider_dict = dict(provider)
url = provider_dict.pop("url")
attribution = provider_dict.pop("html_attribution")
provider_dict.update({"attribution": attribution})
return cls(url=url, options=provider_dict)
def to_dict(self) -> dict:
return dataclasses.asdict(self)
@dataclass
class WMSWebTile(RasterWebTile):
"""
A class for the background tile layer of Leaflet map that uses a WMS
service as the source of the tiles.
The available options can be found at: https://leafletjs.com/reference.html#tilelayer-wms
"""
kind = "wms_web_tile"