Create a simple stock Leaflet marker on the map, with optional popup text or Vincent visualization. Parameters ---------- location: tuple or list Latitude and Longitude of Marker (Northing, Easting) popup: string or folium.Popup, default None Label for the M
| 374 | |
| 375 | |
| 376 | class Marker(MacroElement): |
| 377 | """ |
| 378 | Create a simple stock Leaflet marker on the map, with optional |
| 379 | popup text or Vincent visualization. |
| 380 | |
| 381 | Parameters |
| 382 | ---------- |
| 383 | location: tuple or list |
| 384 | Latitude and Longitude of Marker (Northing, Easting) |
| 385 | popup: string or folium.Popup, default None |
| 386 | Label for the Marker; either an escaped HTML string to initialize |
| 387 | folium.Popup or a folium.Popup instance. |
| 388 | tooltip: str or folium.Tooltip, default None |
| 389 | Display a text when hovering over the object. |
| 390 | icon: Icon, CustomIcon or DivIcon, optional |
| 391 | the Icon plugin to use to render the marker. |
| 392 | draggable: bool, default False |
| 393 | Set to True to be able to drag the marker around the map. |
| 394 | |
| 395 | Returns |
| 396 | ------- |
| 397 | Marker names and HTML in obj.template_vars |
| 398 | |
| 399 | Examples |
| 400 | -------- |
| 401 | >>> Marker(location=[45.5, -122.3], popup="Portland, OR") |
| 402 | >>> Marker(location=[45.5, -122.3], popup=Popup("Portland, OR")) |
| 403 | # If the popup label has characters that need to be escaped in HTML |
| 404 | >>> Marker( |
| 405 | ... location=[45.5, -122.3], |
| 406 | ... popup=Popup("Mom & Pop Arrow Shop >>", parse_html=True), |
| 407 | ... ) |
| 408 | """ |
| 409 | |
| 410 | _template = Template( |
| 411 | """ |
| 412 | {% macro script(this, kwargs) %} |
| 413 | var {{ this.get_name() }} = L.marker( |
| 414 | {{ this.location|tojson }}, |
| 415 | {{ this.options|tojavascript }} |
| 416 | ).addTo({{ this._parent.get_name() }}); |
| 417 | {% endmacro %} |
| 418 | """ |
| 419 | ) |
| 420 | |
| 421 | class SetIcon(MacroElement): |
| 422 | """Set the icon of a marker after both are created.""" |
| 423 | |
| 424 | _template = Template( |
| 425 | """ |
| 426 | {% macro script(this, kwargs) %} |
| 427 | {{ this.marker.get_name() }}.setIcon({{ this.icon.get_name() }}); |
| 428 | {% endmacro %} |
| 429 | """ |
| 430 | ) |
| 431 | |
| 432 | def __init__( |
| 433 | self, marker: "Marker", icon: Union[Icon, "CustomIcon", "DivIcon"] |