streamlit / js.py
SUNGJIN LEE
Initial commit
312b9eb
from folium.map import Marker
from jinja2 import Template
def set_marker_click_template():
click_marker = """
{% macro script(this, kwargs) %}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(function() {
console.log("ν΄λ¦½λ³΄λ“œμ— λ³΅μ‚¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€: ", text);
}, function(err) {
console.error("ν΄λ¦½λ³΄λ“œ 볡사에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€: ", err);
});
}
function showToast() {
var toast = document.getElementById("toast");
toast.style.visibility = "visible";
setTimeout(function() {
toast.style.visibility = "hidden";
}, 3000);
}
function onClick(e) {
var marker = e.target;
if (marker.getTooltip()) {
var cellID = marker.getTooltip().getElement().innerText.trim();
copyToClipboard(cellID);
}
}
var {{ this.get_name() }} = L.marker(
{{ this.location|tojson }},
{{ this.options|tojson }}
).addTo({{ this._parent.get_name() }}).on('click', onClick);
{% endmacro %}
"""
Marker._template = Template(click_marker)