Skip to content

Commit

Permalink
Bound personal/hashtag ride maps
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinorg committed Jan 6, 2025
1 parent 21dc6f4 commit ce53897
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 54 deletions.
15 changes: 14 additions & 1 deletion freezing/web/static/js/ride-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const track_colors = [
'rgb(0, 137, 255)', 'rgb(33, 119, 255)', 'rgb(112, 101, 255)', 'rgb(153, 83, 255)', 'rgb(185, 65, 255)',
'rgb(212, 44, 252)', 'rgb(234, 10, 218)', 'rgb(252, 0, 179)', 'rgb(255, 0, 136)', 'rgb(255, 0, 87)',
];
function create_ride_map(id, url, ride_color = null) {
function create_ride_map(id, url, ride_color = null, recenter = false) {
const map = L.map(id, { scrollWheelZoom: false }).setView([38.9072, -77.0369], 9);
const colorMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
var tiles = L.tileLayer('https://{s}.basemaps.cartocdn.com/' + colorMode + '_all/{z}/{x}/{y}{r}.png', {
Expand All @@ -23,6 +23,19 @@ function create_ride_map(id, url, ride_color = null) {
maxZoom: 20,
}).addTo(map);
fetch(url).then(r => r.json()).then(data => {
if (recenter) {
let minlat = 90, maxlat = -90, minlon = 180, maxlon = -180;
for (const { track } of data.tracks) {
for (const [lat, lon] of track) {
if (lat < minlat) minlat = lat; else if (lat > maxlat) maxlat = lat;
if (lon < minlon) minlon = lon; else if (lon > maxlon) maxlon = lon;
}
}
if (minlat < maxlat) {
const bounds = new L.LatLngBounds([[maxlat, maxlon], [minlat, minlon]]);
map.fitBounds(bounds, {padding: [20, 20]});
}
}
data.tracks.forEach(({ team, track}, index) => {
const color = ride_color ?? track_colors[team % track_colors.length];
const opacity = .2 + .4 * (index + 1) / data.tracks.length;
Expand Down
4 changes: 2 additions & 2 deletions freezing/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
<a class="dropdown-item" href="/pointless/hashtag/donut">Doughnut Rides</a>
</li>
<li>
<a class="dropdown-item" href="/pointless/generic/adulting">Errandeering</a>
<a class="dropdown-item" href="/pointless/hashtag/adulting">Errandeering</a>
</li>
<li>
<a class="dropdown-item" href="/pointless/hashtag/420">Expand Your Horizons</a>
Expand All @@ -332,7 +332,7 @@
<a class="dropdown-item" href="/pointless/hashtag/fsbooks">Little Free Library</a>
</li>
<li>
<a class="dropdown-item" href="/pointless/generic/londonbridge">London Bridge Rides</a>
<a class="dropdown-item" href="/pointless/hashtag/londonbridge">London Bridge Rides</a>
</li>
<li>
<a class="dropdown-item" href="/pointless/arlington">Loopy for Arlington</a>
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/templates/pointless/hashtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h3 class="accordion-header">
<script type="text/javascript">
$(function() {
$('#map-button').one('click', () => {
create_ride_map('map', '/api/all/trackmap.json?hashtag={{data.hashtag_notag}}');
create_ride_map('map', '/api/all/trackmap.json?hashtag={{data.hashtag_notag}}', null, true);
});
});
</script>
Expand Down
18 changes: 9 additions & 9 deletions freezing/web/templates/user/rides.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ <h2 class="clearfix">
role="tab"
data-bs-toggle="tab">My Rides</a>
</li>
<li role="presentation" class="nav-item">
<a href="#map"
id="map-link"
class="nav-link"
aria-controls="map"
role="tab"
data-bs-toggle="tab">My Ride Map</a>
</li>
<li role="presentation" class="nav-item">
<a href="#profile"
class="nav-link"
Expand All @@ -97,14 +105,6 @@ <h2 class="clearfix">
role="tab"
data-bs-toggle="tab">My Weekly Points</a>
</li>
<li role="presentation" class="nav-item">
<a href="#map"
id="map-link"
class="nav-link"
aria-controls="map"
role="tab"
data-bs-toggle="tab">My Ride Map</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
Expand Down Expand Up @@ -272,7 +272,7 @@ <h2 class="clearfix">
});

$('#map-link').one('click', () => {
create_ride_map('map', '/api/my/trackmap.json', 'red');
create_ride_map('map', '/api/my/trackmap.json', 'red', true);
});
});
</script>
Expand Down
1 change: 0 additions & 1 deletion freezing/web/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class AccessDenied(RuntimeError):
"freezingerrands": "generic/adulting",
"fsrealsuppleride": "generic/suppleride",
"kidical": "kidmiles",
"londonbridge": "generic/londonbridge",
"rosshillloop": "rosshillloop",
"withkid": "pointlesskids",
}
Expand Down
19 changes: 0 additions & 19 deletions leaderboards/adulting.yml

This file was deleted.

17 changes: 17 additions & 0 deletions leaderboards/hashtag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ tags:
find and photograph the vehicles WHILE on a bike ride. Use the hashtag <code>#abc</code> and post to the forum.
rank_by_rides: True

- tag: adulting
alt: freezingerrands
name: Errandeering
description: |
Pointless prize for doing stuff on your bike you might be tempted to do in your car.
Grocery store, post office, pharmacy dentist, manicurist, gym, farmers market, dry cleaning, bike shop, library, etc.
Commutes, coffee rides, kid pick up / drop off do not count.
Tag rides with <code>#adulting</code> or <code>#freezingerrands</code>.
rank_by_rides: True

- tag: bob
name: Baby on Board
description: |
Expand Down Expand Up @@ -143,6 +153,13 @@ tags:
to the public. Tag with <code>#LakeFinder</code>.
rank_by_rides: True

- tag: londonbridge
name: London Bridge
description: |
Number of rides where you fell 😨🚲😱 (tagged with <code>#londonbridge</code>).
url: https://www.bikearlingtonforum.com/forums/topic/ww-london-bridge-pointless-prize-log/
rank_by_rides: True

- tag: oldGeorge
name: Old Georgetown Bike Lane
description: |
Expand Down
21 changes: 0 additions & 21 deletions leaderboards/londonbridge.yml

This file was deleted.

0 comments on commit ce53897

Please sign in to comment.