Skip to content

Commit

Permalink
Merge branch 'master' of github.com:martin-ueding/geo-activity-playgr…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
martin-ueding committed Jun 9, 2024
2 parents 25e3956 + 701309a commit 7253801
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
32 changes: 32 additions & 0 deletions geo_activity_playground/webui/activity_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@ def render_day(self, year: int, month: int, day: int) -> dict:
"date": datetime.date(year, month, day).isoformat(),
}

def render_all(self) -> dict:
cmap = matplotlib.colormaps["Dark2"]
fc = geojson.FeatureCollection(
features=[
geojson.Feature(
geometry=geojson.MultiLineString(
coordinates=[
[
[lon, lat]
for lat, lon in zip(
group["latitude"], group["longitude"]
)
]
for _, group in self._repository.get_time_series(
activity["id"]
).groupby("segment_id")
]
),
properties={
"color": matplotlib.colors.to_hex(cmap(i % 8)),
"activity_name": activity["name"],
"activity_id": str(activity["id"]),
},
)
for i, activity in enumerate(self._repository.iter_activities())
]
)

return {
"geojson": geojson.dumps(fc),
}

def render_name(self, name: str) -> dict:
meta = self._repository.meta
selection = meta["name"] == name
Expand Down
6 changes: 6 additions & 0 deletions geo_activity_playground/webui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
def route_activity(app: Flask, repository: ActivityRepository) -> None:
activity_controller = ActivityController(repository)

@app.route("/activity/all")
def activity_all():
return render_template(
"activity-lines.html.j2", **activity_controller.render_all()
)

@app.route("/activity/<id>")
def activity(id: str):
return render_template(
Expand Down
36 changes: 36 additions & 0 deletions geo_activity_playground/webui/templates/activity-lines.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends "page.html.j2" %}

{% block container %}

<div class="row mb-3">
<div class="col">
<h1>All Activity Lines</h1>
</div>
</div>

<div class="row mb-3">
<div class="col-md-12">
<div id="activity-map" style="height: 500px;"></div>
<script>
function onEachFeature(feature, layer) {
layer.bindPopup(`<a href=/activity/${feature.properties.activity_id}>${feature.properties.activity_name}</a>`)
}
var map = L.map('activity-map', {
fullscreenControl: true
});
L.tileLayer('/tile/grayscale/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
let geojson = L.geoJSON({{ geojson| safe }}, {
style: function (feature) { return { color: feature.properties.color } },
onEachFeature: onEachFeature
}).addTo(map)
map.fitBounds(geojson.getBounds());
</script>
</div>
</div>

{% endblock %}

0 comments on commit 7253801

Please sign in to comment.