Popup

class visigoth.containers.popup.Popup(element, title='', stroke_width=2, stroke='grey', fill='white', popup_group_id=None, opacity=1.0, corner_radius=4, font_height=18, text_attributes={}, opened=False)

Wrap an element within a closable popup box

Parameters:
  • element (DiagramElement) – element to wrap
  • title (str) – title for the popup
Keyword Arguments:
 
  • stroke_width (int) – width of the border in pixels
  • stroke (str) – colour of the border
  • fill (str) – fill colour for the box
  • popup_group_id (str) – (optional) id of an enclosing svg <g> element
  • opacity (float) – set the opacity of the popup, in range 0.0 (transparent) to 1.0 (opaque)
  • corner_radius (float) – radius of the popup corners in pixels
  • font_height (int) – font size in pixels
  • text_attributes (dict) – a dict containing SVG name/value attributes
  • opened (boolean) – True iff the popup should be initially open

Example

(Link to open example in new tab):

Source Code (Link to Github):

# -*- coding: utf-8 -*-

from visigoth import Diagram
from visigoth.containers import Map, Popup
from visigoth.utils.mapping import Geocoder, Mapping, Projections
from visigoth.map_layers import WMS, Geoplot
from visigoth.map_layers.geoplot import Multipoint
from visigoth.common import Space

d = Diagram()

gc = Geocoder()

center = gc.fetchCenter("New York")
bounds = Mapping.computeBoundaries(center,200000,projection=Projections.ESPG_3857)

timesq = gc.fetchCenter("Times Square, New York")
timesq_bounds = Mapping.computeBoundaries(timesq,500,projection=Projections.ESPG_3857)

timesq_m = Map(256,boundaries=timesq_bounds,projection=Projections.ESPG_3857,font_height=5)
timesq_wms = WMS(type="osm")
timesq_m.addLayer(timesq_wms)
timesq_popup = Popup(timesq_m,"Times Square",fill="white")

m = Map(512,boundaries=bounds,projection=Projections.ESPG_3857,zoom_to=2)

wms = WMS(type="osm")
wms.setInfo("Map")

gp = Geoplot(multipoints=[Multipoint([timesq],label="Times Square",popup=timesq_popup)])

m.addLayer(wms)
m.addLayer(gp)
d.add(Space(100))
d.add(m)

html = d.draw(format="html")

f = open("example.html", "w")
f.write(html)
f.close()