~ihabunek/triglav

41f7a32d04a648e231212ce4a11303e189396dc6 — Ivan Habunek 1 year, 7 months ago 897c77e leafleting
WIP
M assets/js/routes.js => assets/js/routes.js +14 -0
@@ 14,7 14,21 @@ const stops = JSON.parse(document.getElementById("stops-json").innerHTML)
const icon = new Icon({ iconUrl: "/images/stop.svg", iconSize: [14, 14] })

const waysGeoJSON = JSON.parse(document.getElementById("ways-geojson").innerHTML)
const platformsGeoJSON = JSON.parse(document.getElementById("platforms-geojson").innerHTML)

const stylePlatform = (feature) => ({
  "color": "#ff7800",
  "weight": 5,
  "opacity": 0.65,
  icon: icon
})

const platformToLayer = (feature, latlng) => {
  return L.marker(latlng, {icon: icon});
}

L.geoJSON(waysGeoJSON).addTo(map)
L.geoJSON(platformsGeoJSON, { pointToLayer: platformToLayer }).addTo(map)

const markers = []
for (const stop of stops) {

A assets/static/images/blue_square.svg => assets/static/images/blue_square.svg +0 -0
M lib/triglav_web/controllers/zet/routes_controller.ex => lib/triglav_web/controllers/zet/routes_controller.ex +29 -5
@@ 69,7 69,8 @@ defmodule TriglavWeb.Zet.RoutesController do
      relations
      |> Enum.map(& &1.id)
      |> Osmosis.list_platform_members()
      |> Enum.group_by(& &1.relation_id)

    platform_members_grouped = Enum.group_by(platform_members, & &1.relation_id)

    relations_by_stop_ids =
      for relation <- relations, Relation.is_route(relation), into: %{} do


@@ 91,9 92,8 @@ defmodule TriglavWeb.Zet.RoutesController do
      |> Enum.map(&Map.take(&1, [:id, :name, :lat, :lon]))
      |> Jason.encode!()

    ways_geojson =
      ways_geojson_feature_collection(relations)
      |> Jason.encode!()
    ways_geojson = ways_geojson_feature_collection(relations) |> Jason.encode!()
    platforms_geojson = platforms_geojson_feature_collection(platform_members) |> Jason.encode!()

    render(conn, "detail.html",
      conn: conn,


@@ 105,7 105,8 @@ defmodule TriglavWeb.Zet.RoutesController do
      trips: grouped_trips,
      stops_json: stops_json,
      ways_geojson: ways_geojson,
      platform_members: platform_members
      platforms_geojson: platforms_geojson,
      platform_members: platform_members_grouped
    )
  end



@@ 134,6 135,29 @@ defmodule TriglavWeb.Zet.RoutesController do
    }
  end

  defp platforms_geojson_feature_collection(platform_members) do
    features =
      for member <- platform_members do
        %{
          type: "Feature",
          properties: %{
            name: member.member.tags["name"],
            gtfs_stop_id: member.member.tags["gtfs:stop_id"]
          },
          geometry: %{
            type: "Point",
            coordinates: Tuple.to_list(member.member.geom.coordinates)
          }
        }
      end

    %{
      type: "FeatureCollection",
      features: features
    }
    |> IO.inspect()
  end

  def group_errors_by_relation(errors) do
    {errors, rel_errors} = Enum.split_with(errors, &is_nil(&1.relation_id))


M lib/triglav_web/templates/zet/routes/detail.html.eex => lib/triglav_web/templates/zet/routes/detail.html.eex +6 -2
@@ 1,4 1,4 @@
<link rel="stylesheet" type="text/css" href="<%= Routes.static_path(@conn, "/css/routes.css") %>">
<link rel="stylesheet" type="text/css" href="<%= static_path("/css/routes.css") %>">

<style type="text/css">
  #routes-map {


@@ 15,6 15,10 @@
  <%= raw(@ways_geojson) %>
</script>

<script id="platforms-geojson" type="application/json">
  <%= raw(@platforms_geojson) %>
</script>

<main role="main" class="container-wide">
  <h1>#<%= @route.id %>: <%= @route.long_name %></h1>



@@ 152,4 156,4 @@
  <% end %>
</main>

<script defer type="text/javascript" src="<%= Routes.static_path(@conn, "/js/routes.js") %>"></script>
<script defer type="text/javascript" src="<%= static_path("/js/routes.js") %>"></script>