This now does everything I want from it. Achievement unlocked.
This commit is contained in:
parent
392a225691
commit
f675cf6519
4 changed files with 182 additions and 36 deletions
|
|
@ -3,22 +3,36 @@
|
|||
[clojure.browser.dom :as dom]
|
||||
[clojure.string :as cs]
|
||||
[geocsv-lite.data :refer [get-csv-url get-data get-query-part-as-map]]
|
||||
[geocsv-lite.gis :as gis]
|
||||
[geocsv-lite.map :as m]
|
||||
[geocsv-lite.notify :as n]))
|
||||
|
||||
|
||||
(defn ^:export initialise-map-element
|
||||
"Create a map view in the element with this `id` and decorate it with
|
||||
pins showing locations from this `data-source`."
|
||||
pins showing locations from this `data-source`. If `data-source` is nil
|
||||
or an empty string, the content of the element will be used, if present."
|
||||
[id data-source]
|
||||
(n/message (str "geocsv-lite.core.initialise-map-element called with args id: " id "; data-source: " data-source "."))
|
||||
(n/message
|
||||
(str
|
||||
"geocsv-lite.core.initialise-map-element called with args id: "
|
||||
id "; data-source: " data-source "."))
|
||||
(let [sid (str id)
|
||||
kid (keyword sid)
|
||||
v (m/add-view sid 55 -4 10)]
|
||||
(.whenReady v (fn [] (get-data kid data-source)))))
|
||||
|
||||
(defonce app-state (atom {:text "Hello world!"}))
|
||||
(defn ^:export initialise-map-element-from-content
|
||||
[id]
|
||||
(let [sid (str id)
|
||||
kid (keyword sid)
|
||||
v (m/add-view sid 55 -4 10)]
|
||||
(.whenReady
|
||||
v
|
||||
(fn
|
||||
[]
|
||||
(get-data kid (.innerText (.getElementById js/document id)))))))
|
||||
|
||||
|
||||
|
||||
(defn on-js-reload []
|
||||
;; optionally touch your app-state to force rerendering depending on
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@
|
|||
(when (string? %)
|
||||
(cs/lower-case
|
||||
(cs/replace
|
||||
% #"[^\w\d]+" "-"))))]
|
||||
(cs/trim %)
|
||||
#"[^\w\d]+" "-"))))]
|
||||
(keyword
|
||||
(if (empty? n)
|
||||
(gensym)
|
||||
|
|
@ -90,6 +91,7 @@
|
|||
"Get data for the view identified by this keyword `k` from this `data-source`.
|
||||
The data source may be a URL, or a CSV or JSON formatted string."
|
||||
[k data-source]
|
||||
(js/console.debug (str "get-data: k = `" k "`; data-source = `" data-source "`"))
|
||||
(let [p (js->clj (.parse js/Papa data-source) :keywordize-keys true)
|
||||
data (if
|
||||
(empty? (:errors p))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue