When one clicks on a Map that contains a ClickForLatLng, the coordinates of the pointer's position are copied to clipboard. Parameters ========== format_str : str, default 'lat + "," + lng' The javascript string used to format the text copied to clipboard. eg:
| 1849 | |
| 1850 | |
| 1851 | class ClickForLatLng(MacroElement): |
| 1852 | """ |
| 1853 | When one clicks on a Map that contains a ClickForLatLng, |
| 1854 | the coordinates of the pointer's position are copied to clipboard. |
| 1855 | |
| 1856 | Parameters |
| 1857 | ========== |
| 1858 | format_str : str, default 'lat + "," + lng' |
| 1859 | The javascript string used to format the text copied to clipboard. |
| 1860 | eg: |
| 1861 | format_str = 'lat + "," + lng' >> 46.558860,3.397397 |
| 1862 | format_str = '"[" + lat + "," + lng + "]"' >> [46.558860,3.397397] |
| 1863 | alert : bool, default True |
| 1864 | Whether there should be an alert when something has been copied to clipboard. |
| 1865 | """ |
| 1866 | |
| 1867 | _template = Template( |
| 1868 | """ |
| 1869 | {% macro script(this, kwargs) %} |
| 1870 | function getLatLng(e){ |
| 1871 | var lat = e.latlng.lat.toFixed(6), |
| 1872 | lng = e.latlng.lng.toFixed(6); |
| 1873 | var txt = {{this.format_str}}; |
| 1874 | navigator.clipboard.writeText(txt); |
| 1875 | {% if this.alert %}alert("Copied to clipboard : \\n " + txt);{% endif %} |
| 1876 | }; |
| 1877 | {{this._parent.get_name()}}.on('click', getLatLng); |
| 1878 | {% endmacro %} |
| 1879 | """ |
| 1880 | ) # noqa |
| 1881 | |
| 1882 | def __init__(self, format_str: Optional[str] = None, alert: bool = True): |
| 1883 | super().__init__() |
| 1884 | self._name = "ClickForLatLng" |
| 1885 | self.format_str = format_str or 'lat + "," + lng' |
| 1886 | self.alert = alert |
| 1887 | |
| 1888 | |
| 1889 | class CustomIcon(Icon): |
nothing calls this directly
no test coverage detected
searching dependent graphs…