~ihabunek/triglav

b9ed8f9b1619d01a601e9656a927e6dc00b2cacc — Ivan Habunek 1 year, 23 days ago 6d637d6
Add JOSM remote for zooming to stop
M assets/css/app.scss => assets/css/app.scss +1 -0
@@ 135,6 135,7 @@ a.josm-remote {
.green { color: $green; }
.tag { color: DimGray; white-space: nowrap; }
.smaller { font-size: 0.9rem; }
.hidden { visibility: hidden; }

// Phoenix crap


M lib/triglav/josm.ex => lib/triglav/josm.ex +13 -4
@@ 14,10 14,6 @@ defmodule Triglav.Josm do

  @base "http://127.0.0.1:8111"

  defp url(path, params) do
    "#{@base}#{path}?#{URI.encode_query(params)}"
  end

  @spec load_object(object, options) :: String.t()
  def load_object(object, opts \\ []) do
    load_objects([object], opts)


@@ 34,6 30,19 @@ defmodule Triglav.Josm do
    })
  end

  def zoom(lat, lon) do
    url("/zoom", %{
      top: lat,
      bottom: lat,
      left: lon,
      right: lon
    })
  end

  defp url(path, params) do
    "#{@base}#{path}?#{URI.encode_query(params)}"
  end

  defp object_ids(objects) do
    objects
    |> Enum.map(&object_id/1)

M lib/triglav/zet/gtfs.ex => lib/triglav/zet/gtfs.ex +1 -1
@@ 25,7 25,7 @@ defmodule Triglav.Zet.Gtfs do
          SELECT t.trip_id,
                 t.direction_id,
                 array_agg(
                   ARRAY[s.stop_id, s.stop_name, st.stop_sequence::text]
                   row(s.stop_id, s.stop_name, s.stop_lat, s.stop_lon, st.stop_sequence::text)
                   ORDER BY st.stop_sequence
                 ) AS stops
          FROM gtfs.stop_times st

M lib/triglav_web/templates/zet/routes/detail.html.eex => lib/triglav_web/templates/zet/routes/detail.html.eex +6 -4
@@ 5,9 5,7 @@

  <section>
    <%= render_relation_hierarchy(@hierarchy) %>
    <a class="josm-remote" href="<%= Triglav.Josm.load_objects(@relations) %>" target="_blank">
      Open in JOSM
    </a>
    <%= josm_load_objects(@relations) %>
  </section>

  <%= if length(@errors) > 0 or map_size(@rel_errors) > 0 do %>


@@ 61,14 59,16 @@
                <th>#</th>
                <th>ID</th>
                <th>Name</th>
                <th>⌖</th>
              </tr>
            </thead>
            <tbody>
              <%= for [id, name, ord] <- trip["stops"] do %>
              <%= for {id, name, lat, lon, ord} <- trip["stops"] do %>
              <tr>
                <td><%= ord %>.</td>
                <td><%= id %></td>
                <td><%= name %></td>
                <td><%= josm_zoom(lat, lon) %></td>
              </tr>
              <% end %>
            </tbody>


@@ 77,4 77,6 @@
      <% end %>
    </div>
  <% end %>

  <iframe name="josm" class="hidden"></iframe>
</main>

M lib/triglav_web/views/osm_helpers.ex => lib/triglav_web/views/osm_helpers.ex +9 -1
@@ 48,9 48,17 @@ defmodule TriglavWeb.OsmHelpers do
    link = Triglav.Josm.load_objects(objects)

    ~E"""
    <a class="josm-remote" href="<%= link %>" target="_blank">
    <a class="josm-remote" href="<%= link %>" target="josm">
      Open in JOSM
    </a>
    """
  end

  def josm_zoom(lat, lon) do
    link = Triglav.Josm.zoom(lat, lon)

    ~E"""
    <a href="<%= link %>" class="josm-remote" title="Open in JOSM" target="josm">⌖</a>
    """
  end
end