From 35a1114199bc959479c5ac54da633f911a247208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Fri, 26 May 2017 22:38:46 +0200 Subject: [PATCH] calculate image idimensions from Source dimensions :3 --- src/c3nav/mapdata/models/section.py | 6 +++--- src/c3nav/mapdata/utils/svg.py | 10 ++++++---- src/c3nav/routing/route.py | 2 -- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/c3nav/mapdata/models/section.py b/src/c3nav/mapdata/models/section.py index ed270205..f1a24f92 100644 --- a/src/c3nav/mapdata/models/section.py +++ b/src/c3nav/mapdata/models/section.py @@ -6,7 +6,6 @@ from shapely.ops import cascaded_union from c3nav.mapdata.models.base import EditorFormMixin from c3nav.mapdata.models.locations import SpecificLocation -from c3nav.mapdata.utils.misc import get_dimensions from c3nav.mapdata.utils.svg import SVGImage @@ -64,8 +63,9 @@ class Section(SpecificLocation, EditorFormMixin, models.Model): svg.add_geometry(obstacle_geometries, fill_color='#999999') def render_svg(self, effects=True, draw_spaces=None): - width, height = get_dimensions() - svg = SVGImage(width=width, height=height, scale=settings.RENDER_SCALE) + from c3nav.mapdata.models import Source + bounds = Source.max_bounds() + svg = SVGImage(bounds=bounds, scale=settings.RENDER_SCALE) building_geometries = cascaded_union(tuple(b.geometry for b in self.buildings.all())) diff --git a/src/c3nav/mapdata/utils/svg.py b/src/c3nav/mapdata/utils/svg.py index b647df9e..3645412d 100644 --- a/src/c3nav/mapdata/utils/svg.py +++ b/src/c3nav/mapdata/utils/svg.py @@ -2,13 +2,14 @@ import re import xml.etree.ElementTree as ET from itertools import chain -from shapely.affinity import scale +from shapely.affinity import scale, translate class SVGImage: - def __init__(self, width: int, height: int, scale: float=1): - self.width = width - self.height = height + def __init__(self, bounds, scale: float=1): + (self.bottom, self.left), (self.top, self.right) = bounds + self.width = self.right-self.left + self.height = self.top-self.bottom self.scale = scale self.g = ET.Element('g', {}) self.defs = ET.Element('defs') @@ -44,6 +45,7 @@ class SVGImage: return re.sub(r'([0-9]+)\.0', r'\1', re.sub(r'([0-9]+\.[0-9])[0-9]+', r'\1', data)) def _create_geometry(self, geometry): + geometry = translate(geometry, xoff=0-self.left, yoff=0-self.bottom) geometry = scale(geometry, xfact=1, yfact=-1, origin=(self.width / 2, self.height / 2)) geometry = scale(geometry, xfact=self.scale, yfact=self.scale, origin=(0, 0)) element = ET.fromstring(self._trim_decimals(geometry.svg(0, '#FFFFFF'))) diff --git a/src/c3nav/routing/route.py b/src/c3nav/routing/route.py index 677d5fb8..033fc31c 100644 --- a/src/c3nav/routing/route.py +++ b/src/c3nav/routing/route.py @@ -4,8 +4,6 @@ from collections import OrderedDict import numpy as np from django.utils.translation import ugettext_lazy as _ -from c3nav.mapdata.utils.misc import get_dimensions - class Route: def __init__(self, connections, distance=None):