11
11
from .models .sources import OSM , ImageTileSource , TileJSONSource
12
12
from .constants import MAPTILER_API_KEY_ENV_VAR
13
13
14
+ # --- OSM
15
+
16
+
17
+ class BasemapLayer (LayerLike ):
18
+ """An OSM raster tile layer"""
19
+
20
+ def __init__ (self ) -> None :
21
+ self ._model = TileLayer (id = "osm" , source = OSM ())
22
+
23
+ @property
24
+ def model (self ) -> TileLayer :
25
+ return self ._model
26
+
27
+
28
+ """
29
+ new OGCMapTile({
30
+ url: 'https://maps.gnosis.earth/ogcapi/collections/NaturalEarth:raster:HYP_HR_SR_OB_DR/map/tiles/WebMercatorQuad',
31
+ crossOrigin: '',
32
+ }),
33
+ """
34
+
35
+ # --- CartoDB
36
+
14
37
# light_all,
15
38
# dark_all,
16
39
# light_nolabels,
@@ -58,66 +81,9 @@ def url(self) -> str:
58
81
)
59
82
60
83
61
- class BasemapLayer (LayerLike ):
62
- def __init__ (self , style : str | Carto = None ) -> None :
63
- if isinstance (style , Carto ):
64
- self ._model = BasemapLayer .carto (style )
65
- else :
66
- self ._model = BasemapLayer .osm ()
67
-
68
- @property
69
- def model (self ) -> TileLayer :
70
- return self ._model
71
-
72
- @staticmethod
73
- def osm () -> TileLayer :
74
- """Create a OSM tile layer object
75
-
76
- Returns:
77
- An OSM raster tile layer
78
-
79
- Examples:
80
- >>> from openlayers.basemaps import BasemapLayer
81
- >>> osm = BasemapLayer.osm()
82
- """
83
- return TileLayer (id = "osm" , source = OSM ())
84
-
85
- @staticmethod
86
- def carto (
87
- style_name : str | Carto = Carto .DARK_ALL , double_resolution : bool = True
88
- ) -> TileLayer :
89
- """Create a CartoDB tile layer object
90
-
91
- Note:
92
- See [CartoDB/basemap-styles](https://github.com/CartoDB/basemap-styles) for available styles.
93
-
94
- Args:
95
- style_name (str | Carto): The name of the style
96
- double_resolution (bool): Whether to use double resolution tiles
97
-
98
- Returns:
99
- A CartoDB raster tile layer
100
-
101
- Examples:
102
- >>> from openlayers.basemaps import BasemapLayer
103
- >>> carto = BasemapLayer.carto()
104
- """
105
- style = CartoRasterStyle (style = style_name , double_resolution = double_resolution )
106
- return TileLayer (
107
- id = f"carto-{ Carto (style_name ).value .replace ('_' , '-' ).replace ('/' , '-' )} " ,
108
- source = ImageTileSource (url = style .url , attributions = style .attribution ),
109
- )
110
-
111
-
112
- """
113
- new OGCMapTile({
114
- url: 'https://maps.gnosis.earth/ogcapi/collections/NaturalEarth:raster:HYP_HR_SR_OB_DR/map/tiles/WebMercatorQuad',
115
- crossOrigin: '',
116
- }),
117
- """
84
+ class CartoBasemapLayer (BasemapLayer ):
85
+ """A CartoDB raster tile layer"""
118
86
119
-
120
- class CartoBasemapLayer (LayerLike ):
121
87
def __init__ (
122
88
self , style_name : Carto | str = Carto .DARK_ALL , double_resolution : bool = True
123
89
):
@@ -127,12 +93,13 @@ def __init__(
127
93
source = ImageTileSource (url = style .url , attributions = style .attribution ),
128
94
)
129
95
130
- @property
131
- def model (self ) -> TileLayer :
132
- return self ._model
96
+
97
+ # --- MapTiler
133
98
134
99
135
100
class MapTiler (Enum ):
101
+ """MapTiler basemap styles"""
102
+
136
103
BASIC_V2 = "basic-v2"
137
104
STREETS_V2 = "streets-v2"
138
105
HYBRID = "hybrid"
@@ -158,7 +125,9 @@ class MapTilerValidator(BaseModel):
158
125
api_key : str = Field (os .getenv (MAPTILER_API_KEY_ENV_VAR ), validate_default = True )
159
126
160
127
161
- class MapTilerBasemapLayer (LayerLike ):
128
+ class MapTilerBasemapLayer (BasemapLayer ):
129
+ """A MapTiler raster tile layer"""
130
+
162
131
def __init__ (
163
132
self ,
164
133
style_name : MapTiler | str = MapTiler .STREETS_V2 ,
@@ -175,7 +144,3 @@ def __init__(
175
144
id = f"maptiler-{ style } " ,
176
145
source = TileJSONSource (url = url , tile_size = 512 , cross_origin = "anonymous" ),
177
146
)
178
-
179
- @property
180
- def model (self ) -> TileLayer :
181
- return self ._model
0 commit comments