我想扩展我的folium地图的功能
我在这里找到了一个很好的线索:
但是当应用于我的代码时,它不起作用
export_js = [
(
"leaflet_bigimage_js",
"js/Leaflet.BigImage.js",
)
]
export_css = [
(
"leaflet_bigimage_css",
"css/Leaflet.BigImage.css",
)
]
exp = folium.MacroElement()
exp.template = jinja2.Template("""
{% macro script(this, kwargs) %}
L.control.bigImage({position: 'topright'}).addTo{map}
{% endmacro %}
""")
map.get_root().add_child(exp)映射工作,但元素根本没有出现。此外,JS控制台什么也看不见。
有什么办法能解决这个问题吗?
更新:
我也试过:
class exp(MacroElement):
exp_template = Template(u"""
{% macro script(this, kwargs) %}
L.control.bigImage({position: 'topright'}).addTo({{
this._parent.get_name() }})
{% endmacro %}
""")
map.add_child(exp())但结果是一样的
发布于 2022-11-23 16:22:29
如果计算机上有css和js文件,则可以使用branca库,该库与folium一起安装,以包含js和css元素。
import folium
from branca.element import CssLink, JavascriptLink
from pathlib import Path
js_file = Path("/path/to/script.js")
js_link = JavascriptLink(js_file.as_uri())
css_file = Path("/path/to/style.css")
css_link = CssLink(css_file.as_uri())
map = folium.Map()
html = map.get_root()
header = html.header
#Add links
header.add_child(css_link)
header.add_child(js_link)https://stackoverflow.com/questions/74545694
复制相似问题