Draw rectangle overlays on a map. See :func:`folium.vector_layers.path_options` for the `Path` options. Parameters ---------- bounds: [(lat1, lon1), (lat2, lon2)] Two lat lon pairs marking the two corners of the rectangle. popup: string or folium.Popup, default None
| 241 | |
| 242 | |
| 243 | class Rectangle(MacroElement): |
| 244 | """Draw rectangle overlays on a map. |
| 245 | |
| 246 | See :func:`folium.vector_layers.path_options` for the `Path` options. |
| 247 | |
| 248 | Parameters |
| 249 | ---------- |
| 250 | bounds: [(lat1, lon1), (lat2, lon2)] |
| 251 | Two lat lon pairs marking the two corners of the rectangle. |
| 252 | popup: string or folium.Popup, default None |
| 253 | Input text or visualization for object displayed when clicking. |
| 254 | tooltip: str or folium.Tooltip, default None |
| 255 | Display a text when hovering over the object. |
| 256 | **kwargs |
| 257 | Other valid (possibly inherited) options. See: |
| 258 | https://leafletjs.com/reference.html#rectangle |
| 259 | |
| 260 | """ |
| 261 | |
| 262 | _template = Template( |
| 263 | """ |
| 264 | {% macro script(this, kwargs) %} |
| 265 | var {{this.get_name()}} = L.rectangle( |
| 266 | {{ this.locations|tojson }}, |
| 267 | {{ this.options|tojson }} |
| 268 | ).addTo({{this._parent.get_name()}}); |
| 269 | {% endmacro %} |
| 270 | """ |
| 271 | ) |
| 272 | |
| 273 | def __init__( |
| 274 | self, |
| 275 | bounds: TypeLine, |
| 276 | popup: Union[Popup, str, None] = None, |
| 277 | tooltip: Union[Tooltip, str, None] = None, |
| 278 | **kwargs: TypePathOptions, |
| 279 | ): |
| 280 | super().__init__() |
| 281 | self._name = "rectangle" |
| 282 | self.options = path_options(line=True, radius=None, **kwargs) |
| 283 | self.locations = validate_locations(bounds) |
| 284 | assert len(self.locations) == 2, "Need two lat/lon pairs" |
| 285 | if popup is not None: |
| 286 | self.add_child(popup if isinstance(popup, Popup) else Popup(str(popup))) |
| 287 | if tooltip is not None: |
| 288 | self.add_child( |
| 289 | tooltip if isinstance(tooltip, Tooltip) else Tooltip(str(tooltip)) |
| 290 | ) |
| 291 | |
| 292 | def _get_self_bounds(self) -> List[List[Optional[float]]]: |
| 293 | """Compute the bounds of the object itself.""" |
| 294 | return get_bounds(self.locations) |
| 295 | |
| 296 | |
| 297 | class Circle(Marker): |