larsen / rando-planner

Clerk viewers and utils to plan bikepacking trips
https://rando-planner.stefanorodighiero.net/
4 stars 0 forks source link

GPX polyline is not visualized in absence of a `:daily-plans` key in the plan #53

Open larsen opened 1 month ago

larsen commented 1 month ago

In the documentation it is advertised that one can visualize a GPX file simply using something like

(clerk/with-viewer leaflet/leaflet-gpx-viewer
  {:gpx "gpx/be-rostock.gpx"})

But this is broken, because the actual visualization code does:

(when (:points value)
  (let [point-groups (:grouped-by-day value)]
    (js/console.log (count point-groups))
    (doall
     (for [[pp color] (map vector
                           point-groups
                           (take (count point-groups)
                                 (cycle '["#660e60","#893f71","#ac6f82","#cfa093","#f3d0a4"])
                                 (cycle '["black" "yellow"])))]
       (.addTo (.polyline js/L (clj->js (map (fn [{lat :lat, lon :lon} p]
                                               [lat lon])
                                             pp))
                          (clj->js {:color color}))
               @m))))
  (.addTo (.marker js/L (clj->js [(:lat start) (:lon start)])
                   (clj->js {:icon start-icon})) @m)
  (.addTo (.marker js/L (clj->js [(:lat end) (:lon end)])
                   (clj->js {:icon end-icon})) @m))

which assumes the visualized data structure contains a :grouped-by-day key. But this is true only when a :daily-plans key has been specified