Show station and airport icons on the map
This commit is contained in:
		
							parent
							
								
									0c02d9c899
								
							
						
					
					
						commit
						4b8b1f7556
					
				| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
 | 
			
		||||
{% block style %}
 | 
			
		||||
 | 
			
		||||
{% if station_coordinates %}
 | 
			
		||||
{% if coordinates %}
 | 
			
		||||
 <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
 | 
			
		||||
     integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
 | 
			
		||||
     crossorigin=""/>
 | 
			
		||||
| 
						 | 
				
			
			@ -77,7 +77,7 @@
 | 
			
		|||
  {% endfor %}
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
  {% if station_coordinates %}
 | 
			
		||||
  {% if coordinates %}
 | 
			
		||||
  <div id="map"></div>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -86,25 +86,41 @@
 | 
			
		|||
 | 
			
		||||
{% block scripts %}
 | 
			
		||||
 | 
			
		||||
{% if station_coordinates %}
 | 
			
		||||
{% if coordinates %}
 | 
			
		||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
 | 
			
		||||
   integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
 | 
			
		||||
   crossorigin=""></script>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
var station_coordinates = {{ station_coordinates | tojson }};
 | 
			
		||||
var coordinates = {{ coordinates | tojson }};
 | 
			
		||||
 | 
			
		||||
// Initialize the map
 | 
			
		||||
var map = L.map('map').fitBounds(station_coordinates);
 | 
			
		||||
var map = L.map('map').fitBounds(coordinates.map(function(station) {
 | 
			
		||||
  return [station.latitude, station.longitude];
 | 
			
		||||
}));
 | 
			
		||||
 | 
			
		||||
// Set up the tile layer
 | 
			
		||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
 | 
			
		||||
  attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
 | 
			
		||||
}).addTo(map);
 | 
			
		||||
 | 
			
		||||
// Add markers to the map
 | 
			
		||||
station_coordinates.forEach(function(coord) {
 | 
			
		||||
  L.marker(coord).addTo(map);
 | 
			
		||||
var stationIcon = L.divIcon({
 | 
			
		||||
  className: 'custom-div-icon',
 | 
			
		||||
  html: "<div style='font-size: 24px;'>🚉</div>",
 | 
			
		||||
  iconSize: [30, 42],
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var airportIcon = L.divIcon({
 | 
			
		||||
  className: 'custom-div-icon',
 | 
			
		||||
  html: "<div style='font-size: 24px;'>✈️</div>",
 | 
			
		||||
  iconSize: [30, 42],
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Add markers with appropriate icons to the map
 | 
			
		||||
coordinates.forEach(function(item) {
 | 
			
		||||
  var icon = item.type === "station" ? stationIcon : airportIcon;
 | 
			
		||||
  var marker = L.marker([item.latitude, item.longitude], { icon: icon }).addTo(map);
 | 
			
		||||
  marker.bindPopup(item.name);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										30
									
								
								web_view.py
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								web_view.py
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -3,7 +3,6 @@
 | 
			
		|||
"""Web page to show upcoming events."""
 | 
			
		||||
 | 
			
		||||
import inspect
 | 
			
		||||
import itertools
 | 
			
		||||
import operator
 | 
			
		||||
import os.path
 | 
			
		||||
import sys
 | 
			
		||||
| 
						 | 
				
			
			@ -182,8 +181,8 @@ def load_trains() -> list[StrDict]:
 | 
			
		|||
        for leg in train["legs"]:
 | 
			
		||||
            assert leg["from"] in by_name
 | 
			
		||||
            assert leg["to"] in by_name
 | 
			
		||||
            leg["from_station"] = by_name[train["from"]]
 | 
			
		||||
            leg["to_station"] = by_name[train["to"]]
 | 
			
		||||
            leg["from_station"] = by_name[leg["from"]]
 | 
			
		||||
            leg["to_station"] = by_name[leg["to"]]
 | 
			
		||||
 | 
			
		||||
    return trains
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -256,8 +255,8 @@ def trip_list() -> str:
 | 
			
		|||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]:
 | 
			
		||||
    """Extract and deduplicate station coordinates from trip."""
 | 
			
		||||
def collect_trip_coordinates(trip: Trip) -> list[StrDict]:
 | 
			
		||||
    """Extract and deduplicate airport and station coordinates from trip."""
 | 
			
		||||
    stations = {}
 | 
			
		||||
    station_list = []
 | 
			
		||||
    airports = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -279,8 +278,21 @@ def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]:
 | 
			
		|||
        stations[s["uic"]] = s
 | 
			
		||||
 | 
			
		||||
    return [
 | 
			
		||||
        (s["latitude"], s["longitude"])
 | 
			
		||||
        for s in itertools.chain(stations.values(), airports.values())
 | 
			
		||||
        {
 | 
			
		||||
            "name": s["name"],
 | 
			
		||||
            "type": "station",
 | 
			
		||||
            "latitude": s["latitude"],
 | 
			
		||||
            "longitude": s["longitude"],
 | 
			
		||||
        }
 | 
			
		||||
        for s in stations.values()
 | 
			
		||||
    ] + [
 | 
			
		||||
        {
 | 
			
		||||
            "name": s["name"],
 | 
			
		||||
            "type": "airport",
 | 
			
		||||
            "latitude": s["latitude"],
 | 
			
		||||
            "longitude": s["longitude"],
 | 
			
		||||
        }
 | 
			
		||||
        for s in airports.values()
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -295,13 +307,13 @@ def trip_page(start: str) -> str:
 | 
			
		|||
    if not trip:
 | 
			
		||||
        flask.abort(404)
 | 
			
		||||
 | 
			
		||||
    station_coordinates = collect_station_coordinates(trip)
 | 
			
		||||
    coordinates = collect_trip_coordinates(trip)
 | 
			
		||||
 | 
			
		||||
    return flask.render_template(
 | 
			
		||||
        "trip_page.html",
 | 
			
		||||
        trip=trip,
 | 
			
		||||
        today=today,
 | 
			
		||||
        station_coordinates=station_coordinates,
 | 
			
		||||
        coordinates=coordinates,
 | 
			
		||||
        get_country=agenda.get_country,
 | 
			
		||||
        format_list_with_ampersand=format_list_with_ampersand,
 | 
			
		||||
    )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue