calculate image idimensions from Source dimensions :3
This commit is contained in:
parent
dcfab74f29
commit
35a1114199
3 changed files with 9 additions and 9 deletions
|
@ -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()))
|
||||
|
||||
|
|
|
@ -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')))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue