Still doesn't even nearly work, but progress...
This commit is contained in:
parent
86c675f22d
commit
abb1c000ec
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -14,3 +14,7 @@ profiles.clj
|
||||||
|
|
||||||
/node_modules
|
/node_modules
|
||||||
/log
|
/log
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
[cljs-ajax "0.8.0"]
|
[cljs-ajax "0.8.0"]
|
||||||
[cljsjs/leaflet "1.2.0-0"]
|
[cljsjs/leaflet "1.2.0-0"]
|
||||||
[clojure.java-time "0.3.2"]
|
[clojure.java-time "0.3.2"]
|
||||||
|
[com.cemerick/url "0.1.1"]
|
||||||
[com.cognitect/transit-clj "0.8.319"]
|
[com.cognitect/transit-clj "0.8.319"]
|
||||||
[cprop "0.1.15"]
|
[cprop "0.1.15"]
|
||||||
[day8.re-frame/http-fx "0.1.6"]
|
[day8.re-frame/http-fx "0.1.6"]
|
||||||
|
|
34
resources/public/data/data.csv
Normal file
34
resources/public/data/data.csv
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
Councils by Population Size,Name,Organisation ,Category,Population,,Latitude,Longitude,Co-ordinates
|
||||||
|
1,Glasgow,Glasgow City Council,Planning authority,626,,55.86,-4.25,"55.86, -4.25"
|
||||||
|
2,Edinburgh,City of Edinburgh Council ,Planning authority,518,,55.96,-3.18,"55.96, -3.18"
|
||||||
|
3,Fife,Fife Council,Planning authority,372,,56.2,-3.16,"56.20, -3.16"
|
||||||
|
4,North Lanarkshire,North Lanarkshire Council,Planning authority,340,,55.95,-3.99,"55.95, -3.99"
|
||||||
|
5,South Lanarkshire,South Lanarkshire Council,Planning authority,319,,55.78,-4.05,"55.78, -4.05"
|
||||||
|
6,Aberdeenshire,Aberdeenshire Council,Planning authority,261,,57.28,-2.37,"57.28, -2.37"
|
||||||
|
7,Highland,Highland Council,Planning authority,235,,57.48,-4.22,"57.48, -4.22"
|
||||||
|
8,Aberdeen,Aberdeen City Council.,Planning authority,228,,57.15,-2.09,"57.15, -2.09"
|
||||||
|
9,West Lothian,West Lothian Council,Planning authority,182,,55.93,-3.46,"55.93, -3.46"
|
||||||
|
10,Renfrewshire,Renfrewshire Council,Planning authority,178,3259,55.84,-4.42,"55.84, -4.42"
|
||||||
|
11,Falkirk,Falkirk Council,Planning authority,160,,,,
|
||||||
|
12,Perth and Kinross,Perth and Kinross Council,Planning authority,151,,,,
|
||||||
|
13,Dumfries and Galloway,Dumfries and Galloway Council.,Planning authority,149,,,,
|
||||||
|
14,Dundee,Dundee City Council.,Planning authority,149,,,,
|
||||||
|
15,North Ayrshire,North Ayrshire Council,Planning authority,135,,,,
|
||||||
|
16,East Ayrshire,East Ayrshire Council,Planning authority,122,,,,
|
||||||
|
17,Angus,Angus Council.,Planning authority,116,,,,
|
||||||
|
18,Scottish Borders,Scottish Borders Council,Planning authority,115,,,,
|
||||||
|
19,South Ayrshire,South Ayrshire Council,Planning authority,113,,,,
|
||||||
|
20,East Dunbartonshire,East Dunbartonshire Council,Planning authority,108,,,,
|
||||||
|
21,East Lothian,East Lothian Council,Planning authority,106,,,,
|
||||||
|
22,Moray,Moray Council,Planning authority,96,,,,
|
||||||
|
23,East Renfrewshire,East Renfrewshire Council,Planning authority,95,,,,
|
||||||
|
24,Stirling,Stirling Council,Planning authority,94,,,,
|
||||||
|
25,Midlothian,Midlothian Council,Planning authority,91,,,,
|
||||||
|
26,West Dunbartonshire,West Dunbartonshire Council,Planning authority,89,,,,
|
||||||
|
27,Argyll and Bute,Argyll and Bute Council.,Planning authority,86,,,,
|
||||||
|
28,Inverclyde,Inverclyde Council,Planning authority,78,,,,
|
||||||
|
29,Clackmannanshire,Clackmannanshire Council.,Planning authority,51,,,,
|
||||||
|
30,Na h-Eileanan Siar,Comhairle nan Eilean Siar (Western Isles) Council,Planning authority,26,,,,
|
||||||
|
31,Shetland,Shetland Islands Council,Planning authority,23,,,,
|
||||||
|
32,Orkney,Orkney Islands Council,Planning authority,22,,58.9,-2.9,"58.90, -2.90"
|
||||||
|
,,,Total,5434,,,,
|
|
298
resources/public/data/data.edn
Normal file
298
resources/public/data/data.edn
Normal file
|
@ -0,0 +1,298 @@
|
||||||
|
|
||||||
|
({:councils-by-population-size 1,
|
||||||
|
:name "Glasgow",
|
||||||
|
:organisation- "Glasgow City Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 626,
|
||||||
|
: "",
|
||||||
|
:latitude 55.86,
|
||||||
|
:longitude -4.25,
|
||||||
|
:co-ordinates "55.86, -4.25"}
|
||||||
|
{:councils-by-population-size 2,
|
||||||
|
:name "Edinburgh",
|
||||||
|
:organisation- "City of Edinburgh Council ",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 518,
|
||||||
|
: "",
|
||||||
|
:latitude 55.96,
|
||||||
|
:longitude -3.18,
|
||||||
|
:co-ordinates "55.96, -3.18"}
|
||||||
|
{:councils-by-population-size 3,
|
||||||
|
:name "Fife",
|
||||||
|
:organisation- "Fife Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 372,
|
||||||
|
: "",
|
||||||
|
:latitude 56.2,
|
||||||
|
:longitude -3.16,
|
||||||
|
:co-ordinates "56.20, -3.16"}
|
||||||
|
{:councils-by-population-size 4,
|
||||||
|
:name "North Lanarkshire",
|
||||||
|
:organisation- "North Lanarkshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 340,
|
||||||
|
: "",
|
||||||
|
:latitude 55.95,
|
||||||
|
:longitude -3.99,
|
||||||
|
:co-ordinates "55.95, -3.99"}
|
||||||
|
{:councils-by-population-size 5,
|
||||||
|
:name "South Lanarkshire",
|
||||||
|
:organisation- "South Lanarkshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 319,
|
||||||
|
: "",
|
||||||
|
:latitude 55.78,
|
||||||
|
:longitude -4.05,
|
||||||
|
:co-ordinates "55.78, -4.05"}
|
||||||
|
{:councils-by-population-size 6,
|
||||||
|
:name "Aberdeenshire",
|
||||||
|
:organisation- "Aberdeenshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 261,
|
||||||
|
: "",
|
||||||
|
:latitude 57.28,
|
||||||
|
:longitude -2.37,
|
||||||
|
:co-ordinates "57.28, -2.37"}
|
||||||
|
{:councils-by-population-size 7,
|
||||||
|
:name "Highland",
|
||||||
|
:organisation- "Highland Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 235,
|
||||||
|
: "",
|
||||||
|
:latitude 57.48,
|
||||||
|
:longitude -4.22,
|
||||||
|
:co-ordinates "57.48, -4.22"}
|
||||||
|
{:councils-by-population-size 8,
|
||||||
|
:name "Aberdeen",
|
||||||
|
:organisation- "Aberdeen City Council.",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 228,
|
||||||
|
: "",
|
||||||
|
:latitude 57.15,
|
||||||
|
:longitude -2.09,
|
||||||
|
:co-ordinates "57.15, -2.09"}
|
||||||
|
{:councils-by-population-size 9,
|
||||||
|
:name "West Lothian",
|
||||||
|
:organisation- "West Lothian Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 182,
|
||||||
|
: "",
|
||||||
|
:latitude 55.93,
|
||||||
|
:longitude -3.46,
|
||||||
|
:co-ordinates "55.93, -3.46"}
|
||||||
|
{:councils-by-population-size 10,
|
||||||
|
:name "Renfrewshire",
|
||||||
|
:organisation- "Renfrewshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 178,
|
||||||
|
: 3259,
|
||||||
|
:latitude 55.84,
|
||||||
|
:longitude -4.42,
|
||||||
|
:co-ordinates "55.84, -4.42"}
|
||||||
|
{:councils-by-population-size 11,
|
||||||
|
:name "Falkirk",
|
||||||
|
:organisation- "Falkirk Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 160,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 12,
|
||||||
|
:name "Perth and Kinross",
|
||||||
|
:organisation- "Perth and Kinross Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 151,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 13,
|
||||||
|
:name "Dumfries and Galloway",
|
||||||
|
:organisation- "Dumfries and Galloway Council.",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 149,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 14,
|
||||||
|
:name "Dundee",
|
||||||
|
:organisation- "Dundee City Council.",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 149,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 15,
|
||||||
|
:name "North Ayrshire",
|
||||||
|
:organisation- "North Ayrshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 135,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 16,
|
||||||
|
:name "East Ayrshire",
|
||||||
|
:organisation- "East Ayrshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 122,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 17,
|
||||||
|
:name "Angus",
|
||||||
|
:organisation- "Angus Council.",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 116,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 18,
|
||||||
|
:name "Scottish Borders",
|
||||||
|
:organisation- "Scottish Borders Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 115,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 19,
|
||||||
|
:name "South Ayrshire",
|
||||||
|
:organisation- "South Ayrshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 113,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 20,
|
||||||
|
:name "East Dunbartonshire",
|
||||||
|
:organisation- "East Dunbartonshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 108,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 21,
|
||||||
|
:name "East Lothian",
|
||||||
|
:organisation- "East Lothian Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 106,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 22,
|
||||||
|
:name "Moray",
|
||||||
|
:organisation- "Moray Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 96,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 23,
|
||||||
|
:name "East Renfrewshire",
|
||||||
|
:organisation- "East Renfrewshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 95,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 24,
|
||||||
|
:name "Stirling",
|
||||||
|
:organisation- "Stirling Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 94,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 25,
|
||||||
|
:name "Midlothian",
|
||||||
|
:organisation- "Midlothian Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 91,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 26,
|
||||||
|
:name "West Dunbartonshire",
|
||||||
|
:organisation- "West Dunbartonshire Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 89,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 27,
|
||||||
|
:name "Argyll and Bute",
|
||||||
|
:organisation- "Argyll and Bute Council.",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 86,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 28,
|
||||||
|
:name "Inverclyde",
|
||||||
|
:organisation- "Inverclyde Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 78,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 29,
|
||||||
|
:name "Clackmannanshire",
|
||||||
|
:organisation- "Clackmannanshire Council.",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 51,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 30,
|
||||||
|
:name "Na h-Eileanan Siar",
|
||||||
|
:organisation- "Comhairle nan Eilean Siar (Western Isles) Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 26,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 31,
|
||||||
|
:name "Shetland",
|
||||||
|
:organisation- "Shetland Islands Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 23,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""}
|
||||||
|
{:councils-by-population-size 32,
|
||||||
|
:name "Orkney",
|
||||||
|
:organisation- "Orkney Islands Council",
|
||||||
|
:category "Planning authority",
|
||||||
|
:population 22,
|
||||||
|
: "",
|
||||||
|
:latitude 58.9,
|
||||||
|
:longitude -2.9,
|
||||||
|
:co-ordinates "58.90, -2.90"}
|
||||||
|
{:councils-by-population-size "",
|
||||||
|
:name "",
|
||||||
|
:organisation- "",
|
||||||
|
:category "Total",
|
||||||
|
:population 5434,
|
||||||
|
: "",
|
||||||
|
:latitude "",
|
||||||
|
:longitude "",
|
||||||
|
:co-ordinates ""})
|
2
resources/public/data/data.json
Normal file
2
resources/public/data/data.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -34,6 +34,7 @@
|
||||||
{:class (when @expanded? :is-active)}
|
{:class (when @expanded? :is-active)}
|
||||||
[:div.navbar-start
|
[:div.navbar-start
|
||||||
[nav-link "#/" "Home" :home]
|
[nav-link "#/" "Home" :home]
|
||||||
|
[nav-link "#/map" "Map" :map]
|
||||||
[nav-link "#/about" "About" :about]]]]))
|
[nav-link "#/about" "About" :about]]]]))
|
||||||
|
|
||||||
(defn about-page []
|
(defn about-page []
|
||||||
|
@ -47,10 +48,12 @@
|
||||||
|
|
||||||
(defn map-page []
|
(defn map-page []
|
||||||
"Return the content for the main map page. Map showing current location."
|
"Return the content for the main map page. Map showing current location."
|
||||||
|
(js/console.log "Attempting to switch to map: 1")
|
||||||
(mv/panel))
|
(mv/panel))
|
||||||
|
|
||||||
(def pages
|
(def pages
|
||||||
{:home #'home-page
|
{:home #'home-page
|
||||||
|
:map #'map-page
|
||||||
:about #'about-page})
|
:about #'about-page})
|
||||||
|
|
||||||
(defn page []
|
(defn page []
|
||||||
|
@ -66,10 +69,10 @@
|
||||||
(reitit/router
|
(reitit/router
|
||||||
[["/" {:name :home
|
[["/" {:name :home
|
||||||
:view #'home-page
|
:view #'home-page
|
||||||
:controllers [{:start (fn [_] (rf/dispatch [:page/init-home]))}]}]
|
:controllers [{:start (fn [_] (rf/dispatch [:init-home]))}]}]
|
||||||
["/map" {:name :home
|
["/map" {:name :map
|
||||||
:view #'map-page
|
:view #'map-page
|
||||||
:controllers [{:start (fn [_] (rf/dispatch [:page/init-map]))}]}]
|
:controllers [{:start (fn [_] (rf/dispatch [:init-map]))}]}]
|
||||||
["/about" {:name :about
|
["/about" {:name :about
|
||||||
:view #'about-page}]]))
|
:view #'about-page}]]))
|
||||||
|
|
||||||
|
@ -86,6 +89,7 @@
|
||||||
(r/render [#'page] (.getElementById js/document "app")))
|
(r/render [#'page] (.getElementById js/document "app")))
|
||||||
|
|
||||||
(defn init! []
|
(defn init! []
|
||||||
|
(rf/dispatch-sync [:initialise-db])
|
||||||
(start-router!)
|
(start-router!)
|
||||||
(ajax/load-interceptors!)
|
(ajax/load-interceptors!)
|
||||||
(mount-components))
|
(mount-components))
|
||||||
|
|
8
src/cljs/geocsv/db.cljs
Normal file
8
src/cljs/geocsv/db.cljs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
(ns ^{:doc "geocsv app initial database."
|
||||||
|
:author "Simon Brooke"}
|
||||||
|
geocsv.db)
|
||||||
|
|
||||||
|
(def default-db
|
||||||
|
{:page :home
|
||||||
|
:map {:map-centre [56 -4]
|
||||||
|
:map-zoom 6}})
|
|
@ -1,65 +1,39 @@
|
||||||
(ns geocsv.events
|
(ns geocsv.events
|
||||||
(:require
|
(:require [ajax.core :as ajax]
|
||||||
|
[ajax.json :refer [json-request-format json-response-format]]
|
||||||
|
[cemerick.url :refer [url url-encode]]
|
||||||
|
[geocsv.db :refer [default-db]]
|
||||||
|
[geocsv.gis :refer [refresh-map-pins]]
|
||||||
[re-frame.core :as rf]
|
[re-frame.core :as rf]
|
||||||
[ajax.core :as ajax]
|
|
||||||
[reitit.frontend.easy :as rfe]
|
[reitit.frontend.easy :as rfe]
|
||||||
[reitit.frontend.controllers :as rfc]))
|
[reitit.frontend.controllers :as rfc]))
|
||||||
|
|
||||||
;;dispatchers
|
|
||||||
|
|
||||||
(rf/reg-event-db
|
(def source-host
|
||||||
:navigate
|
"The base URL of the host from which the app was loaded."
|
||||||
(fn [db [_ match]]
|
(assoc
|
||||||
(let [old-match (:common/route db)
|
(url js/window.location)
|
||||||
new-match (assoc match :controllers
|
:path "/"
|
||||||
(rfc/apply-controllers (:controllers old-match) match))]
|
:query nil
|
||||||
(assoc db :route new-match))))
|
:anchor nil))
|
||||||
|
|
||||||
(rf/reg-fx
|
|
||||||
:navigate-fx!
|
|
||||||
(fn [[k & [params query]]]
|
|
||||||
(rfe/push-state k params query)))
|
|
||||||
|
|
||||||
|
;;dispatchers: keep in alphabetical order, please.
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:navigate!
|
:bad-data
|
||||||
(fn [_ [_ url-key params query]]
|
;; TODO: why is this an `-fx`? Does it need to be?
|
||||||
{:navigate-fx! [url-key params query]}))
|
(fn
|
||||||
|
[{db :db} [_ response]]
|
||||||
(rf/reg-event-db
|
;; TODO: signal something has failed? It doesn't matter very much, unless it keeps failing.
|
||||||
:set-docs
|
(js/console.log (str "Failed to fetch data data" response))
|
||||||
(fn [db [_ docs]]
|
db))
|
||||||
(assoc db :docs docs)))
|
|
||||||
|
|
||||||
(rf/reg-event-fx
|
|
||||||
:fetch-docs
|
|
||||||
(fn [_ _]
|
|
||||||
{:http-xhrio {:method :get
|
|
||||||
:uri "/docs"
|
|
||||||
:response-format (ajax/raw-response-format)
|
|
||||||
:on-success [:set-docs]}}))
|
|
||||||
|
|
||||||
(rf/reg-event-db
|
(rf/reg-event-db
|
||||||
:common/set-error
|
:common/set-error
|
||||||
(fn [db [_ error]]
|
(fn [db [_ error]]
|
||||||
(assoc db :common/error error)))
|
(assoc db :common/error error)))
|
||||||
|
|
||||||
(reg-event-db
|
|
||||||
:set-view
|
|
||||||
(fn [db [_ view]]
|
|
||||||
(assoc db :view view)))
|
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:page/init-home
|
|
||||||
(fn [_ _]
|
|
||||||
{:dispatch [:fetch-docs]}))
|
|
||||||
|
|
||||||
(rf/reg-event-fx
|
|
||||||
:page/init-maps
|
|
||||||
(fn [_ _]
|
|
||||||
{:dispatch [:fetch-data]}))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
:fetch-data
|
:fetch-data
|
||||||
(fn [{db :db} _]
|
(fn [{db :db} _]
|
||||||
(let [uri (assoc source-host
|
(let [uri (assoc source-host
|
||||||
|
@ -76,38 +50,106 @@
|
||||||
:on-failure [:bad-data]}
|
:on-failure [:bad-data]}
|
||||||
:db db})))
|
:db db})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
|
:fetch-docs
|
||||||
|
(fn [_ _]
|
||||||
|
{:http-xhrio {:method :get
|
||||||
|
:uri "/docs"
|
||||||
|
:response-format (ajax/raw-response-format)
|
||||||
|
:on-success [:set-docs]}}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:init-home
|
||||||
|
(fn [_ _]
|
||||||
|
{:dispatch [:fetch-docs]}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:init-map
|
||||||
|
(fn [_ _]
|
||||||
|
{:dispatch [:fetch-data]}))
|
||||||
|
|
||||||
|
(rf/reg-event-db
|
||||||
|
:initialise-db
|
||||||
|
(fn [_ _]
|
||||||
|
(js/console.log "Initialising state.")
|
||||||
|
default-db))
|
||||||
|
|
||||||
|
(rf/reg-event-db
|
||||||
|
:navigate
|
||||||
|
(fn [db [_ match]]
|
||||||
|
(let [old-match (:common/route db)
|
||||||
|
new-match (assoc match :controllers
|
||||||
|
(rfc/apply-controllers (:controllers old-match) match))]
|
||||||
|
(assoc db :route new-match))))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:navigate!
|
||||||
|
(fn [_ [_ url-key params query]]
|
||||||
|
{:navigate-fx! [url-key params query]}))
|
||||||
|
|
||||||
|
(rf/reg-fx
|
||||||
|
:navigate-fx!
|
||||||
|
(fn [[k & [params query]]]
|
||||||
|
(rfe/push-state k params query)))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
:process-data
|
:process-data
|
||||||
;; TODO: why is this an `-fx`? Does it need to be?
|
;; TODO: why is this an `-fx`? Does it need to be?
|
||||||
(fn
|
(fn
|
||||||
[{db :db} [_ response]]
|
[{db :db} [_ response]]
|
||||||
(let [data (js->clj response)]
|
(let [data (js->clj response)]
|
||||||
(js/console.log (str ":process-data: " response))
|
(js/console.log (str "processing fetched JSON data"))
|
||||||
{:db (refresh-map-pins (assoc db :data data))})))
|
{:db (if
|
||||||
|
(:view db)
|
||||||
|
(refresh-map-pins (assoc db :data data))
|
||||||
|
db)})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-db
|
||||||
:bad-data
|
:set-docs
|
||||||
;; TODO: why is this an `-fx`? Does it need to be?
|
(fn [db [_ docs]]
|
||||||
(fn
|
(assoc db :docs docs)))
|
||||||
[{db :db} [_ response]]
|
|
||||||
;; TODO: signal something has failed? It doesn't matter very much, unless it keeps failing.
|
|
||||||
(js/console.log (str "Failed to fetch data data" response))
|
|
||||||
db))
|
|
||||||
|
|
||||||
|
(rf/reg-event-db
|
||||||
|
:set-view
|
||||||
|
(fn [db [_ view]]
|
||||||
|
(assoc db :view view)))
|
||||||
|
|
||||||
;;subscriptions
|
;;subscriptions. Keep in alphabetical order, please
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:common/error
|
||||||
|
(fn [db _]
|
||||||
|
(:common/error db)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:docs
|
||||||
|
(fn [db _]
|
||||||
|
(:docs db)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:latitude
|
||||||
|
(fn [db _]
|
||||||
|
(let [v (or (first (:map-centre (:map db))) 54)]
|
||||||
|
(js/console.log (str "Fetching latitude" v))
|
||||||
|
v)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:longitude
|
||||||
|
(fn [db _]
|
||||||
|
(let [v (or (nth (:map-centre (:map db)) 1) -4)]
|
||||||
|
(js/console.log (str "Fetching longitude" v))
|
||||||
|
v)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:map
|
||||||
|
(fn [db _]
|
||||||
|
(:map db)))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:route
|
:route
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(-> db :route)))
|
(-> db :route)))
|
||||||
|
|
||||||
(rf/reg-sub
|
|
||||||
:page-id
|
|
||||||
:<- [:route]
|
|
||||||
(fn [route _]
|
|
||||||
(-> route :data :name)))
|
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:page
|
:page
|
||||||
:<- [:route]
|
:<- [:route]
|
||||||
|
@ -115,11 +157,13 @@
|
||||||
(-> route :data :view)))
|
(-> route :data :view)))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:docs
|
:page-id
|
||||||
(fn [db _]
|
:<- [:route]
|
||||||
(:docs db)))
|
(fn [route _]
|
||||||
|
(-> route :data :name)))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:common/error
|
:zoom
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(:common/error db)))
|
(:map-zoom (:map db))))
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
(ns ^{:doc "geocsv app map stuff."
|
(ns ^{:doc "geocsv app map stuff."
|
||||||
:author "Simon Brooke"}
|
:author "Simon Brooke"}
|
||||||
geocsv.gis
|
geocsv.gis
|
||||||
(:require [cljs.reader :refer [read-string]]
|
(:require [ajax.core :refer [GET]]
|
||||||
|
[ajax.json :refer [json-request-format json-response-format]]
|
||||||
|
[cljs.reader :refer [read-string]]
|
||||||
[clojure.string :refer [capitalize lower-case]]
|
[clojure.string :refer [capitalize lower-case]]
|
||||||
[cemerick.url :refer (url url-encode)]
|
[cemerick.url :refer (url url-encode)]
|
||||||
[day8.re-frame.http-fx]
|
[day8.re-frame.http-fx]
|
||||||
[re-frame.core :refer [dispatch reg-event-db reg-event-fx subscribe]]
|
[re-frame.core :refer [dispatch reg-event-db reg-event-fx subscribe]]))
|
||||||
[ajax.core :refer [GET]]
|
|
||||||
[ajax.json :refer [json-request-format json-response-format]]
|
|
||||||
[youyesyet.locality :refer [locality]]
|
|
||||||
))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;
|
;;;;
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
(defn map-did-mount-mapbox
|
(defn map-did-mount-mapbox
|
||||||
"Did-mount function loading map tile data from MapBox (proprietary)."
|
"Did-mount function loading map tile data from MapBox (proprietary)."
|
||||||
[]
|
[]
|
||||||
(get-current-location)
|
|
||||||
(let [view (.setView
|
(let [view (.setView
|
||||||
(.map js/L "map" (clj->js {:zoomControl "false"})))]
|
(.map js/L "map" (clj->js {:zoomControl "false"})))]
|
||||||
;; NEED TO REPLACE FIXME with your mapID!
|
;; NEED TO REPLACE FIXME with your mapID!
|
||||||
|
@ -59,12 +58,12 @@
|
||||||
(defn map-did-mount-osm
|
(defn map-did-mount-osm
|
||||||
"Did-mount function loading map tile data from Open Street Map."
|
"Did-mount function loading map tile data from Open Street Map."
|
||||||
[]
|
[]
|
||||||
(get-current-location) ;; - [Violation] Only request geolocation information in response to a user gesture.
|
|
||||||
(let [view (.setView
|
(let [view (.setView
|
||||||
(.map js/L
|
(.map js/L
|
||||||
"map"
|
"map"
|
||||||
(clj->js {:zoomControl false}))
|
;; (clj->js {:zoomControl false})
|
||||||
#js [@(subscribe [:latitude]) @(subscribe [:longitude])]
|
)
|
||||||
|
#js [56 -4] ;;[@(subscribe [:latitude]) @(subscribe [:longitude])]
|
||||||
@(subscribe [:zoom]))]
|
@(subscribe [:zoom]))]
|
||||||
(.addTo (.tileLayer js/L osm-url
|
(.addTo (.tileLayer js/L osm-url
|
||||||
(clj->js {:attribution osm-attrib
|
(clj->js {:attribution osm-attrib
|
||||||
|
@ -76,8 +75,8 @@
|
||||||
(js/console.log (str "Moving centre to " c))
|
(js/console.log (str "Moving centre to " c))
|
||||||
(dispatch-sync [:set-latitude (.-lat c)])
|
(dispatch-sync [:set-latitude (.-lat c)])
|
||||||
(dispatch-sync [:set-longitude (.-lng c)])
|
(dispatch-sync [:set-longitude (.-lng c)])
|
||||||
(dispatch [:fetch-locality]))))
|
(dispatch [:fetch-data]))))
|
||||||
(refresh-map-pins)
|
;; (refresh-map-pins)
|
||||||
view))
|
view))
|
||||||
|
|
||||||
(defn map-did-mount
|
(defn map-did-mount
|
||||||
|
@ -98,5 +97,6 @@
|
||||||
"A reagent class for the map object."
|
"A reagent class for the map object."
|
||||||
[]
|
[]
|
||||||
;; (get-current-location)
|
;; (get-current-location)
|
||||||
|
(js/console.log "Attempting to switch to map: 2")
|
||||||
(reagent/create-class {:reagent-render map-render
|
(reagent/create-class {:reagent-render map-render
|
||||||
:component-did-mount map-did-mount}))
|
:component-did-mount map-did-mount}))
|
||||||
|
|
Loading…
Reference in a new issue