fly_to_bounds can now fly to the current route
This commit is contained in:
parent
2df6b971f9
commit
c72e64789c
1 changed files with 28 additions and 15 deletions
|
@ -148,7 +148,8 @@ c3nav = {
|
||||||
c3nav.update_map_locations();
|
c3nav.update_map_locations();
|
||||||
},
|
},
|
||||||
_clear_route_layers: function() {
|
_clear_route_layers: function() {
|
||||||
console.log('clear route layers');
|
c3nav._firstRouteLevel = null;
|
||||||
|
c3nav._routeLayerBounds = {};
|
||||||
for (var id in c3nav._routeLayers) {
|
for (var id in c3nav._routeLayers) {
|
||||||
c3nav._routeLayers[id].clearLayers();
|
c3nav._routeLayers[id].clearLayers();
|
||||||
}
|
}
|
||||||
|
@ -216,7 +217,6 @@ c3nav = {
|
||||||
}
|
}
|
||||||
c3nav._push_state({route_result: data.result}, true);
|
c3nav._push_state({route_result: data.result}, true);
|
||||||
c3nav._display_route_result(data.result);
|
c3nav._display_route_result(data.result);
|
||||||
$route.removeClass('loading');
|
|
||||||
},
|
},
|
||||||
_display_route_result: function(result) {
|
_display_route_result: function(result) {
|
||||||
var $route = $('#route-summary'),
|
var $route = $('#route-summary'),
|
||||||
|
@ -226,6 +226,7 @@ c3nav = {
|
||||||
next_level_collect = [],
|
next_level_collect = [],
|
||||||
in_intermediate_level = true,
|
in_intermediate_level = true,
|
||||||
item, coords;
|
item, coords;
|
||||||
|
c3nav._clear_route_layers();
|
||||||
for (var i=0; i < result.items.length; i++) {
|
for (var i=0; i < result.items.length; i++) {
|
||||||
item = result.items[i];
|
item = result.items[i];
|
||||||
coords = [item.coordinates[0], item.coordinates[1]];
|
coords = [item.coordinates[0], item.coordinates[1]];
|
||||||
|
@ -236,7 +237,7 @@ c3nav = {
|
||||||
next_level_collect = next_level_collect.concat(level_collect);
|
next_level_collect = next_level_collect.concat(level_collect);
|
||||||
} else if (last_primary_level) {
|
} else if (last_primary_level) {
|
||||||
// if we were in an intermediate level, add this line to it
|
// if we were in an intermediate level, add this line to it
|
||||||
c3nav._add_line_to_level(last_primary_level, level_collect);
|
c3nav._add_line_to_route(last_primary_level, level_collect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.level.on_top_of) {
|
if (item.level.on_top_of) {
|
||||||
|
@ -245,8 +246,8 @@ c3nav = {
|
||||||
} else {
|
} else {
|
||||||
// if we are now in a primary level, add intermediate lines as links to last primary and this level
|
// if we are now in a primary level, add intermediate lines as links to last primary and this level
|
||||||
in_intermediate_level = false;
|
in_intermediate_level = false;
|
||||||
c3nav._add_line_to_level(last_primary_level, next_level_collect, false, item.level.id);
|
c3nav._add_line_to_route(last_primary_level, next_level_collect, false, item.level.id);
|
||||||
c3nav._add_line_to_level(item.level.id, next_level_collect, false, last_primary_level);
|
c3nav._add_line_to_route(item.level.id, next_level_collect, false, last_primary_level);
|
||||||
if (!first_primary_level) first_primary_level = item.level.id;
|
if (!first_primary_level) first_primary_level = item.level.id;
|
||||||
last_primary_level = item.level.id;
|
last_primary_level = item.level.id;
|
||||||
next_level_collect = [];
|
next_level_collect = [];
|
||||||
|
@ -255,28 +256,35 @@ c3nav = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (last_primary_level) {
|
if (last_primary_level) {
|
||||||
c3nav._add_line_to_level(last_primary_level, next_level_collect);
|
c3nav._add_line_to_route(last_primary_level, next_level_collect);
|
||||||
c3nav._add_line_to_level(last_primary_level, level_collect);
|
c3nav._add_line_to_route(last_primary_level, level_collect);
|
||||||
}
|
}
|
||||||
c3nav._add_line_to_level(first_primary_level, [
|
c3nav._add_line_to_route(first_primary_level, [
|
||||||
[result.origin.point[1], result.origin.point[2]],
|
[result.origin.point[1], result.origin.point[2]],
|
||||||
result.items[0].coordinates.slice(0, 2)
|
result.items[0].coordinates.slice(0, 2)
|
||||||
], true);
|
], true);
|
||||||
c3nav._add_line_to_level(last_primary_level, [
|
c3nav._add_line_to_route(last_primary_level, [
|
||||||
item.coordinates.slice(0, 2),
|
item.coordinates.slice(0, 2),
|
||||||
[result.destination.point[1], result.destination.point[2]]
|
[result.destination.point[1], result.destination.point[2]]
|
||||||
], true);
|
], true);
|
||||||
|
c3nav._firstRouteLevel = first_primary_level;
|
||||||
$route.find('span').text(String(result.distance)+' m');
|
$route.find('span').text(String(result.distance)+' m');
|
||||||
|
$route.removeClass('loading');
|
||||||
|
c3nav.fly_to_bounds(true);
|
||||||
},
|
},
|
||||||
_add_line_to_level: function(level, coords, gray, link_to_level) {
|
_add_line_to_route: function(level, coords, gray, link_to_level) {
|
||||||
if (coords.length < 2) return;
|
if (coords.length < 2) return;
|
||||||
var latlngs = L.GeoJSON.coordsToLatLngs(coords),
|
var latlngs = L.GeoJSON.coordsToLatLngs(coords),
|
||||||
routeLayer = c3nav._routeLayers[level];
|
routeLayer = c3nav._routeLayers[level];
|
||||||
|
line = L.polyline(latlngs, {
|
||||||
|
color: gray ? '#888888': $('button.swap').css('color'),
|
||||||
|
dashArray: (gray || link_to_level) ? '7' : null
|
||||||
|
}).addTo(routeLayer),
|
||||||
|
bounds = {};
|
||||||
|
bounds[level] = line.getBounds();
|
||||||
|
|
||||||
|
c3nav._merge_bounds(c3nav._routeLayerBounds, bounds);
|
||||||
|
|
||||||
L.polyline(latlngs, {
|
|
||||||
color: gray ? '#888888': $('button.swap').css('color'),
|
|
||||||
dashArray: (gray || link_to_level) ? '7' : null
|
|
||||||
}).addTo(routeLayer);
|
|
||||||
if (link_to_level) {
|
if (link_to_level) {
|
||||||
L.polyline(latlngs, {
|
L.polyline(latlngs, {
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
|
@ -655,6 +663,8 @@ c3nav = {
|
||||||
c3nav._locationLayers = {};
|
c3nav._locationLayers = {};
|
||||||
c3nav._locationLayerBounds = {};
|
c3nav._locationLayerBounds = {};
|
||||||
c3nav._routeLayers = {};
|
c3nav._routeLayers = {};
|
||||||
|
c3nav._routeLayerBounds = {};
|
||||||
|
c3nav._firstRouteLevel = null;
|
||||||
for (i = c3nav.levels.length - 1; i >= 0; i--) {
|
for (i = c3nav.levels.length - 1; i >= 0; i--) {
|
||||||
var level = c3nav.levels[i];
|
var level = c3nav.levels[i];
|
||||||
var layerGroup = c3nav._levelControl.addLevel(level[0], level[2]);
|
var layerGroup = c3nav._levelControl.addLevel(level[0], level[2]);
|
||||||
|
@ -703,7 +713,10 @@ c3nav = {
|
||||||
var level = c3nav._levelControl.currentLevel,
|
var level = c3nav._levelControl.currentLevel,
|
||||||
bounds = null;
|
bounds = null;
|
||||||
|
|
||||||
if (c3nav._locationLayerBounds[level]) {
|
if (c3nav._firstRouteLevel) {
|
||||||
|
level = c3nav._firstRouteLevel;
|
||||||
|
bounds = c3nav._routeLayerBounds[level];
|
||||||
|
} else if (c3nav._locationLayerBounds[level]) {
|
||||||
bounds = c3nav._locationLayerBounds[level];
|
bounds = c3nav._locationLayerBounds[level];
|
||||||
} else {
|
} else {
|
||||||
for (var level_id in c3nav._locationLayers) {
|
for (var level_id in c3nav._locationLayers) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue