Skip to content

Instantly share code, notes, and snippets.

@Gordonei
Last active March 27, 2019 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gordonei/79b20cc3c6ccc5258888be17088c4178 to your computer and use it in GitHub Desktop.
Save Gordonei/79b20cc3c6ccc5258888be17088c4178 to your computer and use it in GitHub Desktop.
Similar to https://github.com/python-visualization/folium/blob/master/folium/plugins/float_image.py , but more generic. Seemed odd that such a thing didn't already exist.
import branca
import jinja2
class FloatDiv(branca.element.MacroElement):
"""Adds a floating div in HTML canvas on top of the map."""
_template = jinja2.Template("""
{% macro header(this,kwargs) %}
<style>
#{{this.get_name()}} {
position:absolute;
top:{{this.top}}%;
left:{{this.left}}%;
}
</style>
{% endmacro %}
{% macro html(this,kwargs) %}
<div id="{{this.get_name()}}" alt="float_div" style="z-index: 999999">
{{this.content}}
</div
{% endmacro %}
""")
def __init__(self, content, top=10, left=0):
super(FloatDiv, self).__init__()
self._name = 'FloatDiv'
self.content = content
self.top = top
self.left = left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment