display coordinates details
This commit is contained in:
parent
4d2607ca3f
commit
eeae2d019b
3 changed files with 36 additions and 14 deletions
|
@ -25,8 +25,7 @@ from c3nav.mapdata.models.level import Level
|
|||
from c3nav.mapdata.models.locations import (Location, LocationGroupCategory, LocationRedirect, LocationSlug,
|
||||
SpecificLocation)
|
||||
from c3nav.mapdata.utils.locations import (get_location_by_id_for_request, get_location_by_slug_for_request,
|
||||
locations_for_request, searchable_locations_for_request,
|
||||
visible_locations_for_request)
|
||||
searchable_locations_for_request, visible_locations_for_request)
|
||||
from c3nav.mapdata.utils.models import get_submodels
|
||||
|
||||
|
||||
|
@ -299,10 +298,8 @@ class LocationViewSet(RetrieveModelMixin, GenericViewSet):
|
|||
@detail_route(methods=['get'])
|
||||
@api_etag()
|
||||
def display(self, request, pk=None):
|
||||
if not pk.isdigit():
|
||||
raise NotFound
|
||||
location = get_location_by_id_for_request(pk, request)
|
||||
|
||||
location = locations_for_request(request).get(int(pk))
|
||||
if location is None:
|
||||
raise NotFound
|
||||
|
||||
|
|
|
@ -240,6 +240,13 @@ class CustomLocation:
|
|||
'x': self.x,
|
||||
'y': self.y})
|
||||
|
||||
@property
|
||||
def serialized_geometry(self):
|
||||
return {
|
||||
'type': 'Point',
|
||||
'coordinates': (self.x, self.y)
|
||||
}
|
||||
|
||||
def serialize(self, simple_geometry=False, geometry=True, **kwargs):
|
||||
result = OrderedDict((
|
||||
('id', self.pk),
|
||||
|
@ -252,8 +259,26 @@ class CustomLocation:
|
|||
result['bounds'] = ((int(math.floor(self.x)), int(math.floor(self.y))),
|
||||
(int(math.ceil(self.x)), int(math.ceil(self.y))))
|
||||
if geometry:
|
||||
result['geometry'] = {
|
||||
'type': 'Point',
|
||||
'coordinates': (self.x, self.y)
|
||||
}
|
||||
result['geometry'] = self.serialized_geometry
|
||||
return result
|
||||
|
||||
def details_display(self):
|
||||
return {
|
||||
'id': self.pk,
|
||||
'display': [
|
||||
(str(_('Type')), str(_('Coordinates'))),
|
||||
(str(_('ID')), str(self.pk)),
|
||||
(str(_('Slug')), str(self.pk)),
|
||||
(str(_('Level')), {
|
||||
'id': self.level.pk,
|
||||
'slug': self.level.get_slug(),
|
||||
'title': self.level.title,
|
||||
'can_search': self.level.can_search,
|
||||
}),
|
||||
(str(_('X Coordinate')), str(self.x)),
|
||||
(str(_('Y Coordinate')), str(self.y)),
|
||||
(str(_('Title')), str(self.title)),
|
||||
(str(_('Subtitle')), str(self.subtitle)),
|
||||
],
|
||||
'geometry': self.serialized_geometry,
|
||||
}
|
||||
|
|
|
@ -159,14 +159,14 @@ c3nav = {
|
|||
|
||||
load_location_details: function (location) {
|
||||
var $location_details = $('#location-details');
|
||||
if (parseInt($location_details.attr('data-id')) !== location.id) {
|
||||
if ($location_details.attr('data-id') !== String(location.id)) {
|
||||
$location_details.addClass('loading').attr('data-id', location.id);
|
||||
$.getJSON('/api/locations/'+location.id+'/display', c3nav._location_details_loaded);
|
||||
}
|
||||
},
|
||||
_location_details_loaded: function(data) {
|
||||
var $location_details = $('#location-details');
|
||||
if (parseInt($location_details.attr('data-id')) !== data.id) {
|
||||
if ($location_details.attr('data-id') !== String(data.id)) {
|
||||
// loaded too late, information no longer needed
|
||||
return;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ c3nav = {
|
|||
loclist = $('<dd>');
|
||||
for (var j = 0; j < sublocations.length; j++) {
|
||||
loc = sublocations[j];
|
||||
if (loc.can_searc) {
|
||||
if (loc.can_search) {
|
||||
loclist.append($('<a>').attr('href', '/l/' + loc.slug + '/details/').attr('data-id', loc.id).click(function (e) {
|
||||
e.preventDefault();
|
||||
c3nav._locationinput_set($('#destination-input'), c3nav.locations_by_id[parseInt($(this).attr('data-id'))]);
|
||||
|
@ -197,11 +197,11 @@ c3nav = {
|
|||
}
|
||||
}
|
||||
$location_details.find('.details-body').html('').append(elem);
|
||||
$location_details.removeClass('loading').find('.editor').attr('href', data.editor_url);
|
||||
$location_details.removeClass('loading').find('.editor').toggle(data.editor_url).attr('href', data.editor_url);
|
||||
},
|
||||
load_route: function (origin, destination, nofly) {
|
||||
var $route = $('#route-summary');
|
||||
if (parseInt($route.attr('data-origin')) !== origin.id || parseInt($route.attr('data-destination')) !== destination.id) {
|
||||
if ($route.attr('data-origin') !== String(origin.id) || $route.attr('data-destination') !== String(destination.id)) {
|
||||
c3nav._clear_route_layers();
|
||||
$route.addClass('loading').attr('data-origin', origin.id).attr('data-destination', destination.id);
|
||||
$.post('/api/routing/route/', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue