Skip to content

Commit

Permalink
Fix map markers not being sent to web clients
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamVenner committed Jun 7, 2022
1 parent 55037b6 commit fdad901
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/ui/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,15 @@ pub(super) fn render(state: &mut UIState, ui: &Ui) {
// Update web users
if let Some(web) = &mut state.web.server {
web.send(smh_web::Event::Map { map });
web.send(smh_web::Event::Markers {
custom: false,
markers: state.vision.markers.iter().map(|marker| [marker.p0, marker.p1]).collect::<Box<_>>(),
});
}
}

if let Some(web) = &mut state.web.server {
web.send(smh_web::Event::Markers {
custom: false,
markers: state.vision.markers.iter().map(|marker| [marker.p0, marker.p1]).collect::<Box<_>>(),
});
}
}

let (quad, map_viewport) = MapViewport::calc(
Expand Down
8 changes: 3 additions & 5 deletions web/www/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,18 @@ function draw_marker(ctx, marker, color) {
ctx.textBaseline = 'top';
ctx.fillStyle = 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')';

if (meters_to_px_ratio === null) {
return;
}

var heightmap_data = calc_alt_delta([marker.p0x, marker.p0y], [marker.p1x, marker.p1y]);
var alt_delta = null;
var meters;

if (heightmap_data) {
alt_delta = heightmap_data[0];
meters = heightmap_data[1];
} else {
} else if (meters_to_px_ratio !== null) {
var dist = Math.sqrt(((marker.p0x - marker.p1x) ** 2) + ((marker.p0y - marker.p1y) ** 2));
meters = meters_to_px_ratio * dist;
} else {
return;
}

var milliradians = milliradians_from_meters(meters, alt_delta);
Expand Down

0 comments on commit fdad901

Please sign in to comment.