show dynamic locations in the frontend already!

This commit is contained in:
Laura Klünder 2019-12-27 20:36:22 +01:00
parent 7e56927a72
commit cc1a53d0d6
2 changed files with 26 additions and 2 deletions

View file

@ -501,7 +501,7 @@ class DynamicLocation(CustomLocationProxyMixin, SpecificLocation, models.Model):
'title': self.title,
'subtitle': '%s %s, %s' % (_('currently unavailable'), _('(moving)'), self.subtitle)
}
result = custom_location.serialize()
result = custom_location.serialize(simple_geometry=True)
result.update({
'available': True,
'id': self.pk,
@ -590,7 +590,7 @@ class Position(CustomLocationProxyMixin, models.Model):
'title': self.name,
'subtitle': _('currently unavailable'),
}
result = custom_location.serialize()
result = custom_location.serialize(simple_geometry=True)
result.update({
'available': True,
'id': 'p:%s' % self.secret,

View file

@ -1524,6 +1524,15 @@ c3nav = {
// if location is not in the searchable list...
return
}
console.log(location);
if (location.dynamic) {
if (!('available' in location)) {
$.getJSON('/api/locations/dynamic/' + location.id + '/', c3nav._dynamic_location_loaded);
return;
} else if (!location.available) {
return;
}
}
// add a location to the map as a marker
if (location.locations) {
var bounds = {};
@ -1566,6 +1575,21 @@ c3nav = {
bounds[level_id] = bounds[level_id] ? bounds[level_id].extend(new_bounds[level_id]) : new_bounds[level_id];
}
},
_dynamic_location_loaded: function(data) {
if (c3nav._maybe_update_dynamic_location($('#origin-input'), data) || c3nav._maybe_update_dynamic_location($('#destination-input'), data)) {
c3nav.update_state();
// todo: fly to bounds
}
},
_maybe_update_dynamic_location: function(elem, location) {
if (elem.is('.empty')) return false;
var orig_location = elem.data('location');
if (orig_location.id !== location.id) return false;
new_location = $.extend({}, orig_location, location);
c3nav._locationinput_set(elem, new_location);
return true;
},
_location_geometry_loaded: function(data) {
if (c3nav._visible_map_locations.indexOf(data.id) === -1 || data.geometry === null || data.level === null) return;