@@ -102,6 +102,9 @@ class TileLayer(BaseModel):
102
102
url : str
103
103
name : Optional [str ] = "default"
104
104
105
+ def asdict (self ):
106
+ return {"tileLayerUrl" : self .url , "name" : self .name }
107
+
105
108
@validator ('url' )
106
109
def validate_url (cls , url ):
107
110
xyz_format = "/{z}/{x}/{y}"
@@ -131,13 +134,34 @@ class TiledImageData(BaseData):
131
134
"""
132
135
tile_layer : TileLayer
133
136
tile_bounds : TiledBounds
134
- alternative_layers : List [TileLayer ] = None
137
+ alternative_layers : List [TileLayer ] = []
135
138
zoom_levels : Tuple [int , int ]
136
139
max_native_zoom : Optional [int ] = None
137
140
tile_size : Optional [int ] = DEFAULT_TMS_TILE_SIZE
138
141
version : Optional [int ] = 2
139
142
multithread : bool = True
140
143
144
+ def __post_init__ (self ):
145
+ if self .max_native_zoom is None :
146
+ self .max_native_zoom = self .zoom_levels [0 ]
147
+
148
+ def asdict (self ):
149
+ return {
150
+ "tileLayerUrl" : self .tile_layer .url ,
151
+ "bounds" : [[
152
+ self .tile_bounds .bounds [0 ].x , self .tile_bounds .bounds [0 ].y
153
+ ], [self .tile_bounds .bounds [1 ].x , self .tile_bounds .bounds [1 ].y ]],
154
+ "minZoom" : self .zoom_levels [0 ],
155
+ "maxZoom" : self .zoom_levels [1 ],
156
+ "maxNativeZoom" : self .max_native_zoom ,
157
+ "epsg" : self .tile_bounds .epsg .name ,
158
+ "tileSize" : self .tile_size ,
159
+ "alternativeLayers" : [
160
+ layer .asdict () for layer in self .alternative_layers
161
+ ],
162
+ "version" : self .version
163
+ }
164
+
141
165
def as_raster_data (self ,
142
166
zoom : int = 0 ,
143
167
max_tiles : int = 32 ,
@@ -149,9 +173,24 @@ def as_raster_data(self,
149
173
"""
150
174
if self .tile_bounds .epsg == EPSG .SIMPLEPIXEL :
151
175
xstart , ystart , xend , yend = self ._get_simple_image_params (zoom )
152
-
176
+ elif self .tile_bounds .epsg == EPSG .EPSG4326 :
177
+ xstart , ystart , xend , yend = self ._get_3857_image_params (zoom )
153
178
elif self .tile_bounds .epsg == EPSG .EPSG3857 :
179
+ #transform to 4326
180
+ transformer = EPSGTransformer .create_geo_to_geo_transformer (
181
+ EPSG .EPSG3857 , EPSG .EPSG4326 )
182
+ self .tile_bounds .bounds = [
183
+ transformer (self .tile_bounds .bounds [0 ]),
184
+ transformer (self .tile_bounds .bounds [1 ])
185
+ ]
154
186
xstart , ystart , xend , yend = self ._get_3857_image_params (zoom )
187
+ #transform back to 3857
188
+ transformer = EPSGTransformer .create_geo_to_geo_transformer (
189
+ EPSG .EPSG4326 , EPSG .EPSG3857 )
190
+ self .tile_bounds .bounds = [
191
+ transformer (self .tile_bounds .bounds [0 ]),
192
+ transformer (self .tile_bounds .bounds [1 ])
193
+ ]
155
194
else :
156
195
raise ValueError (f"Unsupported epsg found: { self .tile_bounds .epsg } " )
157
196
@@ -202,8 +241,8 @@ def _get_3857_image_params(self, zoom) -> Tuple[float, float, float, float]:
202
241
1 ].x , self .tile_bounds .bounds [0 ].x
203
242
204
243
# Convert to zoom 0 tile coordinates
205
- xstart , ystart = self ._latlng_to_tile (lat_start , lng_start , zoom )
206
- xend , yend = self ._latlng_to_tile (lat_end , lng_end , zoom )
244
+ xstart , ystart = self ._latlng_to_tile (lat_start , lng_start )
245
+ xend , yend = self ._latlng_to_tile (lat_end , lng_end )
207
246
208
247
# Make sure that the tiles are increasing in order
209
248
xstart , xend = min (xstart , xend ), max (xstart , xend )
0 commit comments