Show elevation on the map directly while hovering. [rebuild]
[release]
@@ -125,6 +125,7 @@ struct RouteResults {
closest_path_segment: FindClosest<usize>,
hover_on_line_plot: Option<(Distance, Drawable)>,
+ hover_on_route_tooltip: Option<Text>,
draw_route_unzoomed: Drawable,
draw_route_zoomed: Drawable,
panel: Panel,
@@ -276,6 +277,7 @@ impl RouteResults {
paths,
closest_path_segment,
hover_on_line_plot: None,
+ hover_on_route_tooltip: None,
}
}
@@ -313,6 +315,8 @@ impl RouteResults {
});
}
+ if ctx.redo_mouseover() {
+ self.hover_on_route_tooltip = None;
if let Some(pt) = ctx.canvas.get_cursor_in_map_space() {
if let Some((idx, pt)) = self
.closest_path_segment
@@ -325,9 +329,9 @@ impl RouteResults {
}
if let Some(ref pl) = self.paths[idx].1 {
if let Some((dist_here, _)) = pl.dist_along_of_point(pt) {
- // The LinePlot doesn't hold onto the original Series, so it can't help us
- // figure out elevation here. Let's match this point to the original path
- // and guess elevation ourselves...
+ // The LinePlot doesn't hold onto the original Series, so it can't help
+ // us figure out elevation here. Let's match this point to the original
+ // path and guess elevation ourselves...
let map = &app.primary.map;
let elevation = match self.paths[idx]
.0
@@ -345,6 +349,11 @@ impl RouteResults {
self.panel
.find_mut::<LinePlot<Distance, Distance>>("elevation")
.set_hovering(ctx, dist + dist_here, elevation);
+ self.hover_on_route_tooltip = Some(Text::from(Line(format!(
+ "Elevation: {}",
+ elevation.to_string(&app.opts.units)
+ ))));
+ }
}
}
}
@@ -361,6 +370,9 @@ impl RouteResults {
if let Some((_, ref draw)) = self.hover_on_line_plot {
g.redraw(draw);
}
+ if let Some(ref txt) = self.hover_on_route_tooltip {
+ g.draw_mouse_tooltip(txt.clone());
+ }
}
}
