Skip to content

Commit 403f725

Browse files
author
Stefan Kuethe
committed
Update docs
1 parent 5cbdaaa commit 403f725

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

docs/api/styles.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
::: openlayers.styles.FlatStyle
44

5+
::: openlayers.styles.default_style

docs/concepts/layers.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,25 @@ Sources state which data the map should display.
2424
2525
## Styles
2626

27-
...
27+
Vector layers can be styled with a style object containing properties for _stroke_, _fill_, etc.:
28+
29+
```python
30+
style = ol.FlatStyle(
31+
stroke_color = "yellow",
32+
stroke_width = 1.5,
33+
fill_color = "orange"
34+
)
35+
```
36+
37+
It is also possible to use a simple dictonary instead. In this case property names must use hyphens instead
38+
of underscores:
39+
40+
```python
41+
const style = {
42+
"stroke-color": "yellow",
43+
"stroke-width": 1.5,
44+
"fill-color": "orange",
45+
}
46+
```
47+
48+
> See [Styles API](../../api/styles/) and [ol/style/flat](https://openlayers.org/en/latest/apidoc/module-ol_style_flat.html) for details.

examples/standalone/layers/vector_image_layer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# See https://openlayers.org/en/latest/examples/image-vector-layer.html
22

33
import openlayers as ol
4-
# from openlayers.models.layers import VectorImageLayer
54

65
data = "https://openlayers.org/data/vector/ecoregions.json"
76

src/openlayers/styles.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ def fix_keys(d: dict) -> dict:
1515
# TODO: Move to models folder
1616
# See https://openlayers.org/en/latest/apidoc/module-ol_style_flat.html
1717
class FlatStyle(BaseModel):
18-
"""Flat style
18+
"""A style object for vector layers
19+
20+
Underscores in the property names are automatically converted to hyphens.
1921
2022
Note:
21-
See [ol-apidoc/module-ol_style_flat](https://openlayers.org/en/latest/apidoc/module-ol_style_flat.html)
22-
for all available style parameters.
23+
See [ol/style/flat](https://openlayers.org/en/latest/apidoc/module-ol_style_flat.html)
24+
for all available style properties.
2325
"""
2426

2527
model_config = ConfigDict(extra="allow")
@@ -54,6 +56,15 @@ def model_dump2(self) -> dict:
5456

5557

5658
def default_style(**kwargs) -> FlatStyle:
59+
"""Create a default style object for vector layers
60+
61+
Args:
62+
**kwargs (Any): Additional style properties or
63+
updates of the default properties
64+
65+
Returns:
66+
A style object
67+
"""
5768
return FlatStyle(
5869
fill_color="rgba(255,255,255,0.4)",
5970
# ---
@@ -65,16 +76,3 @@ def default_style(**kwargs) -> FlatStyle:
6576
circle_stroke_width=1.25,
6677
circle_stroke_color="#3399CC",
6778
).model_copy(update=kwargs)
68-
69-
70-
# class CircleStyle(FlatStyle): ...
71-
72-
"""
73-
class IconStyle(FlatStyle):
74-
icon_src: str | None = None
75-
icon_color: str | None = None
76-
icon_opacity: float | int | None = None
77-
icon_scale: float | int | None = None
78-
"""
79-
80-
# class FillStyle(FlatStyle): ...

0 commit comments

Comments
 (0)