|
| 1 | +from enum import Enum |
| 2 | +from typing import Optional, List |
| 3 | + |
| 4 | +from pydantic import BaseModel, validator |
| 5 | + |
| 6 | +from .geometry import Point |
| 7 | + |
| 8 | + |
| 9 | +class EPSG(Enum): |
| 10 | + """ Provides the EPSG for tiled image assets that are currently supported. |
| 11 | + |
| 12 | + SIMPLEPIXEL is Simple that can be used to obtain the pixel space coordinates |
| 13 | +
|
| 14 | + >>> epsg = EPSG() |
| 15 | + """ |
| 16 | + SIMPLEPIXEL = 1 |
| 17 | + EPSG4326 = 2 |
| 18 | + EPSG3857 = 3 |
| 19 | + EPSG3395 = 4 |
| 20 | + |
| 21 | + |
| 22 | +class TiledBounds(BaseModel): |
| 23 | + """ Bounds for a tiled image asset related to the relevant epsg. |
| 24 | +
|
| 25 | + Each bound is a list of Point objects. |
| 26 | +
|
| 27 | + If version of asset is 2, these should be [[lat,lng],[lat,lng]] |
| 28 | + If version of asset is 1, these should be [[lng,lat]],[lng,lat]] |
| 29 | +
|
| 30 | + >>> bounds = TiledBounds( |
| 31 | + epsg=EPSG.4326, |
| 32 | + bounds=[[0,0],[100,100]] |
| 33 | + ) |
| 34 | + """ |
| 35 | + epsg: EPSG |
| 36 | + bounds: List[List[Point]] |
| 37 | + |
| 38 | + |
| 39 | +class TileLayer(BaseModel): |
| 40 | + """ Url that contains the tile layer. Must be in the format: |
| 41 | +
|
| 42 | + https://c.tile.openstreetmap.org/{z}/{x}/{y}.png |
| 43 | +
|
| 44 | + >>> layer = TileLayer( |
| 45 | + url=https://c.tile.openstreetmap.org/{z}/{x}/{y}.png, |
| 46 | + name="slippy map tile" |
| 47 | + ) |
| 48 | + """ |
| 49 | + url: str |
| 50 | + name: Optional[str] = "default" |
| 51 | + |
| 52 | + def from_dict(): |
| 53 | + pass |
| 54 | + |
| 55 | + def to_dict(): |
| 56 | + pass |
| 57 | + |
| 58 | + @validator('url') |
| 59 | + def validate_url(cls, url): |
| 60 | + xyz_format = "/{z}/{x}/{y}" |
| 61 | + if xyz_format not in url: |
| 62 | + raise AssertionError(f"{self.url} needs to contain {xyz_format}") |
| 63 | + return url |
0 commit comments