Skip to content

Instantly share code, notes, and snippets.

@naamancampbell
Last active October 19, 2019 21:38
Show Gist options
  • Save naamancampbell/f1fd6c9d98aba2a7f7facd1ced426d19 to your computer and use it in GitHub Desktop.
Save naamancampbell/f1fd6c9d98aba2a7f7facd1ced426d19 to your computer and use it in GitHub Desktop.
Display Multiple Strava Activity Maps in Flask Template
{% for activity in activities %}
<div class="post">
{% if activity.strava_data['map']['polyline'] is not none %}
<div id="map_{{ activity.id }}" class="img-fluid" style="height: 300px;"></div>
{% endif %}
{# other activity data #}
</div>
{% endfor %}
{% for activity in activities %}
{% if activity.strava_data['map']['polyline'] is not none %}
<script>
let encodedRoute_{{ activity.id }} = '{{ activity.strava_data['map']['polyline']|replace("\\", "\\\\")|safe }}';
let coordinates_{{ activity.id }} = L.Polyline.fromEncoded(encodedRoute_{{ activity.id }}).getLatLngs();
let map_{{ activity.id }} = L.map('map_{{ activity.id }}').fitBounds(coordinates_{{ activity.id }});
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
}).addTo(map_{{ activity.id }});
L.polyline(
coordinates_{{ activity.id }},
{
color: 'blue',
weight: 2,
opacity: .7,
lineJoin: 'round'
}
).addTo(map_{{ activity.id }});
</script>
{% endif %}
{% endfor %}
@naamancampbell
Copy link
Author

Display Multiple Strava Activity Maps in Flask Template
Reads in a collection of Strava Activities and displays a map for each activity.

Based on Mark Needham's Leaflet: Mapping Strava runs/polylines on Open Street Map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment