diff --git a/assets/js/map.ts b/assets/js/map.ts index 3668c1e..6bc9b36 100644 --- a/assets/js/map.ts +++ b/assets/js/map.ts @@ -560,13 +560,15 @@ let MapAPRSMap = { } // Add the new marker as the most recent for this callsign + // Check if openPopup is explicitly set to false to prevent interrupting user + const shouldOpenPopup = data.openPopup !== false; self.addMarker({ ...data, historical: false, is_most_recent_for_callsign: true, callsign_group: data.callsign_group || data.callsign || incomingCallsign, popup: data.popup || self.buildPopupContent(data), - openPopup: true, + openPopup: shouldOpenPopup, }); }); @@ -807,6 +809,11 @@ let MapAPRSMap = { // Add popup if content provided if (data.popup) { marker.bindPopup(data.popup, { autoPan: false }); + + // Handle popup close events for all popups + marker.on("popupclose", () => { + self.pushEvent("popup_closed", {}); + }); } // Handle marker click @@ -820,6 +827,11 @@ let MapAPRSMap = { }); }); + // Handle popup close events + marker.on("popupclose", () => { + self.pushEvent("popup_closed", {}); + }); + // Mark historical markers for identification if (data.historical) { (marker as any)._isHistorical = true; diff --git a/lib/aprsme_web/live/map_live/index.ex b/lib/aprsme_web/live/map_live/index.ex index a1279b1..6568d2a 100644 --- a/lib/aprsme_web/live/map_live/index.ex +++ b/lib/aprsme_web/live/map_live/index.ex @@ -33,7 +33,7 @@ defmodule AprsmeWeb.MapLive.Index do socket = assign_defaults(socket, one_hour_ago) socket = assign(socket, packet_buffer: [], buffer_timer: nil) - socket = assign(socket, all_packets: %{}) + socket = assign(socket, all_packets: %{}, station_popup_open: false) if connected?(socket) do Endpoint.subscribe("aprs_messages") @@ -66,6 +66,7 @@ defmodule AprsmeWeb.MapLive.Index do packets: [], page_title: "APRS Map", visible_packets: %{}, + station_popup_open: false, map_bounds: %{ north: 49.0, south: 24.0, @@ -184,7 +185,8 @@ defmodule AprsmeWeb.MapLive.Index do @impl true def handle_event("marker_clicked", _params, socket) do - {:noreply, socket} + # When a marker is clicked, mark that a station popup is open + {:noreply, assign(socket, station_popup_open: true)} end @impl true @@ -252,6 +254,12 @@ defmodule AprsmeWeb.MapLive.Index do {:noreply, socket} end + @impl true + def handle_event("popup_closed", _params, socket) do + # When any popup is closed, mark that no station popup is open + {:noreply, assign(socket, station_popup_open: false)} + end + @impl true def handle_event("get_assigns", _params, socket) do send(self(), {:test_assigns, socket.assigns}) @@ -405,7 +413,13 @@ defmodule AprsmeWeb.MapLive.Index do socket = if marker_data do - push_event(socket, "new_packet", marker_data) + # Only show new packet popup if no station popup is currently open + if socket.assigns.station_popup_open do + # Send without opening popup to avoid interrupting user + push_event(socket, "new_packet", Map.put(marker_data, :openPopup, false)) + else + push_event(socket, "new_packet", marker_data) + end else socket end