11Polygon/Multipolygon
22====================
33
4- Example Polygon
5- ---------------
4+ Polygon
5+ -------
6+
7+ You can easily create a ``Polygon `` providing the list of vertex locations (in lat/lng).
68
79.. jupyter-execute ::
810
@@ -19,62 +21,95 @@ Example Polygon
1921
2022 m
2123
24+ Because the ``Polygon `` an interactive widget, you can dynamically update the locations/color from Python, and you will see updated on the ``Map ``.
2225
23- Example Polygon with hole
24- -------------------------
26+ Polygon with holes
27+ ------------------
2528
26- .. jupyter-execute ::
29+ You can define holes in your `` Polygon `` by using nested lists of vertex locations.
2730
28- from ipyleaflet import Map, Polygon
31+ .. jupyter-execute ::
2932
30- hole_polygon = Polygon(
31- locations= [[(37, -109.05),(41, -109.03),(41, -102.05),(37, -102.04)],
32- [(37.29, -108.58),(40.71, -108.58),(40.71, -102.50),(37.29, -102.50)]],
33+ from ipyleaflet import Map, Polygon
3334
34- color="green",
35- fill_color="green"
36- )
35+ polygon = Polygon(
36+ locations= [
37+ [(37, -109.05), (41, -109.03), (41, -102.05), (37, -102.04)],
38+ [(37.29, -108.58), (40.71, -108.58), (40.71, -102.50), (37.29, -102.50)]
39+ ],
40+ color="green",
41+ fill_color="green"
42+ )
3743
38- m = Map(center=(37.5531, -109.6914), zoom=5)
39- m.add_layer(hole_polygon );
44+ m = Map(center=(37.5531, -109.6914), zoom=5)
45+ m.add_layer(polygon );
4046
41- m
47+ m
4248
4349
44- Example Multipolygon
45- --------------------
50+ MultiPolygon
51+ ------------
4652
4753.. jupyter-execute ::
4854
4955 from ipyleaflet import Map, Polygon
5056
5157 multipolygon = Polygon(
52- locations=[[(42, -49), (43, -49), (43, -48)],[(44,-49),(43, -50),(44,-50)]],
53- color="green",
54- fill_color="green"
55- )
58+ locations=[
59+ [(42, -49), (43, -49), (43, -48)],
60+ [(44,-49), (43, -50), (44,-50)]
61+ ],
62+ color="green",
63+ fill_color="green"
64+ )
5665
5766 m = Map(center=(42.5531, -48.6914), zoom=6)
5867 m.add_layer(multipolygon);
5968
6069 m
6170
6271
72+ Editable Polygon
73+ ----------------
74+
75+ If ``transform `` is set to ``True ``, you can dynamically edit the polygon with the mouse.
76+
77+ .. jupyter-execute ::
78+
79+ from ipyleaflet import Map, Polygon
80+
81+ polygon = Polygon(
82+ locations=[(42, -49), (43, -49), (43, -48)],
83+ color="green",
84+ fill_color="green",
85+ transform=True
86+ )
87+
88+ m = Map(center=(42.5531, -48.6914), zoom=6)
89+ m.add_layer(polygon);
90+
91+ m
92+
93+
6394Attributes
6495----------
6596
66- ============= ================ ===
97+ =============== ================ ===
6798Attribute Default Value Doc
68- ============= ================ ===
99+ =============== ================ ===
69100locations [] List of points of the polygon
70101stroke True Set it to `False ` to disable borders
71102color "#0033FF" Stroke color
72103opacity 1.0 Stroke opacity
73104weight 5 Stroke width in pixels
74105fill True Whether to fill the polygon or not
75- fill_color None
106+ fill_color None If None, it will be the same as the color value
76107fill_opacity 0.2
77108dash_array
78109line_cap "round"
79110line_join "round"
80- ============= ================ ===
111+ transform False Whether the polygon is editable with the mouse or not
112+ scaling True Whether the polygon scale is editable or not, needs transform set to ``True ``
113+ rotation True Whether the polygon rotation is editable or not, needs transform set to ``True ``
114+ uniform_scaling False Whether to keep the scale ratio when editing the scale, needs transform set to ``True ``
115+ =============== ================ ===
0 commit comments