Skip to content

Commit 213648e

Browse files
committed
Change AIS ship symbol to point in direction of heading
1 parent 63eedd0 commit 213648e

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

src/local_pathfinding/local_pathfinding/visualizer.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(self, msgs: List[ci.LPathData]):
8989
self.ais_ship_ids = [ship.id for ship in self.ais_ships]
9090
ais_ship_xy = cs.latlon_list_to_xy_list(self.reference_latlon, ais_ship_latlons)
9191
self.ais_pos_x, self.ais_pos_y = self._split_coordinates(ais_ship_xy)
92+
self.ais_headings = [ship.cog.heading for ship in self.ais_ships]
9293

9394
# TODO: Include other LPathData attributes for plotting their data
9495

@@ -516,21 +517,33 @@ def live_update_plot(state: VisualizerState) -> go.Figure:
516517
y_max = max(state.final_local_wp_y) + 10
517518

518519
# Display AIS Ships
519-
ais_trace = go.Scatter(
520-
x=state.ais_pos_x,
521-
y=state.ais_pos_y,
522-
mode="markers",
523-
name="AIS Ship",
524-
marker=dict(color="orange", size=10, symbol="diamond"),
525-
text=[f"ID: {id}" for id in state.ais_ship_ids],
526-
hovertemplate=(
527-
"<b>🚢 AIS Ship</b><br>"
528-
"X: %{x:.2f}<br>"
529-
"Y: %{y:.2f}<br>"
530-
"%{text}<extra></extra>"
531-
),
532-
)
533-
fig.add_trace(ais_trace)
520+
for x_val, y_val, heading, ais_id in zip(
521+
state.ais_pos_x, state.ais_pos_y, state.ais_headings, state.ais_ship_ids
522+
):
523+
fig.add_trace(
524+
go.Scatter(
525+
x=[x_val],
526+
y=[y_val],
527+
mode="markers",
528+
name=f"AIS {str(ais_id)}",
529+
hovertemplate=(
530+
f"<b>🚢 AIS Ship {str(ais_id)}</b><br>"
531+
f"X: {x_val:.2f}<br>"
532+
f"Y: {y_val:.2f}<br>"
533+
f"Heading: {heading:.1f}°<extra></extra>"
534+
),
535+
marker=dict(
536+
symbol="arrow-wide",
537+
line_color="orange",
538+
color="orange",
539+
line_width=2,
540+
size=15,
541+
angleref="up",
542+
angle=cs.true_bearing_to_plotly_cartesian(heading),
543+
),
544+
showlegend=False,
545+
)
546+
)
534547

535548
# Update Layout
536549
fig.update_layout(
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id,latitude,longitude,heading,speed,rot,width,height
2-
1,49.01261318191024,-135.65593922412154,90.0,1.0,1,1.0,1.0
3-
2,48.67919212345747,-132.94724986187234,90.0,15.0,2,2.0,2.0
4-
3,48.11352031871804,-135.67990496461405,30,20.0,3,3,3.0
5-
4,48.1970229368345,-128.93710143805356,4.0,4.0,4,4.0,4.0
6-
5,48.51027819947852,-126.15925374786544,5.0,5.0,5,5.0,5.0
2+
1,49.01261318191024,-135.65593922412154,90.0,40.0,30,1.0,1.0
3+
2,48.67919212345747,-132.94724986187234,90.0,40.0,50,2.0,2.0
4+
3,48.11352031871804,-135.67990496461405,30,80.0,-50,3,3.0
5+
4,48.1970229368345,-128.93710143805356,4.0,20.0,-30,4.0,4.0
6+
5,48.51027819947852,-126.15925374786544,5.0,10.0,20,5.0,5.0

0 commit comments

Comments
 (0)