Better feedback reporting; auto pan and zoom now work.
This commit is contained in:
parent
98abf86cbe
commit
20507ba5f3
|
@ -35,7 +35,7 @@ footer a {
|
|||
h1, h2, h3, h4, h5, h6 {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding-left: 10%;
|
||||
padding: 0.5em 10%;
|
||||
text-align: left;
|
||||
background-color: #3298dc;
|
||||
color: white;
|
||||
|
@ -44,3 +44,19 @@ h1, h2, h3, h4, h5, h6 {
|
|||
samp {
|
||||
background-color: #b0b0ff;
|
||||
}
|
||||
|
||||
#error
|
||||
{
|
||||
background-color: maroon;
|
||||
color: white;
|
||||
margin: 0px;
|
||||
padding-left: 10%;
|
||||
}
|
||||
|
||||
#message
|
||||
{
|
||||
background-color: darkgreen;
|
||||
color: white;
|
||||
margin: 0px;
|
||||
padding-left: 10%;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ crossorigin=""/ -->
|
|||
<h4>
|
||||
An ultra-lightweight tool to show comma-separated value data on a map
|
||||
</h4>
|
||||
<div id="app">
|
||||
<p id="message"></p>
|
||||
<p id="error"></p>
|
||||
<div id="app">
|
||||
<div id="map" style="height: 600px; width: 80%; border: thin solid gray;"></div>
|
||||
<div id="doc">
|
||||
<p>
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
[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.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`."
|
||||
[id data-source]
|
||||
(js/console.log (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)]
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
[cljs.core.async :refer [<!]]
|
||||
[geocsv-lite.gis :as gis]
|
||||
[geocsv-lite.map :refer [get-view]]
|
||||
))
|
||||
|
||||
[geocsv-lite.notify :as n]))
|
||||
|
||||
|
||||
|
||||
|
@ -69,7 +68,7 @@
|
|||
(rest data))
|
||||
]
|
||||
(gis/refresh-map-pins (get-view k) records))
|
||||
(js/console.error (str "Bad response from server: " (:status response)))))
|
||||
(n/error (str "Bad response from server: " (:status response)))))
|
||||
|
||||
|
||||
(defn get-data
|
||||
|
@ -90,8 +89,3 @@
|
|||
(go (let [response (<! (http/get uri))]
|
||||
(apply handler-fn (list response k)))))
|
||||
|
||||
|
||||
;; (go (let [uri "http://localhost:3449/data/data.csv"
|
||||
;; response (<! (http/get uri))]
|
||||
;; (when (= (:status response) 200)
|
||||
;; (default-handler response :map))))
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
:author "Simon Brooke"}
|
||||
geocsv-lite.gis
|
||||
(:require [cljs.reader :refer [read-string]]
|
||||
[clojure.string :as cs]))
|
||||
[clojure.string :as cs]
|
||||
[geocsv-lite.notify :as n]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
|
@ -39,28 +40,28 @@
|
|||
(fn [position]
|
||||
(let [lat (.-latitude (.-coords position))
|
||||
lng (.-longitude (.-coords position))]
|
||||
(js/console.log (str "Current location is: " lat ", " lng))
|
||||
(n/message (str "Current location is: " lat ", " lng))
|
||||
(if
|
||||
(and view (float? lat) (float? lng))
|
||||
(do
|
||||
(.panTo view (.latLng js/L lat lng)))
|
||||
(do
|
||||
(js/console.log
|
||||
(n/message
|
||||
(if view
|
||||
(str "Geolocation failed lat: '" lat "'; lng '" lng "'")
|
||||
"No value for subscription to [:view]"))
|
||||
0)))))
|
||||
(do
|
||||
(js/console.log "Geolocation not available")
|
||||
(n/message "Geolocation not available")
|
||||
0))
|
||||
(catch js/Object any
|
||||
(js/console.log "Exception while trying to access location: " + any)
|
||||
(n/error (str "Exception while trying to access location: " any))
|
||||
0)))
|
||||
|
||||
|
||||
(defn map-pin-click-handler
|
||||
[id]
|
||||
(js/console.log (str "Click handler for record #" id)))
|
||||
(n/message (str "Click handler for record #" id)))
|
||||
|
||||
|
||||
(defn pin-image
|
||||
|
@ -139,7 +140,7 @@
|
|||
:title (:name record)}))]
|
||||
(.bindPopup marker (popup-table-content record))
|
||||
(.addTo marker view)
|
||||
(js/console.log (str "Added `"(:name record)"` in at " lat ", " lng))
|
||||
(n/message (str "Added `"(:name record)"` in at " lat ", " lng))
|
||||
marker))))
|
||||
|
||||
(defn map-remove-pins
|
||||
|
@ -170,10 +171,12 @@
|
|||
centre of the locations of these records as indicated by the values of their
|
||||
`:latitude` and `:longitude` keys."
|
||||
[records]
|
||||
(let [lats (map js/Number (map :latitude records))
|
||||
(let [lats (remove zero?
|
||||
(filter number? (map js/Number (map :latitude records))))
|
||||
min-lat (apply min lats)
|
||||
max-lat (apply max lats)
|
||||
lngs (filter js/Number (map :longitude records))
|
||||
lngs (remove zero?
|
||||
(filter number? (map js/Number (map :longitude records))))
|
||||
min-lng (apply min lngs)
|
||||
max-lng (apply max lngs)]
|
||||
(if-not
|
||||
|
@ -189,15 +192,16 @@
|
|||
[view records]
|
||||
(let [view (map-remove-pins view)
|
||||
centre (compute-centre records)]
|
||||
(js/console.log (str "refresh-map-pins called; " (count records) " records, centre at " centre))
|
||||
(js/console.log (str "Type of longitude " (:longitude (first records)) " is: " (type (:longitude (first records)))))
|
||||
(if
|
||||
view
|
||||
(let [added (remove nil? (map #(add-map-pin %1 %2 view) records (range)))]
|
||||
(js/console.log (str "Adding " (count added) " pins"))
|
||||
(do
|
||||
(n/message
|
||||
(str
|
||||
"Mapped "
|
||||
(count
|
||||
(remove nil? (map #(add-map-pin %1 %2 view) records (range))))
|
||||
" records, centre at " centre))
|
||||
(if
|
||||
(:latitude centre)
|
||||
(do
|
||||
(js/console.log (str "computed centre: " centre))
|
||||
(.setView view (clj->js [(:latitude centre) (:longitude centre)]) (:zoom centre)))))
|
||||
(do (js/console.log "View is not yet ready")))))
|
||||
(.setView view (clj->js [(:latitude centre) (:longitude centre)]) (:zoom centre))))
|
||||
(do (n/error "View is not yet ready")))))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(ns geocsv-lite.map
|
||||
(:require ))
|
||||
(:require [geocsv-lite.notify :as n]))
|
||||
|
||||
;;; Cribbed heavily from
|
||||
;;; https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/leaflet
|
||||
|
@ -76,15 +76,15 @@
|
|||
v (or
|
||||
(@views k)
|
||||
(map-did-mount id lat lng zoom))]
|
||||
(js/console.log (str "Added Leaflet view to element with id `" id "`"))
|
||||
(n/message (str "Added Leaflet view to element with id `" id "`"))
|
||||
(swap! views assoc k v)
|
||||
v))
|
||||
|
||||
|
||||
(defn get-view
|
||||
[k]
|
||||
(when-not (keyword? k) (js/console.log "Key `" k "` passed to get-view is not a keyword"))
|
||||
(when-not (k @views) (js/console.log "Key `" k "` does not identify a known view"))
|
||||
(when-not (keyword? k) (n/message (str "Key `" k "` passed to get-view is not a keyword")))
|
||||
(when-not (k @views) (n/message (str "Key `" k "` does not identify a known view")))
|
||||
(k @views))
|
||||
|
||||
|
||||
|
|
13
src/geocsv_lite/notify.cljs
Normal file
13
src/geocsv_lite/notify.cljs
Normal file
|
@ -0,0 +1,13 @@
|
|||
(ns geocsv-lite.notify
|
||||
(:require [clojure.browser.dom :as dom]))
|
||||
|
||||
(defn message
|
||||
[msg]
|
||||
(js/console.log msg)
|
||||
(dom/set-text (.getElementById js/document "message") msg))
|
||||
|
||||
|
||||
(defn error
|
||||
[err]
|
||||
(js/console.error err)
|
||||
(dom/set-text (.getElementById js/document "error") err))
|
Loading…
Reference in a new issue