diff --git a/README.md b/README.md index 1f0b7cc..884224c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ You will need [Leiningen][1] 2.0 or above installed. To start a web server for the application, run: - lein run + lein npm install + lein run ## License diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a16f310 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "geocsv", + "version": "0.1.0-SNAPSHOT", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "leaflet": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.3.1.tgz", + "integrity": "sha512-adQOIzh+bfdridLM1xIgJ9VnJbAUY3wqs/ueF+ITla+PLQ1z47USdBKUf+iD9FuUA8RtlT6j6hZBfZoA6mW+XQ==" + } + } +} diff --git a/project.clj b/project.clj index 3ba53f9..9992b17 100644 --- a/project.clj +++ b/project.clj @@ -39,6 +39,7 @@ [selmer "1.12.18"]] :min-lein-version "2.0.0" + :npm {:dependencies [[leaflet "1.3.1"]]} :source-paths ["src/clj" "src/cljs" "src/cljc"] :test-paths ["test/clj"] @@ -46,7 +47,11 @@ :target-path "target/%s/" :main ^:skip-aot geocsv.core - :plugins [[lein-cljsbuild "1.1.7"]] + :plugins [[lein-cljsbuild "1.1.7"] + [lein-codox "0.10.7"] + [lein-npm "0.6.2"] + [lein-release "1.0.5"]] + :clean-targets ^{:protect false} [:target-path [:cljsbuild :builds :app :compiler :output-dir] [:cljsbuild :builds :app :compiler :output-to]] :figwheel diff --git a/resources/html/home.html b/resources/html/home.html index d3d806d..95b7037 100644 --- a/resources/html/home.html +++ b/resources/html/home.html @@ -6,7 +6,7 @@ Welcome to geocsv - +
@@ -36,6 +36,12 @@ + + + + + + {% script "js/lib/node_modules/leaflet/dist/leaflet.js" %} {% script "/js/app.js" %} diff --git a/resources/public/img/credits/clojure-icon.gif b/resources/public/img/credits/clojure-icon.gif new file mode 100644 index 0000000..84eee16 Binary files /dev/null and b/resources/public/img/credits/clojure-icon.gif differ diff --git a/resources/public/img/credits/github-logo-transparent.png b/resources/public/img/credits/github-logo-transparent.png new file mode 100644 index 0000000..6a37959 Binary files /dev/null and b/resources/public/img/credits/github-logo-transparent.png differ diff --git a/resources/public/img/credits/gnu.small.png b/resources/public/img/credits/gnu.small.png new file mode 100644 index 0000000..04177f6 Binary files /dev/null and b/resources/public/img/credits/gnu.small.png differ diff --git a/resources/public/img/credits/luminus-logo.png b/resources/public/img/credits/luminus-logo.png new file mode 100644 index 0000000..df6c283 Binary files /dev/null and b/resources/public/img/credits/luminus-logo.png differ diff --git a/resources/public/img/map-pins/Planning-authority-pin.png b/resources/public/img/map-pins/Planning-authority-pin.png new file mode 100644 index 0000000..12061ea Binary files /dev/null and b/resources/public/img/map-pins/Planning-authority-pin.png differ diff --git a/resources/public/img/map-pins/Planning-authority-pin.svg b/resources/public/img/map-pins/Planning-authority-pin.svg new file mode 100644 index 0000000..ca9926d --- /dev/null +++ b/resources/public/img/map-pins/Planning-authority-pin.svg @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/basic_map_pin.png b/resources/public/img/map-pins/basic_map_pin.png new file mode 100644 index 0000000..c14e0be Binary files /dev/null and b/resources/public/img/map-pins/basic_map_pin.png differ diff --git a/resources/public/img/map-pins/basic_map_pin.svg b/resources/public/img/map-pins/basic_map_pin.svg new file mode 100644 index 0000000..cd8409d --- /dev/null +++ b/resources/public/img/map-pins/basic_map_pin.svg @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + diff --git a/resources/public/img/map-pins/shadow_pin.png b/resources/public/img/map-pins/shadow_pin.png new file mode 100644 index 0000000..07c4daa Binary files /dev/null and b/resources/public/img/map-pins/shadow_pin.png differ diff --git a/resources/public/img/map-pins/shadow_pin.svg b/resources/public/img/map-pins/shadow_pin.svg new file mode 100644 index 0000000..595d104 --- /dev/null +++ b/resources/public/img/map-pins/shadow_pin.svg @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Shadow pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + shadow_pin.svg + $Revision: 1.2 $ + + + + + + + diff --git a/resources/public/img/map-pins/unknown-pin.png b/resources/public/img/map-pins/unknown-pin.png new file mode 100644 index 0000000..f0b8fbb Binary files /dev/null and b/resources/public/img/map-pins/unknown-pin.png differ diff --git a/resources/public/img/map-pins/unknown-pin.svg b/resources/public/img/map-pins/unknown-pin.svg new file mode 100644 index 0000000..638daa1 --- /dev/null +++ b/resources/public/img/map-pins/unknown-pin.svg @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + diff --git a/resources/public/img/map-pins/unknown-pin.xcf b/resources/public/img/map-pins/unknown-pin.xcf new file mode 100644 index 0000000..b55b9f8 Binary files /dev/null and b/resources/public/img/map-pins/unknown-pin.xcf differ diff --git a/resources/public/img/threelines.png b/resources/public/img/threelines.png new file mode 100644 index 0000000..72a2fe5 Binary files /dev/null and b/resources/public/img/threelines.png differ diff --git a/resources/public/img/threelines.xcf b/resources/public/img/threelines.xcf new file mode 100644 index 0000000..e609fe3 Binary files /dev/null and b/resources/public/img/threelines.xcf differ diff --git a/src/cljs/geocsv/ajax.cljs b/src/cljs/geocsv/ajax.cljs index 726d626..4605fd6 100644 --- a/src/cljs/geocsv/ajax.cljs +++ b/src/cljs/geocsv/ajax.cljs @@ -6,9 +6,11 @@ [re-frame.core :as rf])) (defn local-uri? [{:keys [uri]}] - (not (re-find #"^\w+?://" uri))) + (js/console.log (str "local-uri?: received `" (str uri) "` (type " (type uri) ") as uri")) + (not (re-find #"^\w+?://" (str uri)))) (defn default-headers [request] + (js/console.log (str "default-headers: received `" request "` as request")) (if (local-uri? request) (-> request (update :headers #(merge {"x-csrf-token" js/csrfToken} %))) diff --git a/src/cljs/geocsv/events.cljs b/src/cljs/geocsv/events.cljs index 4e4f866..cab559a 100644 --- a/src/cljs/geocsv/events.cljs +++ b/src/cljs/geocsv/events.cljs @@ -162,6 +162,11 @@ (fn [route _] (-> route :data :name))) +(rf/reg-sub + :view + (fn [db _] + (:view db))) + (rf/reg-sub :zoom (fn [db _] diff --git a/src/cljs/geocsv/gis.cljs b/src/cljs/geocsv/gis.cljs index 76b3408..9d19b4e 100644 --- a/src/cljs/geocsv/gis.cljs +++ b/src/cljs/geocsv/gis.cljs @@ -4,7 +4,7 @@ (: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 :as s] [cemerick.url :refer (url url-encode)] [day8.re-frame.http-fx] [re-frame.core :refer [dispatch reg-event-db reg-event-fx subscribe]])) @@ -51,8 +51,7 @@ (do (dispatch [:set-latitude lat]) (dispatch [:set-longitude lng]) - (.panTo view (.latLng js/L lat lng)) - (locality lat lng)) + (.panTo view (.latLng js/L lat lng))) (do (js/console.log (if view @@ -80,29 +79,65 @@ (s/replace (s/lower-case (str (:category record))) #"[^a-z0-9]" "-")) "-pin") "unknown-pin")) +(defn popup-content + "Appropriate content for the popup of a map pin for this `record`." + [record] + (str + "
" + (:name record) + "
" + (apply + str + (map #(str "
" (name %) "
" (record %) "
") (keys record))) + "
")) + +(defn popup-table-content + "Appropriate content for the popup of a map pin for this `record`, as a + table. Obviously this is semantically wrong, but for styling reasons it's + worth trying." + [record] + (str + "
" + (:name record) + "
" + (apply + str + (map #(str "") (keys record))) + "
" (name %) "" (record %) "
")) + (defn add-map-pin - "Add an appropriate map-pin for this `record` in this map `view`." + "Add an appropriate map-pin for this `record` in this map `view`, if it + has a valid `:latitude` and `:longitude`." [record index view] (let [lat (:latitude record) - lng (:longitude record) - pin (.icon js/L - (clj->js - {:iconAnchor [16 41] - :iconSize [32 42] - :iconUrl (str "img/map-pins/" (pin-image record) ".png") - :riseOnHover true - :shadowAnchor [16 23] - :shadowSize [57 24] - :shadowUrl "img/map-pins/shadow_pin.png"})) - marker (.marker js/L - (.latLng js/L lat lng) - (clj->js {:icon pin - :title (:name record)}))] - (.on + lng (:longitude record)] + (if + (and + (number? lat) + (number? lng) + (not (zero? lat)) + (not (zero? lng))) + (let [pin (.icon js/L + (clj->js + {:iconAnchor [16 41] + :iconSize [32 42] + :iconUrl (str "img/map-pins/" (pin-image record) ".png") + :riseOnHover true + :shadowAnchor [16 23] + :shadowSize [57 24] + :shadowUrl "img/map-pins/shadow_pin.png"})) + marker (.marker js/L + (.latLng js/L lat lng) + (clj->js {:icon pin + :title (:name record)}))] + (.bindPopup marker (popup-table-content record)) (.addTo marker view) - "click" - (fn [_] (map-pin-click-handler index))) - marker)) +;; (.on +;; (.addTo marker view) +;; "click" +;; (fn [_] (map-pin-click-handler index))) + (js/console.log (str "Added `"(:name record)"` in at " lat ", " lng)) + marker)))) (defn map-remove-pins "Remove all pins from this map `view`. Side-effecty; liable to be @@ -120,13 +155,12 @@ "Refresh the map pins on the current map. Side-effecty; liable to be problematic." [db] - (let [view (map-remove-pins @(re-frame/subscribe [:view])) + (let [view (map-remove-pins @(subscribe [:view])) data (:data db)] (if view - (do - (js/console.log (str "Adding " (count data) " pins")) - (doall (map #(add-map-pin %1 %2 view) data (range)))) + (let [added (remove nil? (map #(add-map-pin %1 %2 view) data (range)))] + (js/console.log (str "Adding " (count added) " pins"))) (js/console.log "View is not yet ready")) db)) diff --git a/src/cljs/geocsv/views/map.cljs b/src/cljs/geocsv/views/map.cljs index 7d1d3d5..282083b 100644 --- a/src/cljs/geocsv/views/map.cljs +++ b/src/cljs/geocsv/views/map.cljs @@ -70,12 +70,12 @@ :maxZoom 18})) view) (dispatch-sync [:set-view view]) - (.on view "moveend" - (fn [_] (let [c (.getCenter view)] - (js/console.log (str "Moving centre to " c)) - (dispatch-sync [:set-latitude (.-lat c)]) - (dispatch-sync [:set-longitude (.-lng c)]) - (dispatch [:fetch-data])))) +;; (.on view "moveend" +;; (fn [_] (let [c (.getCenter view)] +;; (js/console.log (str "Moving centre to " c)) +;; (dispatch-sync [:set-latitude (.-lat c)]) +;; (dispatch-sync [:set-longitude (.-lng c)]) +;; (dispatch [:fetch-data])))) ;; (refresh-map-pins) view)) @@ -91,7 +91,7 @@ (defn map-render "Render the actual div containing the map." [] - [:div#map {:style {:height "500px"}}]) + [:div#map {:style {:height "500px" :width "800px"}}]) (defn panel "A reagent class for the map object."