show locations immediately after searching

This commit is contained in:
Laura Klünder 2018-12-25 18:08:33 +01:00
parent 9a9ea45242
commit 95fce11d00
3 changed files with 31 additions and 6 deletions

View file

@ -1161,6 +1161,7 @@ c3nav = {
shadowSize: [41, 41]
});
},
visible_map_locations: [],
update_map_locations: function () {
// update locations markers on the map
var origin = $('#origin-input').data('location'),
@ -1170,6 +1171,7 @@ c3nav = {
for (var level_id in c3nav._locationLayers) {
c3nav._locationLayers[level_id].clearLayers()
}
c3nav._visible_map_locations = [];
if (origin) c3nav._merge_bounds(bounds, c3nav._add_location_to_map(origin, single ? new L.Icon.Default() : c3nav.originIcon));
if (destination) c3nav._merge_bounds(bounds, c3nav._add_location_to_map(destination, single ? new L.Icon.Default() : c3nav.destinationIcon));
c3nav._locationLayerBounds = bounds;
@ -1231,7 +1233,7 @@ c3nav = {
];
},
_location_point_overrides: {},
_add_location_to_map: function(location, icon) {
_add_location_to_map: function(location, icon, no_geometry) {
if (!location) {
// if location is not in the searchable list...
return
@ -1239,12 +1241,17 @@ c3nav = {
// add a location to the map as a marker
if (location.locations) {
var bounds = {};
for (var i=0; i<location.locations.length; i++) {
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[location.locations[i]], icon));
for (var i = 0; i < location.locations.length; i++) {
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[location.locations[i]], icon, true));
}
return bounds;
}
if (!no_geometry && c3nav._visible_map_locations.indexOf(location.id) === -1) {
c3nav._visible_map_locations.push(location.id);
$.getJSON('/api/locations/' + location.id + '/geometry/', c3nav._location_geometry_loaded);
}
var point = c3nav._location_point_overrides[location.id] || location.point.slice(1),
latlng = L.GeoJSON.coordsToLatLng(point);
L.marker(latlng, {
@ -1266,6 +1273,17 @@ c3nav = {
}
},
_location_geometry_loaded: function(data) {
if (c3nav._visible_map_locations.indexOf(data.id) === -1 || data.geometry === null || data.level === null) return;
L.geoJSON(data.geometry, {
style: {
color: c3nav._primary_color,
fillOpacity: 0.2,
}
}).addTo(c3nav._locationLayers[data.level]);
},
_fetch_updates_timer: null,
schedule_fetch_updates: function (timeout) {
if (c3nav._fetch_updates_timer === null) {