gws.tools.svg

gws.tools.svg.geometry_tags(geom: shapely.geometry.base.BaseGeometry, rv: gws.types.MapRenderView, sv: gws.types.StyleValues, label: str) → List[tuple][source]
gws.tools.svg.sort_by_z_index(tags: List[tuple])[source]
gws.tools.svg.as_xml(tags: List[tuple]) → str[source]
gws.tools.svg.as_png(tags: List[tuple], size: Tuple[float, float]) → bytes[source]
gws.tools.svg.fragment_tags(fragment: gws.types.SvgFragment, rv: gws.types.MapRenderView) → List[tuple][source]

Convert an SvgFragment to a list of Tags.

A fragment has three components:

  • a list of xml2.Tags (which are just tuples)

  • a list of points, in the map coordinate system

  • a list of named styles

The idea is to represent client-side svg drawings (e.g. dimensions) in a resolution-independent way

The fragment is converted as follows:

  • points are converted to pixels

  • tags’ attributes are iterated. If any attribute value is an array, it’s assumed to be a ‘function’

  • ‘class’ attributes are replaced with inline styles from the .styles list

Attribute ‘functions’ are

  • ‘’ (empty function), [‘’, index, component] - returns pixels[index][component],

    where component is 0 for x, 1 for y

  • ‘rotate’ [‘rotate’, index1, index2, index3] - computes a slope between pixels[index1] and pixels[index2]

    and returns a string rotate(slope, pixels[index3]).