I would like to inject Leaflet plugin into Python folium map.
After applying the following code:
map.get_root().header.add_child(folium.CssLink("https://pasichnykvasyl.github.io/Leaflet.BigImage/src/Leaflet.BigImage.css"))
map.get_root().html.add_child(folium.JavascriptLink("https://pasichnykvasyl.github.io/Leaflet.BigImage/src/Leaflet.BigImage.js"))
png_js = '''
L.control.bigImage({position: 'topleft'}).addTo{map};
'''.replace("{map}", mapJsVar)
map.get_root().script.add_child(Element(png_js))
I can't see the plugin anywhere on my map.
Despite the demo version, which programmatically looks exactly the same
https://pasichnykvasyl.github.io/Leaflet.BigImage/
My console says nothing.
Where did I make mistake then?
Best Answer
In
png_js
, change.addTo{map}
to.addTo({map})
and wrap JS code in$(document).ready(function(){ ... });
Code:
When using the plugin, you probably get CORS policy error displayed on console, which is an off-topic issue unrelated to the question: