map bounds fix
This commit is contained in:
parent
f3ca970174
commit
1e22a54e47
3 changed files with 78 additions and 93 deletions
|
|
@ -6,9 +6,9 @@ defmodule Aprs.Release do
|
||||||
@app :aprs
|
@app :aprs
|
||||||
|
|
||||||
def migrate do
|
def migrate do
|
||||||
|
require Logger
|
||||||
# Initialize deployment timestamp first
|
# Initialize deployment timestamp first
|
||||||
deployed_at = init()
|
deployed_at = init()
|
||||||
require Logger
|
|
||||||
Logger.info("Deployment timestamp: #{deployed_at}")
|
Logger.info("Deployment timestamp: #{deployed_at}")
|
||||||
|
|
||||||
# Run migrations
|
# Run migrations
|
||||||
|
|
@ -20,10 +20,6 @@ defmodule Aprs.Release do
|
||||||
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp repos do
|
|
||||||
Application.fetch_env!(@app, :ecto_repos)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp load_app do
|
defp load_app do
|
||||||
Application.load(@app)
|
Application.load(@app)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -143,18 +143,14 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("bounds_changed", %{"bounds" => bounds}, socket) do
|
def handle_event("bounds_changed", %{"bounds" => bounds}, socket) do
|
||||||
Logger.debug(
|
Logger.debug("handle_event bounds_changed: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}")
|
||||||
"handle_event bounds_changed: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
handle_bounds_update(bounds, socket)
|
handle_bounds_update(bounds, socket)
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("update_bounds", %{"bounds" => bounds}, socket) do
|
def handle_event("update_bounds", %{"bounds" => bounds}, socket) do
|
||||||
Logger.debug(
|
Logger.debug("handle_event update_bounds: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}")
|
||||||
"handle_event update_bounds: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
handle_bounds_update(bounds, socket)
|
handle_bounds_update(bounds, socket)
|
||||||
end
|
end
|
||||||
|
|
@ -318,9 +314,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
west: bounds["west"]
|
west: bounds["west"]
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.debug(
|
Logger.debug("handle_bounds_update: new #{inspect(map_bounds)} vs current #{inspect(socket.assigns.map_bounds)}")
|
||||||
"handle_bounds_update: new #{inspect(map_bounds)} vs current #{inspect(socket.assigns.map_bounds)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Validate bounds to prevent invalid coordinates
|
# Validate bounds to prevent invalid coordinates
|
||||||
if map_bounds.north > 90 or map_bounds.south < -90 or
|
if map_bounds.north > 90 or map_bounds.south < -90 or
|
||||||
|
|
@ -346,9 +340,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
|
|
||||||
@spec process_bounds_update(map(), Socket.t()) :: Socket.t()
|
@spec process_bounds_update(map(), Socket.t()) :: Socket.t()
|
||||||
defp process_bounds_update(map_bounds, socket) do
|
defp process_bounds_update(map_bounds, socket) do
|
||||||
Logger.debug(
|
Logger.debug("process_bounds_update: Loading historical packets for bounds #{inspect(map_bounds)}")
|
||||||
"process_bounds_update: Loading historical packets for bounds #{inspect(map_bounds)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Remove out-of-bounds packets and markers immediately
|
# Remove out-of-bounds packets and markers immediately
|
||||||
new_visible_packets =
|
new_visible_packets =
|
||||||
|
|
@ -382,30 +374,22 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:process_bounds_update, map_bounds}, socket),
|
def handle_info({:process_bounds_update, map_bounds}, socket), do: handle_info_process_bounds_update(map_bounds, socket)
|
||||||
do: handle_info_process_bounds_update(map_bounds, socket)
|
|
||||||
|
|
||||||
def handle_info({:delayed_zoom, %{lat: lat, lng: lng}}, socket),
|
def handle_info({:delayed_zoom, %{lat: lat, lng: lng}}, socket), do: handle_info_delayed_zoom(lat, lng, socket)
|
||||||
do: handle_info_delayed_zoom(lat, lng, socket)
|
|
||||||
|
|
||||||
def handle_info({:ip_location, %{lat: lat, lng: lng}}, socket),
|
def handle_info({:ip_location, %{lat: lat, lng: lng}}, socket), do: handle_info_ip_location(lat, lng, socket)
|
||||||
do: handle_info_ip_location(lat, lng, socket)
|
|
||||||
|
|
||||||
def handle_info(:initialize_replay, socket), do: handle_info_initialize_replay(socket)
|
def handle_info(:initialize_replay, socket), do: handle_info_initialize_replay(socket)
|
||||||
|
|
||||||
def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket)
|
def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket)
|
||||||
|
|
||||||
def handle_info(:reload_historical_packets, socket),
|
def handle_info(:reload_historical_packets, socket), do: handle_reload_historical_packets(socket)
|
||||||
do: handle_reload_historical_packets(socket)
|
|
||||||
|
|
||||||
def handle_info({:postgres_packet, packet}, socket),
|
def handle_info({:postgres_packet, packet}, socket), do: handle_info_postgres_packet(packet, socket)
|
||||||
do: handle_info_postgres_packet(packet, socket)
|
|
||||||
|
|
||||||
def handle_info(
|
def handle_info(%Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet}, socket),
|
||||||
%Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet},
|
do: handle_info({:postgres_packet, packet}, socket)
|
||||||
socket
|
|
||||||
),
|
|
||||||
do: handle_info({:postgres_packet, packet}, socket)
|
|
||||||
|
|
||||||
# Private handler functions for each message type
|
# Private handler functions for each message type
|
||||||
|
|
||||||
|
|
@ -753,7 +737,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
</svg>
|
</svg>
|
||||||
<h2 class="text-xl font-bold">APRS.me</h2>
|
<h2 class="text-xl font-bold">APRS.me</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Close button for mobile -->
|
<!-- Close button for mobile -->
|
||||||
<button
|
<button
|
||||||
class="lg:hidden text-white hover:text-slate-200 transition-colors"
|
class="lg:hidden text-white hover:text-slate-200 transition-colors"
|
||||||
|
|
@ -776,7 +760,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<div class="p-6 space-y-6 bg-slate-50 flex-1 overflow-y-auto">
|
<div class="p-6 space-y-6 bg-slate-50 flex-1 overflow-y-auto">
|
||||||
<!-- Callsign Search -->
|
<!-- Callsign Search -->
|
||||||
|
|
@ -809,7 +793,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Trail Duration -->
|
<!-- Trail Duration -->
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<label class="block text-sm font-semibold text-slate-700 flex items-center space-x-2">
|
<label class="block text-sm font-semibold text-slate-700 flex items-center space-x-2">
|
||||||
|
|
@ -868,7 +852,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
<span>How long should position trails be displayed</span>
|
<span>How long should position trails be displayed</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Historical Data -->
|
<!-- Historical Data -->
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<label class="block text-sm font-semibold text-slate-700 flex items-center space-x-2">
|
<label class="block text-sm font-semibold text-slate-700 flex items-center space-x-2">
|
||||||
|
|
@ -921,7 +905,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
<span>How many hours of historical packets to load</span>
|
<span>How many hours of historical packets to load</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Navigation Links (Mobile) -->
|
<!-- Navigation Links (Mobile) -->
|
||||||
<div class="lg:hidden pt-4 border-t border-slate-200 space-y-3">
|
<div class="lg:hidden pt-4 border-t border-slate-200 space-y-3">
|
||||||
<.link
|
<.link
|
||||||
|
|
@ -953,7 +937,7 @@ defmodule AprsWeb.MapLive.Index do
|
||||||
<span>View Bad Packets</span>
|
<span>View Bad Packets</span>
|
||||||
</.link>
|
</.link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Deployment Information -->
|
<!-- Deployment Information -->
|
||||||
<div class="pt-4 border-t border-slate-200 space-y-3">
|
<div class="pt-4 border-t border-slate-200 space-y-3">
|
||||||
<div class="flex items-center space-x-2 text-sm text-slate-600">
|
<div class="flex items-center space-x-2 text-sm text-slate-600">
|
||||||
|
|
|
||||||
|
|
@ -52,67 +52,72 @@ defmodule AprsWeb.MapLive.MapHelpers do
|
||||||
|
|
||||||
@spec within_bounds?(map() | tuple(), map()) :: boolean()
|
@spec within_bounds?(map() | tuple(), map()) :: boolean()
|
||||||
def within_bounds?(packet_or_coords, bounds) do
|
def within_bounds?(packet_or_coords, bounds) do
|
||||||
to_float = fn
|
# Handle nil bounds
|
||||||
n when is_float(n) ->
|
if is_nil(bounds) do
|
||||||
n
|
|
||||||
|
|
||||||
n when is_integer(n) ->
|
|
||||||
n * 1.0
|
|
||||||
|
|
||||||
%Decimal{} = d ->
|
|
||||||
Decimal.to_float(d)
|
|
||||||
|
|
||||||
n when is_binary(n) ->
|
|
||||||
case Float.parse(n) do
|
|
||||||
{f, _} -> f
|
|
||||||
:error -> 0.0
|
|
||||||
end
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
0.0
|
|
||||||
end
|
|
||||||
|
|
||||||
{lat, lon} =
|
|
||||||
cond do
|
|
||||||
is_map(packet_or_coords) and Map.has_key?(packet_or_coords, :lat) and
|
|
||||||
Map.has_key?(packet_or_coords, :lon) ->
|
|
||||||
{packet_or_coords.lat, packet_or_coords.lon}
|
|
||||||
|
|
||||||
is_map(packet_or_coords) and Map.has_key?(packet_or_coords, "lat") and
|
|
||||||
Map.has_key?(packet_or_coords, "lon") ->
|
|
||||||
{packet_or_coords["lat"], packet_or_coords["lon"]}
|
|
||||||
|
|
||||||
is_map(packet_or_coords) and Map.has_key?(packet_or_coords, :latitude) and
|
|
||||||
Map.has_key?(packet_or_coords, :longitude) ->
|
|
||||||
{packet_or_coords.latitude, packet_or_coords.longitude}
|
|
||||||
|
|
||||||
is_tuple(packet_or_coords) and tuple_size(packet_or_coords) == 2 ->
|
|
||||||
packet_or_coords
|
|
||||||
|
|
||||||
true ->
|
|
||||||
{nil, nil}
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_nil(lat) or is_nil(lon) do
|
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
lat = to_float.(lat)
|
to_float = fn
|
||||||
lon = to_float.(lon)
|
n when is_float(n) ->
|
||||||
south = to_float.(bounds.south)
|
n
|
||||||
north = to_float.(bounds.north)
|
|
||||||
west = to_float.(bounds.west)
|
|
||||||
east = to_float.(bounds.east)
|
|
||||||
|
|
||||||
lat_in_bounds = lat >= south && lat <= north
|
n when is_integer(n) ->
|
||||||
|
n * 1.0
|
||||||
|
|
||||||
lng_in_bounds =
|
%Decimal{} = d ->
|
||||||
if west <= east do
|
Decimal.to_float(d)
|
||||||
lon >= west && lon <= east
|
|
||||||
else
|
n when is_binary(n) ->
|
||||||
lon >= west || lon <= east
|
case Float.parse(n) do
|
||||||
|
{f, _} -> f
|
||||||
|
:error -> 0.0
|
||||||
|
end
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
0.0
|
||||||
|
end
|
||||||
|
|
||||||
|
{lat, lon} =
|
||||||
|
cond do
|
||||||
|
is_map(packet_or_coords) and Map.has_key?(packet_or_coords, :lat) and
|
||||||
|
Map.has_key?(packet_or_coords, :lon) ->
|
||||||
|
{packet_or_coords.lat, packet_or_coords.lon}
|
||||||
|
|
||||||
|
is_map(packet_or_coords) and Map.has_key?(packet_or_coords, "lat") and
|
||||||
|
Map.has_key?(packet_or_coords, "lon") ->
|
||||||
|
{packet_or_coords["lat"], packet_or_coords["lon"]}
|
||||||
|
|
||||||
|
is_map(packet_or_coords) and Map.has_key?(packet_or_coords, :latitude) and
|
||||||
|
Map.has_key?(packet_or_coords, :longitude) ->
|
||||||
|
{packet_or_coords.latitude, packet_or_coords.longitude}
|
||||||
|
|
||||||
|
is_tuple(packet_or_coords) and tuple_size(packet_or_coords) == 2 ->
|
||||||
|
packet_or_coords
|
||||||
|
|
||||||
|
true ->
|
||||||
|
{nil, nil}
|
||||||
end
|
end
|
||||||
|
|
||||||
lat_in_bounds && lng_in_bounds
|
if is_nil(lat) or is_nil(lon) do
|
||||||
|
false
|
||||||
|
else
|
||||||
|
lat = to_float.(lat)
|
||||||
|
lon = to_float.(lon)
|
||||||
|
south = to_float.(bounds.south)
|
||||||
|
north = to_float.(bounds.north)
|
||||||
|
west = to_float.(bounds.west)
|
||||||
|
east = to_float.(bounds.east)
|
||||||
|
|
||||||
|
lat_in_bounds = lat >= south && lat <= north
|
||||||
|
|
||||||
|
lng_in_bounds =
|
||||||
|
if west <= east do
|
||||||
|
lon >= west && lon <= east
|
||||||
|
else
|
||||||
|
lon >= west || lon <= east
|
||||||
|
end
|
||||||
|
|
||||||
|
lat_in_bounds && lng_in_bounds
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue