Skip to content

Commit 463b282

Browse files
committed
Style
1 parent ff76337 commit 463b282

File tree

8 files changed

+29
-30
lines changed

8 files changed

+29
-30
lines changed

src/openlayers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from .controls import *
1111
from .layers import *
1212
from .map import Map
13-
from .view import View
1413
from .styles import FlatStyle
14+
from .view import View
1515

1616
__version__ = importlib.metadata.version(__package__)
1717

src/openlayers/abstracts.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

33
from abc import ABC, abstractmethod
4+
45
from pydantic import BaseModel
56

7+
68
class LayerLike(ABC):
79
@property
810
@abstractmethod
@@ -15,19 +17,3 @@ def to_dict(self) -> dict:
1517

1618
def model_dump(self) -> dict:
1719
return super().model_dump(exclude_none=True, by_alias=True)
18-
19-
20-
# TODO: check if this class is still needed
21-
"""
22-
class BaseType(BaseModel):
23-
model_config = ConfigDict(extra="allow")
24-
25-
def model_dump(self) -> dict:
26-
return dict(
27-
type=self.type, options=super().model_dump(exclude_none=True, by_alias=True)
28-
)
29-
30-
@property
31-
def type(self) -> str:
32-
return type(self).__name__
33-
"""

src/openlayers/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import json
44
import os
55
import random
6+
from typing import Any
67

78
from pydantic import BaseModel
8-
from typing import Any
99

1010
COLOR_SCHEMES = "https://raw.githubusercontent.com/python-visualization/branca/refs/heads/main/branca/_schemes.json"
1111

src/openlayers/geopandas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING, Self
4+
35
import geopandas as gpd
46
import pandas as pd
57

6-
from typing import Self, TYPE_CHECKING
7-
88
from .anywidget import MapWidget
9+
from .colors import Color
910
from .models.layers import VectorLayer, WebGLVectorLayer
1011
from .models.sources import VectorSource
1112
from .models.view import Projection
1213
from .styles import FlatStyle, default_style
13-
from .colors import Color
1414

1515
if TYPE_CHECKING:
1616
from .models.controls import ControlT

src/openlayers/map.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from pathlib import Path
55
from typing import Any
66

7+
from .abstracts import LayerLike
78
from .export import HTMLTemplate, write_file
89
from .models.controls import ControlT
910
from .models.layers import LayerT, TileLayer
1011
from .models.map_options import MapOptions
1112
from .models.sources import OSM
1213
from .models.view import View
1314
from .styles import FlatStyle
14-
from .abstracts import LayerLike
1515

1616

1717
class Map(object):
@@ -26,10 +26,10 @@ def __init__(
2626
if layers is None:
2727
layers = [TileLayer(id="osm", source=OSM())]
2828

29-
#layers = [
29+
# layers = [
3030
# layer.model_dump() if isinstance(layer, LayerLike) else layer
3131
# for layer in layers
32-
#]
32+
# ]
3333
self.map_options = MapOptions(
3434
view=view, layers=layers, controls=controls
3535
).model_dump()

src/openlayers/models/controls.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Literal, Union
44
from uuid import uuid4
55

6-
from pydantic import Field
6+
from pydantic import Field, field_validator
77

88
from .core import OLBaseModel
99
from .layers import LayerT, TileLayer
@@ -12,7 +12,14 @@
1212

1313
# -- Base control
1414
class Control(OLBaseModel):
15-
id: str = Field(default_factory=lambda x: str(uuid4()))
15+
id: str | None = None # = Field(default_factory=lambda x: str(uuid4()))
16+
17+
@field_validator("id")
18+
def validate_id(cls, v) -> str:
19+
if v is None:
20+
return uuid4().hex[0:10]
21+
22+
return v
1623

1724

1825
# --- Controls

src/openlayers/models/map_options.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
from __future__ import annotations
22

3-
from pydantic import BaseModel, field_validator, ConfigDict
3+
from pydantic import BaseModel, ConfigDict, field_validator
44

5+
from ..abstracts import LayerLike
56
from .controls import ControlT
67
from .layers import LayerT
78
from .view import View
8-
from ..abstracts import LayerLike
9+
910

1011
class MapOptions(BaseModel):
11-
model_config = ConfigDict(arbitrary_types_allowed=True) # Needed to support 'LayerLike'
12+
model_config = ConfigDict(
13+
arbitrary_types_allowed=True
14+
) # Needed to support 'LayerLike'
1215

1316
view: View | None = View()
1417
controls: list[dict | ControlT] | None = None
1518
layers: list[dict | LayerT | LayerLike] | None = None
1619

1720
@field_validator("layers")
1821
def validate_layers(cls, layers) -> list[dict | LayerT]:
19-
layers = [layer.model if isinstance(layer, LayerLike) else layer for layer in layers]
22+
layers = [
23+
layer.model if isinstance(layer, LayerLike) else layer for layer in layers
24+
]
2025
return layers
2126

2227
def model_dump(self) -> dict:

src/openlayers/styles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def model_dump(self) -> dict:
3232
def model_dump2(self) -> dict:
3333
return super().model_dump(exclude_none=True)
3434

35+
3536
def default_style() -> FlatStyle:
3637
return FlatStyle(
3738
fill_color="rgba(255,255,255,0.4)",

0 commit comments

Comments
 (0)