Now populating the map with pins as you move across it

Unfortunately, haven't worked out how to remove the pins!
This commit is contained in:
Simon Brooke 2018-07-22 20:28:39 +01:00
parent a256e492dc
commit de5d4de763
2 changed files with 14 additions and 20 deletions

View file

@ -111,25 +111,20 @@
[view] [view]
(if (if
view view
(let [layers (.eachLayer view (fn [l] l))]
(doall (doall
(.eachLayer (map
view #(if
(fn [layer] (instance? js/L.Marker %)
(try (.removeLayer view %))
(if layers))))
(instance? js/L.Marker layer)
(.removeLayer view layer))
(catch js/Object any
(js/console.log
(str "Failed to remove pin '"
layer "' from map: " any))))))))
view) view)
(defn refresh-map-pins (defn refresh-map-pins
"Refresh the map pins on this map. Side-effecty; liable to be problematic." "Refresh the map pins on this map. Side-effecty; liable to be problematic."
[] []
(let [view (map-remove-pins @(subscribe [:view])) (let [view @(subscribe [:view]) ;; (map-remove-pins @(subscribe [:view]))
addresses @(subscribe [:addresses])] addresses @(subscribe [:addresses])]
(if (if
view view

View file

@ -10,6 +10,7 @@
[re-frame.core :refer [dispatch reg-event-db reg-event-fx subscribe]] [re-frame.core :refer [dispatch reg-event-db reg-event-fx subscribe]]
[youyesyet.canvasser-app.gis :refer [refresh-map-pins get-current-location]] [youyesyet.canvasser-app.gis :refer [refresh-map-pins get-current-location]]
[youyesyet.canvasser-app.state :as db] [youyesyet.canvasser-app.state :as db]
[youyesyet.locality :refer [locality]]
)) ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -140,11 +141,10 @@
(reg-event-fx (reg-event-fx
:fetch-locality :fetch-locality
(fn [{db :db} _] (fn [{db :db} _]
(let [uri (str source-host (let [locality (locality (:latitude db) (:longitude db))
"rest/get-local-data?latitude=" uri (str source-host
(:latitude db) "rest/get-local-data?locality="
"&longitude=" locality)]
(or (:longitude db) -4))]
(js/console.log (js/console.log
(str (str
"Fetching locality data: " uri)) "Fetching locality data: " uri))
@ -157,7 +157,6 @@
:on-failure [:bad-locality]} :on-failure [:bad-locality]}
:db (add-to-feedback db :fetch-locality)}))) :db (add-to-feedback db :fetch-locality)})))
;; http://localhost:3000/rest/get-local-data?latitude=54.85131525968606&longitude=
(reg-event-db (reg-event-db
:get-current-location :get-current-location
@ -170,7 +169,7 @@
:process-locality :process-locality
(fn (fn
[db [_ response]] [db [_ response]]
(js/console.log "Updating locality data") (js/console.log (str "Updating locality data: " (count response) " addresses"))
;; loop to do it again ;; loop to do it again
(dispatch [:dispatch-later [{:ms 5000 :dispatch [:fetch-locality]} (dispatch [:dispatch-later [{:ms 5000 :dispatch [:fetch-locality]}
{:ms 1000 :dispatch [:get-current-location]}]]) {:ms 1000 :dispatch [:get-current-location]}]])