When one clicks on a Map that contains a ClickForMarker, a Marker is created at the pointer's position. Parameters ---------- popup: str or IFrame or Html, default None Text to display in the markers' popups. This can also be an Element like IFrame or Html.
| 1801 | |
| 1802 | |
| 1803 | class ClickForMarker(MacroElement): |
| 1804 | """ |
| 1805 | When one clicks on a Map that contains a ClickForMarker, |
| 1806 | a Marker is created at the pointer's position. |
| 1807 | |
| 1808 | Parameters |
| 1809 | ---------- |
| 1810 | popup: str or IFrame or Html, default None |
| 1811 | Text to display in the markers' popups. |
| 1812 | This can also be an Element like IFrame or Html. |
| 1813 | If None, the popups will display the marker's latitude and longitude. |
| 1814 | You can include the latitude and longitude with ${lat} and ${lng}. |
| 1815 | |
| 1816 | |
| 1817 | Examples |
| 1818 | -------- |
| 1819 | >>> ClickForMarker("<b>Lat:</b> ${lat}<br /><b>Lon:</b> ${lng}") |
| 1820 | |
| 1821 | """ |
| 1822 | |
| 1823 | _template = Template( |
| 1824 | """ |
| 1825 | {% macro script(this, kwargs) %} |
| 1826 | function newMarker(e){ |
| 1827 | var new_mark = L.marker().setLatLng(e.latlng).addTo({{this._parent.get_name()}}); |
| 1828 | new_mark.dragging.enable(); |
| 1829 | new_mark.on('dblclick', function(e){ {{this._parent.get_name()}}.removeLayer(e.target)}) |
| 1830 | var lat = e.latlng.lat.toFixed(4), |
| 1831 | lng = e.latlng.lng.toFixed(4); |
| 1832 | new_mark.bindPopup({{ this.popup }}); |
| 1833 | }; |
| 1834 | {{this._parent.get_name()}}.on('click', newMarker); |
| 1835 | {% endmacro %} |
| 1836 | """ |
| 1837 | ) # noqa |
| 1838 | |
| 1839 | def __init__(self, popup: Union[IFrame, Html, str, None] = None): |
| 1840 | super().__init__() |
| 1841 | self._name = "ClickForMarker" |
| 1842 | |
| 1843 | if isinstance(popup, Element): |
| 1844 | popup = popup.render() |
| 1845 | if popup: |
| 1846 | self.popup = "`" + escape_backticks(popup) + "`" # type: ignore |
| 1847 | else: |
| 1848 | self.popup = '"Latitude: " + lat + "<br>Longitude: " + lng ' |
| 1849 | |
| 1850 | |
| 1851 | class ClickForLatLng(MacroElement): |
searching dependent graphs…