1
1
from __future__ import annotations
2
2
3
+ import os
4
+
3
5
from enum import Enum
4
6
5
- from pydantic import BaseModel
7
+ from pydantic import BaseModel , Field
6
8
7
9
from .abstracts import LayerLike
8
10
from .models .layers import TileLayer
9
- from .models .sources import OSM , ImageTileSource
11
+ from .models .sources import OSM , ImageTileSource , TileJSONSource
12
+ from .constants import MAPTILER_API_KEY_ENV_VAR
10
13
11
14
# light_all,
12
15
# dark_all,
@@ -25,7 +28,14 @@ class Carto(Enum):
25
28
26
29
LIGHT_ALL = "light_all"
27
30
DARK_ALL = "dark_all"
28
- VOYAGER_NO_LABLES = "rastertiles/voyager_nolabels"
31
+ LIGHT_NO_LABELS = "light_nolabels"
32
+ LIGHT_ONLY_LABELS = "light_only_labels"
33
+ DARK_NO_LABELS = "dark_nolabels"
34
+ DARK_ONLY_LABELS = "dark_only_labels"
35
+ VOYAGER = "rastertiles/voyager"
36
+ VOYAGER_NO_LABELS = "rastertiles/voyager_nolabels"
37
+ VOYAGER_ONLY_LABELS = "rastertiles/voyager_only_labels"
38
+ VOYAGER_LABELS_UNDER = "rastertiles/voyager_labels_under"
29
39
30
40
31
41
class CartoRasterStyle (BaseModel ):
@@ -108,8 +118,63 @@ def carto(
108
118
109
119
110
120
class CartoBasemapLayer (LayerLike ):
111
- def __init__ (self , style_name : Carto | str = Carto .DARK_ALL ):
112
- self ._model = BasemapLayer .carto (style_name )
121
+ def __init__ (
122
+ self , style_name : Carto | str = Carto .DARK_ALL , double_resolution : bool = True
123
+ ):
124
+ style = CartoRasterStyle (style = style_name , double_resolution = double_resolution )
125
+ self ._model = TileLayer (
126
+ id = f"carto-{ Carto (style_name ).value .replace ('_' , '-' ).replace ('/' , '-' )} " ,
127
+ source = ImageTileSource (url = style .url , attributions = style .attribution ),
128
+ )
129
+
130
+ @property
131
+ def model (self ) -> TileLayer :
132
+ return self ._model
133
+
134
+
135
+ class MapTiler (Enum ):
136
+ BASIC_V2 = "basic-v2"
137
+ STREETS_V2 = "streets-v2"
138
+ HYBRID = "hybrid"
139
+ DATAVIZ_DARK = "dataviz-dark"
140
+
141
+ AQUARELLE = "aquarelle"
142
+ BACKDROP = "backdrop"
143
+ BASIC = "basic"
144
+ BRIGHT = "bright"
145
+ DATAVIZ = "dataviz"
146
+ LANDSCAPE = "landscape"
147
+ OCEAN = "ocean"
148
+ OPEN_STREET_MAP = "openstreetmap"
149
+ OUTDOOR = "outdoor"
150
+ SATELLITE = "satellite"
151
+ STREETS = "streets"
152
+ TONER = "toner"
153
+ TOPO = "topo"
154
+ WINTER = "winter"
155
+
156
+
157
+ class MapTilerValidator (BaseModel ):
158
+ api_key : str = Field (os .getenv (MAPTILER_API_KEY_ENV_VAR ), validate_default = True )
159
+
160
+
161
+ class MapTilerBasemapLayer (LayerLike ):
162
+ def __init__ (
163
+ self ,
164
+ style_name : MapTiler | str = MapTiler .STREETS_V2 ,
165
+ api_key : str = os .getenv (MAPTILER_API_KEY_ENV_VAR ),
166
+ ) -> None :
167
+ style = (
168
+ MapTiler (style_name ).value
169
+ if isinstance (style_name , MapTiler )
170
+ else style_name
171
+ )
172
+ key = MapTilerValidator (api_key = api_key ).api_key
173
+ url = f"https://api.maptiler.com/maps/{ style } /tiles.json?key={ key } "
174
+ self ._model = TileLayer (
175
+ id = f"maptiler-{ style } " ,
176
+ source = TileJSONSource (url = url , tile_size = 512 , cross_origin = "anonymous" ),
177
+ )
113
178
114
179
@property
115
180
def model (self ) -> TileLayer :
0 commit comments