diff --git a/src/c3nav/mapdata/utils/locations.py b/src/c3nav/mapdata/utils/locations.py index 30d57da1..5e7855de 100644 --- a/src/c3nav/mapdata/utils/locations.py +++ b/src/c3nav/mapdata/utils/locations.py @@ -249,7 +249,7 @@ class CustomLocation: 'coordinates': (self.x, self.y) } - def serialize(self, simple_geometry=False, geometry=True, **kwargs): + def serialize(self, include_type=False, simple_geometry=False, geometry=True, **kwargs): result = OrderedDict(( ('id', self.pk), ('slug', self.pk), @@ -258,6 +258,9 @@ class CustomLocation: ('level', self.level.pk), ('space', self.space.pk if self.space else None), )) + if include_type: + result['type'] = 'custom' + result.move_to_end('type', last=False) if simple_geometry: result['point'] = (self.level.pk, self.x, self.y) result['bounds'] = ((int(math.floor(self.x)), int(math.floor(self.y))), diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index dcf90e23..47449b28 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -355,16 +355,22 @@ c3nav = { $details.append(c3nav._build_location_html(result.destination)); // add origin and destination lines - c3nav._add_line_to_route(first_primary_level, c3nav._add_intermediate_point( - result.origin.point.slice(1), - result.items[0].coordinates.slice(0, 2), - result.items[1].coordinates.slice(0, 2) - ), true); - c3nav._add_line_to_route(last_primary_level, c3nav._add_intermediate_point( - result.destination.point.slice(1), - result.items[result.items.length-1].coordinates.slice(0, 2), - result.items[result.items.length-2].coordinates.slice(0, 2) - ).reverse(), true); + c3nav._location_point_overrides = {}; + if (!c3nav._add_location_point_override(result.origin, result.items[0])) { + c3nav._add_line_to_route(first_primary_level, c3nav._add_intermediate_point( + result.origin.point.slice(1), + result.items[0].coordinates.slice(0, 2), + result.items[1].coordinates.slice(0, 2) + ), true); + } + if (!c3nav._add_location_point_override(result.destination, result.items.slice(-1)[0])) { + c3nav._add_line_to_route(last_primary_level, c3nav._add_intermediate_point( + result.destination.point.slice(1), + result.items[result.items.length - 1].coordinates.slice(0, 2), + result.items[result.items.length - 2].coordinates.slice(0, 2) + ).reverse(), true); + } + c3nav.update_map_locations(); c3nav._firstRouteLevel = first_primary_level; $route.find('span').text(result.summary); @@ -374,6 +380,13 @@ c3nav = { if (!nofly) c3nav.fly_to_bounds(true); }, + _add_location_point_override: function (location, item) { + if (location.type === 'level' || location.type === 'space' || location.type === 'area') { + c3nav._location_point_overrides[location.id] = item.coordinates.slice(0, -1); + return true; + } + return false; + }, _build_route_item: function (icon, text) { var elem = $('