Map

class visigoth.containers.map.Map(width, boundaries=None, projection=<visigoth.utils.mapping.projections.PROJ_ESPG_3857 object>, font_height=10, text_attributes={}, width_to_height=None, zoom_to=1, panzoom_radius=40, fill='white')

Overlay multiple layers to create a map

Parameters:

width (int) – width of the map in pixels

Keyword Arguments:
 
  • boundaries (tuple) – tuple containing (min-lon,min-lat) and (max-lon,max-lat) pairs
  • projection (object) – the projection system to use
  • font_height (int) – font size in pixels
  • text_attributes (dict) – a dict containing SVG name/value attributes
  • width_to_height (float) – if specified, sets the width to height ratio of the map
  • zoom_to (int) – specify how much magnification can be selected - must be a power of 2
  • panzoom_radius (int) – specify redius in pixels for the pan/zoom control
  • fill (str) – specify a background colour
addLayer(layer_element)

Add a layer to the map

Parameters:element (DiagramElement) – the element to place into the overlay

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, Box
from visigoth.utils.mapping import Projections, Geocoder, Mapping
from visigoth.map_layers import Scatter, WMS
from visigoth.common import Text

d = Diagram()

gc = Geocoder()
center = gc.fetchCenter("Berlin")
bounds = Mapping.computeBoundaries(center,10000,projection=Projections.ESPG_3857)

m = Map(400,boundaries=bounds,zoom_to=5,projection=Projections.ESPG_3857)

s = Scatter([center])
s.getMarkerManager().setDefaultRadius(20).setMarkerType("pin")
s.getPalette().setDefaultColour("darkred")
wms = WMS(type="osm")
wms.setInfo("Map")

m.addLayer(wms)
m.addLayer(s)
d.add(Text("Berlin Stadtmitte"))
d.add(Box(m))

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