2017-10-10 17:49:53 +02:00
|
|
|
from shapely.geometry import box
|
|
|
|
|
2017-10-19 13:35:17 +02:00
|
|
|
from c3nav.mapdata.render.base import get_render_level_data
|
2017-10-10 14:39:11 +02:00
|
|
|
from c3nav.mapdata.utils.svg import SVGImage
|
|
|
|
|
|
|
|
|
|
|
|
def render_svg(level, miny, minx, maxy, maxx, scale=1):
|
2017-10-19 15:34:01 +02:00
|
|
|
svg = SVGImage(bounds=((miny, minx), (maxy, maxx)), scale=scale, buffer=1)
|
2017-10-10 14:39:11 +02:00
|
|
|
|
2017-10-19 15:34:01 +02:00
|
|
|
within_coords = (minx-1, miny-1, maxx+1, maxy+1)
|
2017-10-10 17:49:53 +02:00
|
|
|
bbox = box(*within_coords)
|
|
|
|
|
2017-10-19 15:31:30 +02:00
|
|
|
render_level_data = get_render_level_data(level)
|
|
|
|
|
|
|
|
crop_to = None
|
|
|
|
primary_level_count = 0
|
|
|
|
for geoms, default_height in reversed(render_level_data):
|
|
|
|
if geoms.holes is not None:
|
|
|
|
primary_level_count += 1
|
|
|
|
|
|
|
|
geoms.crop_to = crop_to if primary_level_count > 1 else None
|
|
|
|
|
|
|
|
if geoms.holes is not None:
|
|
|
|
if crop_to is None:
|
|
|
|
crop_to = geoms.holes
|
|
|
|
else:
|
|
|
|
crop_to = crop_to.intersection(geoms.holes)
|
|
|
|
|
|
|
|
for geoms, default_height in render_level_data:
|
|
|
|
crop_to = bbox
|
|
|
|
if geoms.crop_to is not None:
|
|
|
|
crop_to = crop_to.intersection(geoms.crop_to)
|
|
|
|
|
2017-10-19 13:35:17 +02:00
|
|
|
for altitudearea_geom, altitude in geoms.altitudeareas:
|
2017-10-19 15:31:30 +02:00
|
|
|
svg.add_geometry(crop_to.intersection(altitudearea_geom), fill_color='#eeeeee', altitude=altitude)
|
2017-10-16 17:10:32 +02:00
|
|
|
|
2017-10-19 15:31:30 +02:00
|
|
|
svg.add_geometry(crop_to.intersection(geoms.walls),
|
2017-10-19 13:35:17 +02:00
|
|
|
fill_color='#aaaaaa', stroke_px=0.5, stroke_color='#aaaaaa', elevation=default_height)
|
2017-10-16 17:10:32 +02:00
|
|
|
|
2017-10-19 15:31:30 +02:00
|
|
|
svg.add_geometry(crop_to.intersection(geoms.doors), fill_color='#ffffff', elevation=0)
|
2017-10-17 19:31:19 +02:00
|
|
|
|
2017-10-17 12:24:38 +02:00
|
|
|
return svg
|