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

  • 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

Screenshot (Link to open SVG for interactive features):

../_images/example16.png

Source Code (Link to Github):


import os
import sys
import argparse

from visigoth import Diagram

from visigoth.containers.map import Map
from visigoth.utils.mapping import Metadata, Geocoder, Mapping
from visigoth.map_layers.scatter import Scatter
from visigoth.map_layers.gridsquares import GridSquares
from visigoth.map_layers.wms import WMS
from visigoth.containers.box import Box
from visigoth.common.text import Text


from visigoth.utils.mapping import Projections

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    folder=os.path.split(__file__)[0]

    d = Diagram(fill="white")

    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],radius=20,fill="#00FF0080",marker=True)
    wms = WMS(type="osm")
    wms.setInfo("Map")

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

    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()