first stuff for showing the route on the site
This commit is contained in:
parent
ad58ddbbcb
commit
f6129d621c
14 changed files with 366 additions and 154 deletions
|
@ -1,7 +1,16 @@
|
|||
from django.shortcuts import redirect, render
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from c3nav.mapdata.models import Level
|
||||
from c3nav.mapdata.models.locations import get_location
|
||||
from c3nav.mapdata.render.compose import composer
|
||||
from c3nav.mapdata.utils.misc import get_dimensions
|
||||
from c3nav.routing.graph import Graph
|
||||
from c3nav.routing.utils.draw import _line_coords
|
||||
|
||||
|
||||
def main(request, origin=None, destination=None):
|
||||
|
@ -30,13 +39,39 @@ def main(request, origin=None, destination=None):
|
|||
|
||||
redirect(new_url)
|
||||
|
||||
route = None
|
||||
if origin and destination:
|
||||
graph = Graph.load()
|
||||
route = graph.get_route(origin, destination)
|
||||
route = route.split()
|
||||
print(route)
|
||||
|
||||
print(route)
|
||||
if False:
|
||||
filename = os.path.join(settings.RENDER_ROOT, 'base-level-0.png')
|
||||
|
||||
im = Image.open(filename)
|
||||
height = im.size[1]
|
||||
draw = ImageDraw.Draw(im)
|
||||
for connection in route.connections:
|
||||
draw.line(_line_coords(connection.from_point, connection.to_point, height), fill=(255, 100, 100))
|
||||
|
||||
response = HttpResponse(content_type="image/png")
|
||||
im.save(response, "PNG")
|
||||
return response
|
||||
|
||||
width, height = get_dimensions()
|
||||
|
||||
return render(request, 'site/main.html', {
|
||||
'origin': origin,
|
||||
'destination': destination
|
||||
'destination': destination,
|
||||
'route': route,
|
||||
'width': width,
|
||||
'height': height,
|
||||
'svg_width': width*6,
|
||||
'svg_height': height*6,
|
||||
})
|
||||
|
||||
|
||||
def level_image(request, level):
|
||||
level = get_object_or_404(Level, name=level, intermediate=False)
|
||||
return composer.get_level_image(request, level)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue