neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
Draw a Plani's bikes without taking the page down
47ac060 · Gabriel Morell · 2026-09-03 19:16
Message
{commit_body(@commit)}
Files changed
modified
apps/room_sanctum/lib/room_sanctum_web/components/query_geospatial_map.ex
+17
−6
@@ -790,6 +790,17 @@ defmodule RoomSanctumWeb.Components.QueryGeospatialMap do
| 790 | 790 | end) |
| 791 | 791 | end |
| 792 | 792 | |
| 793 | + # Where a bike is, whichever key its caller had one under. | |
| 794 | + # | |
| 795 | + # The two layers of this component disagree: a free bike carries `point`, | |
| 796 | + # after the column on `gbfs_free_bike_status`, and a station carries `place`. | |
| 797 | + # A caller with markers for both layers has to satisfy both, and dot access | |
| 798 | + # on the one it did not use raises rather than reading nil -- which took the | |
| 799 | + # whole Plani page down over a marker it could have drawn from `lat`/`lon` | |
| 800 | + # anyway. The rest of this function was already reading its optional fields | |
| 801 | + # with `Map.get`; these two were the exception. | |
| 802 | + defp point_of(bike), do: Map.get(bike, :point) || Map.get(bike, :place) | |
| 803 | + | |
| 793 | 804 | # Format free bikes for map display |
| 794 | 805 | defp format_free_bikes(free_bikes) do |
| 795 | 806 | # A feed declares how far each of its vehicle types can go -- Bay Wheels |
@@ -798,18 +809,18 @@ defmodule RoomSanctumWeb.Components.QueryGeospatialMap do
| 798 | 809 | vehicle_types = vehicle_types_for(free_bikes) |
| 799 | 810 | |
| 800 | 811 | free_bikes |
| 801 | − |> Enum.filter(fn bike -> | |
| 802 | − (bike.point != nil) || (bike.lat != nil && bike.lon != nil) | |
| 812 | + |> Enum.filter(fn bike -> | |
| 813 | + point_of(bike) != nil || (Map.get(bike, :lat) != nil && Map.get(bike, :lon) != nil) | |
| 803 | 814 | end) |
| 804 | 815 | |> Enum.map(fn bike -> |
| 805 | 816 | {lat, lng} = cond do |
| 806 | − bike.point != nil -> | |
| 807 | − case bike.point do | |
| 817 | + point_of(bike) != nil -> | |
| 818 | + case point_of(bike) do | |
| 808 | 819 | %Geo.Point{coordinates: {lng, lat}} -> {lat, lng} |
| 809 | 820 | _ -> {0, 0} |
| 810 | 821 | end |
| 811 | − bike.lat != nil && bike.lon != nil -> | |
| 812 | − {bike.lat, bike.lon} | |
| 822 | + Map.get(bike, :lat) != nil && Map.get(bike, :lon) != nil -> | |
| 823 | + {Map.get(bike, :lat), Map.get(bike, :lon)} | |
| 813 | 824 | true -> {0, 0} |
| 814 | 825 | end |
| 815 | 826 |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_plani_live/show.ex
+7
−1
@@ -124,8 +124,14 @@ defmodule RoomSanctumWeb.PlaniLive.Show do
| 124 | 124 | defp marker_layer(_kind), do: :stations |
| 125 | 125 | |
| 126 | 126 | defp as_marker(place) do |
| 127 | + point = %Geo.Point{coordinates: {place.lon, place.lat}, srid: 4326} | |
| 128 | + | |
| 127 | 129 | %{ |
| 128 | − place: %Geo.Point{coordinates: {place.lon, place.lat}, srid: 4326}, | |
| 130 | + # Both, because the two layers of the map component name this | |
| 131 | + # differently -- a station has a `place`, a free bike has a `point` -- | |
| 132 | + # and these markers go to whichever layer their kind belongs to. | |
| 133 | + place: point, | |
| 134 | + point: point, | |
| 129 | 135 | station_id: "#{place.source_id}-#{place.name}", |
| 130 | 136 | bike_id: "#{place.source_id}-#{place.name}", |
| 131 | 137 | name: place.name, |
Parents: 3402380