Skip to content

Commit a428517

Browse files
authored
Detail leaflet viewer (#58)
1 parent d7098cd commit a428517

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

notebooks/rando-planner.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
;; strategies for covering the distance effectively.
5858

5959

60-
;; This page has been composed with Clerk and rando-planner
60+
;; This page was composed with Clerk and rando-planner
6161

6262
;; You can see the code for the project [on
6363
;; github.com](https://github.com/larsen/rando-planner).
@@ -239,6 +239,12 @@ be morale-crushing."]])
239239
{:nextjournal/width :full}
240240
(clerk/with-viewer leaflet/leaflet-gpx-viewer equally-split-plan-with-pauses))
241241

242+
;; Additionally, you can focus the map on the portion of map
243+
;; corresponding to a single day
244+
245+
(clerk/with-viewer leaflet/leaflet-gpx-viewer
246+
(assoc equally-split-plan-with-pauses :focus-on "Second day"))
247+
242248
;; ## How plans are defined
243249

244250
;; Examining an example, we'll provide a more formal definition of

src/rando_planner/leaflet.clj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
(defn add-center-and-bounds [plan]
77
(if (:gpx plan)
8-
(let [points (gpx/points (:gpx plan))]
8+
(let [points (gpx/points (:gpx plan))
9+
grouped-by-day (plan/group-points-by-day plan)
10+
points-to-focus-on (if (:focus-on plan)
11+
(get grouped-by-day (:focus-on plan))
12+
points)
13+
center (gpx/center points-to-focus-on)
14+
bounds (gpx/bounds points-to-focus-on)]
915
(assoc plan
1016
:points points
11-
:grouped-by-day (plan/group-points-by-day plan)
12-
:center (gpx/center points)
13-
:bounds (gpx/bounds points)))
17+
:grouped-by-day (vals grouped-by-day)
18+
:center center
19+
:bounds bounds))
1420
plan))
1521

1622
(defn add-plan-markers [plan]

src/rando_planner/plan.clj

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@
9898
(defn group-points-by-day [plan]
9999
(let [points-with-cumulative-distance (gpx/with-cumulative-distance
100100
(gpx/points (:gpx plan)))]
101-
(map (fn [d]
102-
(filter #(and (>= (:cumulative-distance %)
103-
(:covered d))
104-
(< (:cumulative-distance %)
105-
(+ (:covered d)
106-
(:kilometers d))))
107-
points-with-cumulative-distance))
108-
(daily-distance plan))))
101+
(into {} (map (fn [d]
102+
[(:label d)
103+
(filter #(and (>= (:cumulative-distance %)
104+
(:covered d))
105+
(< (:cumulative-distance %)
106+
(+ (:covered d)
107+
(:kilometers d))))
108+
points-with-cumulative-distance)])
109+
(daily-distance plan)))))
109110

110111
(defn daily-stats
111112
"Given a plan, it returns a list of dictionaries with info and
@@ -128,11 +129,11 @@
128129
gpx/with-cumulative-distance)
129130
daily-distance (daily-distance plan)
130131
points-at-end-of-days (for [dk daily-distance]
131-
(first (filter (fn [p]
132-
(> (:cumulative-distance p)
133-
(+ (:covered dk)
134-
(:kilometers dk))))
135-
points-with-cumulative-distance)))
132+
(first (filter (fn [p]
133+
(> (:cumulative-distance p)
134+
(+ (:covered dk)
135+
(:kilometers dk))))
136+
points-with-cumulative-distance)))
136137
daily-pauses (vec (map
137138
(fn [pauses]
138139
{:pauses pauses})

0 commit comments

Comments
 (0)