diff --git a/assets/js/map.ts b/assets/js/map.ts index 9450779..162eab5 100644 --- a/assets/js/map.ts +++ b/assets/js/map.ts @@ -558,7 +558,7 @@ let MapAPRSMap = { historical: false, is_most_recent_for_callsign: true, callsign_group: data.callsign_group || data.callsign || incomingCallsign, - popup: self.buildPopupContent(data), + popup: data.popup || self.buildPopupContent(data), openPopup: true, }); }); @@ -589,7 +589,7 @@ let MapAPRSMap = { self.addMarker({ ...data, historical: true, - popup: self.buildPopupContent(data), + popup: data.popup || self.buildPopupContent(data), }); }); @@ -629,7 +629,7 @@ let MapAPRSMap = { self.addMarker({ ...packet, historical: true, - popup: self.buildPopupContent(packet), + popup: packet.popup || self.buildPopupContent(packet), }); }); }); @@ -1069,12 +1069,6 @@ let MapAPRSMap = { content += `
${comment}
`; } - if (data.lat && data.lng) { - content += `
- ${data.lat.toFixed(4)}, ${data.lng.toFixed(4)} -
`; - } - if (data.timestamp) { let date; if (typeof data.timestamp === "number") { diff --git a/lib/aprs_web/live/map_live/callsign_view.ex b/lib/aprs_web/live/map_live/callsign_view.ex index b715b16..c261c4b 100644 --- a/lib/aprs_web/live/map_live/callsign_view.ex +++ b/lib/aprs_web/live/map_live/callsign_view.ex @@ -68,8 +68,7 @@ defmodule AprsWeb.MapLive.CallsignView do # Don't load packets here - wait for map_ready event # socket = load_callsign_packets(socket, normalized_callsign) - # Schedule regular cleanup of old packets from the map - Process.send_after(self(), :cleanup_old_packets, 60_000) + # No longer need scheduled cleanup - packets are cleaned up automatically when new ones arrive # Auto-start replay after a short delay Process.send_after(self(), :auto_start_replay, 2000) @@ -192,6 +191,9 @@ defmodule AprsWeb.MapLive.CallsignView do west: to_float(bounds["west"]) } + # Clean up old packets first + socket = cleanup_old_packets(socket) + # Remove out-of-bounds visible packets new_visible_packets = socket.assigns.visible_packets @@ -264,7 +266,6 @@ defmodule AprsWeb.MapLive.CallsignView do end def handle_info(:replay_next_packet, socket), do: handle_replay_next_packet(socket) - def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket) def handle_info(%Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet}, socket) do # Only process packets for the specific callsign being viewed @@ -280,6 +281,9 @@ defmodule AprsWeb.MapLive.CallsignView do def handle_info(_msg, socket), do: {:noreply, socket} defp handle_info_postgres_packet(packet, socket) do + # Clean up old packets before adding the new one + socket = cleanup_old_packets(socket) + key = System.unique_integer([:positive]) updated_visible_packets = Map.put(socket.assigns.visible_packets, key, packet) socket = assign(socket, visible_packets: updated_visible_packets) @@ -625,19 +629,16 @@ defmodule AprsWeb.MapLive.CallsignView do """ end - defp handle_cleanup_old_packets(socket) do - # Schedule next cleanup - Process.send_after(self(), :cleanup_old_packets, 60_000) - + defp cleanup_old_packets(socket, age_threshold_seconds \\ 3600) do # Update packet age threshold - one_hour_ago = DateTime.add(DateTime.utc_now(), -3600, :second) - socket = assign(socket, packet_age_threshold: one_hour_ago) + threshold_time = DateTime.add(DateTime.utc_now(), -age_threshold_seconds, :second) + socket = assign(socket, packet_age_threshold: threshold_time) # Remove expired packets from visible_packets expired_keys = socket.assigns.visible_packets |> Enum.filter(fn {_key, packet} -> - not packet_within_time_threshold?(packet, one_hour_ago) + not packet_within_time_threshold?(packet, threshold_time) end) |> Enum.map(fn {key, _} -> key end) @@ -653,9 +654,7 @@ defmodule AprsWeb.MapLive.CallsignView do # Use Map.drop/2 for better performance updated_visible_packets = Map.drop(socket.assigns.visible_packets, expired_keys) - socket = assign(socket, visible_packets: updated_visible_packets) - - {:noreply, socket} + assign(socket, visible_packets: updated_visible_packets) end defp packet_within_time_threshold?(packet, threshold) do @@ -867,6 +866,9 @@ defmodule AprsWeb.MapLive.CallsignView do visible_packets = build_visible_packets(latest_packet) socket = maybe_push_latest_marker(socket, latest_packet) + # Clean up old packets before assigning new visible packets + socket = cleanup_old_packets(socket) + assign(socket, last_known_position: last_known_position, visible_packets: visible_packets, diff --git a/lib/aprs_web/live/map_live/packet_utils.ex b/lib/aprs_web/live/map_live/packet_utils.ex index 84569e7..7da4290 100644 --- a/lib/aprs_web/live/map_live/packet_utils.ex +++ b/lib/aprs_web/live/map_live/packet_utils.ex @@ -180,7 +180,7 @@ defmodule AprsWeb.MapLive.PacketUtils do end end - defp build_standard_popup_html(packet_info, lat, lon) do + defp build_standard_popup_html(packet_info, _lat, _lon) do comment_html = if packet_info.comment == "", do: "", @@ -204,7 +204,6 @@ defmodule AprsWeb.MapLive.PacketUtils do
#{packet_info.callsign}
#{comment_html} -
#{Float.round(to_float(lat), 4)}, #{Float.round(to_float(lon), 4)}
#{timestamp_html}
""" @@ -217,9 +216,9 @@ defmodule AprsWeb.MapLive.PacketUtils do timestamp_html = if timestamp_dt do """ -
-
#{TimeHelpers.time_ago_in_words(timestamp_dt)}
-
#{Calendar.strftime(timestamp_dt, "%Y-%m-%d %H:%M:%S UTC")}
+
+
#{TimeHelpers.time_ago_in_words(timestamp_dt)}
+
#{Calendar.strftime(timestamp_dt, "%Y-%m-%d %H:%M:%S UTC")}
""" else