geolocation fix
This commit is contained in:
parent
062489f5ae
commit
aaad32c683
2 changed files with 32 additions and 17 deletions
|
|
@ -254,7 +254,7 @@ defmodule Aprsme.Is do
|
||||||
connected: connected,
|
connected: connected,
|
||||||
server: server_to_string(state.server),
|
server: server_to_string(state.server),
|
||||||
port: state.port,
|
port: state.port,
|
||||||
connected_at: if(connected, do: state.connected_at, else: nil),
|
connected_at: if(connected, do: state.connected_at),
|
||||||
uptime_seconds: if(connected, do: DateTime.diff(DateTime.utc_now(), state.connected_at), else: 0),
|
uptime_seconds: if(connected, do: DateTime.diff(DateTime.utc_now(), state.connected_at), else: 0),
|
||||||
login_id: state.login_params.user_id,
|
login_id: state.login_params.user_id,
|
||||||
filter: state.login_params.filter,
|
filter: state.login_params.filter,
|
||||||
|
|
@ -408,13 +408,13 @@ defmodule Aprsme.Is do
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
Logger.warning("Failed to login to APRS-IS: #{inspect(error)}, will retry in 10 seconds")
|
Logger.warning("Failed to login to APRS-IS: #{inspect(error)}, will retry in 10 seconds")
|
||||||
schedule_reconnect(10000)
|
schedule_reconnect(10_000)
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
Logger.warning("Unable to reconnect to APRS-IS: #{inspect(error)}, will retry in 10 seconds")
|
Logger.warning("Unable to reconnect to APRS-IS: #{inspect(error)}, will retry in 10 seconds")
|
||||||
schedule_reconnect(10000)
|
schedule_reconnect(10_000)
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -92,19 +92,24 @@ defmodule AprsmeWeb.MapLive.Index do
|
||||||
Logger.info("MapLive: Checking IP geolocation. Session data: #{inspect(session["ip_geolocation"])}")
|
Logger.info("MapLive: Checking IP geolocation. Session data: #{inspect(session["ip_geolocation"])}")
|
||||||
Logger.info("MapLive: URL params: #{inspect(params)}")
|
Logger.info("MapLive: URL params: #{inspect(params)}")
|
||||||
|
|
||||||
{map_center, map_zoom} =
|
# Check if URL params were explicitly provided (not just defaults)
|
||||||
|
has_explicit_url_params = params["lat"] || params["lng"] || params["z"]
|
||||||
|
|
||||||
|
{map_center, map_zoom, should_skip_initial_url_update} =
|
||||||
case session["ip_geolocation"] do
|
case session["ip_geolocation"] do
|
||||||
%{"lat" => lat, "lng" => lng} when is_number(lat) and is_number(lng) ->
|
%{"lat" => lat, "lng" => lng} when is_number(lat) and is_number(lng) ->
|
||||||
# Use IP geolocation if available and no URL params specified
|
if has_explicit_url_params do
|
||||||
if params["lat"] || params["lng"] do
|
# URL params explicitly provided - use them
|
||||||
# URL params take precedence
|
Logger.info(
|
||||||
Logger.info("MapLive: URL params present, using URL center: #{inspect(url_center)}, zoom: #{url_zoom}")
|
"MapLive: Explicit URL params present, using URL center: #{inspect(url_center)}, zoom: #{url_zoom}"
|
||||||
{url_center, url_zoom}
|
)
|
||||||
|
|
||||||
|
{url_center, url_zoom, false}
|
||||||
else
|
else
|
||||||
# Use IP geolocation with closer zoom
|
# No explicit URL params - use IP geolocation
|
||||||
geo_center = %{lat: lat, lng: lng}
|
geo_center = %{lat: lat, lng: lng}
|
||||||
Logger.info("MapLive: Using IP geolocation center: #{inspect(geo_center)}, zoom: 11")
|
Logger.info("MapLive: Using IP geolocation center: #{inspect(geo_center)}, zoom: 12")
|
||||||
{geo_center, 11}
|
{geo_center, 12, true}
|
||||||
end
|
end
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
|
@ -113,7 +118,8 @@ defmodule AprsmeWeb.MapLive.Index do
|
||||||
"MapLive: No IP geolocation found, using URL/default center: #{inspect(url_center)}, zoom: #{url_zoom}"
|
"MapLive: No IP geolocation found, using URL/default center: #{inspect(url_center)}, zoom: #{url_zoom}"
|
||||||
)
|
)
|
||||||
|
|
||||||
{url_center, url_zoom}
|
# Skip initial URL update if no explicit params were provided
|
||||||
|
{url_center, url_zoom, !has_explicit_url_params}
|
||||||
end
|
end
|
||||||
|
|
||||||
Logger.info("MapLive: Final map params - center: #{inspect(map_center)}, zoom: #{map_zoom}")
|
Logger.info("MapLive: Final map params - center: #{inspect(map_center)}, zoom: #{map_zoom}")
|
||||||
|
|
@ -139,6 +145,7 @@ defmodule AprsmeWeb.MapLive.Index do
|
||||||
map_bounds: initial_bounds,
|
map_bounds: initial_bounds,
|
||||||
map_center: map_center,
|
map_center: map_center,
|
||||||
map_zoom: map_zoom,
|
map_zoom: map_zoom,
|
||||||
|
should_skip_initial_url_update: should_skip_initial_url_update,
|
||||||
visible_packets: %{},
|
visible_packets: %{},
|
||||||
historical_packets: %{},
|
historical_packets: %{},
|
||||||
overlay_callsign: "",
|
overlay_callsign: "",
|
||||||
|
|
@ -450,10 +457,18 @@ defmodule AprsmeWeb.MapLive.Index do
|
||||||
socket
|
socket
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update URL without page reload
|
# Update URL without page reload, but skip on initial load if requested
|
||||||
new_path = "/?lat=#{lat}&lng=#{lng}&z=#{zoom}"
|
socket =
|
||||||
Logger.debug("Updating URL to: #{new_path}")
|
if socket.assigns[:should_skip_initial_url_update] && !socket.assigns[:initial_bounds_loaded] do
|
||||||
socket = push_patch(socket, to: new_path, replace: true)
|
# Skip URL update on initial load
|
||||||
|
Logger.debug("Skipping URL update on initial load")
|
||||||
|
# Clear the flag after first update
|
||||||
|
assign(socket, should_skip_initial_url_update: false)
|
||||||
|
else
|
||||||
|
new_path = "/?lat=#{lat}&lng=#{lng}&z=#{zoom}"
|
||||||
|
Logger.debug("Updating URL to: #{new_path}")
|
||||||
|
push_patch(socket, to: new_path, replace: true)
|
||||||
|
end
|
||||||
|
|
||||||
# If bounds are included, also process bounds update
|
# If bounds are included, also process bounds update
|
||||||
socket =
|
socket =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue