diff --git a/src/c3nav/mapdata/utils/locations.py b/src/c3nav/mapdata/utils/locations.py index 5e7855de..3807c035 100644 --- a/src/c3nav/mapdata/utils/locations.py +++ b/src/c3nav/mapdata/utils/locations.py @@ -257,6 +257,7 @@ class CustomLocation: ('subtitle', self.subtitle), ('level', self.level.pk), ('space', self.space.pk if self.space else None), + ('altitude', None if self.altitude is None else round(self.altitude, 2)) )) if include_type: result['type'] = 'custom' @@ -291,6 +292,7 @@ class CustomLocation: } if self.space else None), (_('X Coordinate'), str(self.x)), (_('Y Coordinate'), str(self.y)), + (_('Altitude'), None if self.altitude is None else str(round(self.altitude, 2))), (_('Title'), self.title), (_('Subtitle'), self.subtitle), ], @@ -304,10 +306,11 @@ class CustomLocation: @cached_property def space(self): - try: - return self.description.space - except Exception: - return None + return self.description.space + + @cached_property + def altitude(self): + return self.description.altitude @cached_property def title(self): diff --git a/src/c3nav/routing/router.py b/src/c3nav/routing/router.py index 60592749..f7f5aedb 100644 --- a/src/c3nav/routing/router.py +++ b/src/c3nav/routing/router.py @@ -294,14 +294,15 @@ class Router: return self.spaces[space] spaces = (self.spaces[space] for space in level.spaces) spaces = ((space, space.geometry.distance(point)) for space in spaces) - spaces = ((space, distance) for space, distance in spaces if distance < 0.5) + spaces = tuple((space, distance) for space, distance in spaces if distance < 0.5) + if not spaces: + return None return min(spaces, key=operator.itemgetter(1))[0] def describe_custom_location(self, location): - return CustomLocationDescription( - space=self.space_for_point(location.level.pk, location, - self.get_restrictions(location.permissions)) - ) + space = self.space_for_point(location.level.pk, location, self.get_restrictions(location.permissions)) + altitude = space.altitudearea_for_point(location).get_altitude(location) if space else None + return CustomLocationDescription(space=space, altitude=altitude) def shortest_path(self, restrictions, options): options_key = json.dumps(options.data, separators=(',', '='), sort_keys=True)[1:-1] @@ -400,7 +401,7 @@ class Router: origin_addition, destination_addition) -CustomLocationDescription = namedtuple('CustomLocationDescription', ('space')) +CustomLocationDescription = namedtuple('CustomLocationDescription', ('space', 'altitude')) class BaseRouterProxy: