implement custom route descriptions
This commit is contained in:
parent
fe7faaff58
commit
120091f985
3 changed files with 32 additions and 7 deletions
|
@ -184,9 +184,9 @@ def edit(request, pk=None, model=None, level=None, space=None, on_top_of=None, e
|
||||||
'geometry_url': '/api/editor/geometries/?level='+str(level.primary_level_pk),
|
'geometry_url': '/api/editor/geometries/?level='+str(level.primary_level_pk),
|
||||||
})
|
})
|
||||||
elif hasattr(model, 'space'):
|
elif hasattr(model, 'space'):
|
||||||
space_id = space.pk
|
|
||||||
if not new:
|
if not new:
|
||||||
space = obj.space
|
space = obj.space
|
||||||
|
space_id = space.pk
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'level': space.level,
|
'level': space.level,
|
||||||
'back_url': reverse('editor.'+related_name+'.list', kwargs={'space': space.pk}),
|
'back_url': reverse('editor.'+related_name+'.list', kwargs={'space': space.pk}),
|
||||||
|
|
|
@ -84,11 +84,26 @@ class Route:
|
||||||
item.descriptions.append((icon, item.waytype.description_up))
|
item.descriptions.append((icon, item.waytype.description_up))
|
||||||
else:
|
else:
|
||||||
item.descriptions.append((icon, item.waytype.description))
|
item.descriptions.append((icon, item.waytype.description))
|
||||||
elif item.last_item and item.new_space:
|
|
||||||
item.descriptions.append(('more_vert', _('Go to %(space_title)s.') % {
|
# add space transfer descriptions
|
||||||
'space_title': item.space.title
|
last_space = None
|
||||||
}))
|
current_space = None
|
||||||
next_item = item
|
for item in items:
|
||||||
|
if item.new_space:
|
||||||
|
next_space = item.space
|
||||||
|
if item.last_item:
|
||||||
|
description = None
|
||||||
|
if last_space:
|
||||||
|
description = current_space.cross_descriptions.get((last_space.pk, next_space.pk), None)
|
||||||
|
if description is None:
|
||||||
|
description = current_space.leave_descriptions.get(next_space.pk, None)
|
||||||
|
if description is None:
|
||||||
|
description = _('Go to %(space_title)s.') % {'space_title': item.space.title}
|
||||||
|
|
||||||
|
item.descriptions.append(('more_vert', description))
|
||||||
|
|
||||||
|
last_space = current_space
|
||||||
|
current_space = next_space
|
||||||
|
|
||||||
# add description for last space
|
# add description for last space
|
||||||
remaining_distance = destination_distance
|
remaining_distance = destination_distance
|
||||||
|
|
|
@ -17,7 +17,7 @@ from shapely.geometry import LineString, Point
|
||||||
from shapely.ops import unary_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
from c3nav.mapdata.models import AltitudeArea, Area, GraphEdge, Level, LocationGroup, MapUpdate, Space, WayType
|
from c3nav.mapdata.models import AltitudeArea, Area, GraphEdge, Level, LocationGroup, MapUpdate, Space, WayType
|
||||||
from c3nav.mapdata.models.geometry.space import POI
|
from c3nav.mapdata.models.geometry.space import POI, CrossDescription, LeaveDescription
|
||||||
from c3nav.mapdata.utils.geometry import assert_multipolygon, get_rings, good_representative_point
|
from c3nav.mapdata.utils.geometry import assert_multipolygon, get_rings, good_representative_point
|
||||||
from c3nav.mapdata.utils.locations import CustomLocation
|
from c3nav.mapdata.utils.locations import CustomLocation
|
||||||
from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable
|
from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable
|
||||||
|
@ -174,6 +174,14 @@ class Router:
|
||||||
level.nodes = set(range(nodes_before_count, len(nodes)))
|
level.nodes = set(range(nodes_before_count, len(nodes)))
|
||||||
levels[level.pk] = level
|
levels[level.pk] = level
|
||||||
|
|
||||||
|
# add graph descriptions
|
||||||
|
for description in LeaveDescription.objects.all():
|
||||||
|
spaces[description.space_id].leave_descriptions[description.target_space_id] = description.description
|
||||||
|
|
||||||
|
for description in CrossDescription.objects.all():
|
||||||
|
spaces[description.space_id].cross_descriptions[(description.origin_space_id,
|
||||||
|
description.target_space_id)] = description.description
|
||||||
|
|
||||||
# waytypes
|
# waytypes
|
||||||
waytypes = deque([RouterWayType(None)])
|
waytypes = deque([RouterWayType(None)])
|
||||||
waytypes_lookup = {None: 0}
|
waytypes_lookup = {None: 0}
|
||||||
|
@ -441,6 +449,8 @@ class RouterSpace(BaseRouterProxy):
|
||||||
def __init__(self, space, altitudeareas=None):
|
def __init__(self, space, altitudeareas=None):
|
||||||
super().__init__(space)
|
super().__init__(space)
|
||||||
self.altitudeareas = altitudeareas if altitudeareas else []
|
self.altitudeareas = altitudeareas if altitudeareas else []
|
||||||
|
self.leave_descriptions = {}
|
||||||
|
self.cross_descriptions = {}
|
||||||
|
|
||||||
def altitudearea_for_point(self, point):
|
def altitudearea_for_point(self, point):
|
||||||
point = Point(point.x, point.y)
|
point = Point(point.x, point.y)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue