Hide map on trip page when there are no coordinates or routes
Closes #205 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
76360c25f3
commit
3ba18f9019
2 changed files with 16 additions and 4 deletions
|
|
@ -56,7 +56,16 @@ function emojiIcon(emoji, zoom) {
|
||||||
|
|
||||||
|
|
||||||
function build_map(map_id, coordinates, routes) {
|
function build_map(map_id, coordinates, routes) {
|
||||||
var map = L.map(map_id).fitBounds(coordinates.map(function(station) { return [station.latitude, station.longitude]; }));
|
var bounds = coordinates.map(function(station) { return [station.latitude, station.longitude]; });
|
||||||
|
if (bounds.length === 0) {
|
||||||
|
routes.forEach(function(r) {
|
||||||
|
if (r.from) bounds.push(r.from);
|
||||||
|
if (r.to) bounds.push(r.to);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var map = bounds.length > 0
|
||||||
|
? L.map(map_id).fitBounds(bounds)
|
||||||
|
: L.map(map_id).setView([20, 0], 2);
|
||||||
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
{% block style %}
|
{% block style %}
|
||||||
|
|
||||||
{% if coordinates %}
|
{% if coordinates or routes %}
|
||||||
<link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}">
|
<link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<link rel="stylesheet" href="{{ url_for("static", filename="css/trips.css") }}">
|
<link rel="stylesheet" href="{{ url_for("static", filename="css/trips.css") }}">
|
||||||
|
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 col-sm-12">
|
<div class="{% if coordinates or routes %}col-md-6{% else %}col-md-12{% endif %} col-sm-12">
|
||||||
<div class="m-3">
|
<div class="m-3">
|
||||||
<div class="trip-prev-next">{{ next_and_previous() }}</div>
|
<div class="trip-prev-next">{{ next_and_previous() }}</div>
|
||||||
<h1 class="trip-page-title">{{ trip.title }}</h1>
|
<h1 class="trip-page-title">{{ trip.title }}</h1>
|
||||||
|
|
@ -497,16 +497,18 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if coordinates or routes %}
|
||||||
<div class="col-md-6 col-sm-12">
|
<div class="col-md-6 col-sm-12">
|
||||||
<button id="toggleMapSize" class="btn btn-primary mb-2">Toggle map size</button>
|
<button id="toggleMapSize" class="btn btn-primary mb-2">Toggle map size</button>
|
||||||
<div id="map" class="half-map">
|
<div id="map" class="half-map">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
{% if coordinates or routes %}
|
||||||
<script src="{{ url_for("static", filename="leaflet/leaflet.js") }}"></script>
|
<script src="{{ url_for("static", filename="leaflet/leaflet.js") }}"></script>
|
||||||
<script src="{{ url_for("static", filename="leaflet-geodesic/leaflet.geodesic.umd.min.js") }}"></script>
|
<script src="{{ url_for("static", filename="leaflet-geodesic/leaflet.geodesic.umd.min.js") }}"></script>
|
||||||
|
|
||||||
|
|
@ -519,4 +521,5 @@ var routes = {{ routes | tojson }};
|
||||||
build_map("map", coordinates, routes);
|
build_map("map", coordinates, routes);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue