Map pins on map working!

This commit is contained in:
Simon Brooke 2017-03-26 11:30:41 +01:00
parent b95fa9919e
commit 6c50592543

View file

@ -62,23 +62,27 @@
"Add a map-pin with this pin-image at this latitude and longitude "Add a map-pin with this pin-image at this latitude and longitude
in this map view" in this map view"
[latitude longitude pin-image view] [latitude longitude pin-image view]
(let [pin (js/console.log (str "Adding pin " pin-image " at " latitude "," longitude))
(.Icon js/L (let [pin (.icon js/L
{:iconUrl (str "img/map-pins/" pin-image ".png") (clj->js
:shadorUrl "img/map-pins/shadow_pin.png" {:iconUrl (str "img/map-pins/" pin-image ".png")
:iconSize [32 42] :shadowUrl "img/map-pins/shadow_pin.png"
:shadowSize [57 24] :iconSize [32 42]
:iconAnchor [16 41] :shadowSize [57 24]
:shadowAnchor [16 23]} :iconAnchor [16 41]
)] :shadowAnchor [16 23]}))
(.addTp (.marker js/L [latitude longitude] {:icon pin})) view)) marker (.marker js/L
(.latLng js/L 55.82 -4.25)
(clj->js {:icon pin}))
]
(.addTo marker view)))
;; My gods mapbox is user-hostile! ;; My gods mapbox is user-hostile!
(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)."
[] []
(let [view (.setView (.map js/L "map") #js [55.82 -4.25] 13)] (let [view (.setView (.map js/L "map" (clj->js {:zoomControl "false"})) #js [55.82 -4.25] 13)]
;; NEED TO REPLACE FIXME with your mapID! ;; NEED TO REPLACE FIXME with your mapID!
(.addTo (.tileLayer js/L "http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png" (.addTo (.tileLayer js/L "http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png"
(clj->js {:attribution "Map data © [...]" (clj->js {:attribution "Map data © [...]"
@ -87,15 +91,16 @@
(defn map-did-mount-osm (defn map-did-mount-osm
"Did-mount function loading map tile data from Open Street Map (open)." "Did-mount function loading map tile data from Open Street Map."
[] []
(let [view (.setView (.map js/L "map") #js [55.86 -4.25] 13) (let [view (.setView (.map js/L "map" (clj->js {:zoomControl false})) #js [55.82 -4.25] 13)
addresses @(subscribe [:addresses])] addresses @(subscribe [:addresses])]
(js/console.log (str "Adding " (count addresses) " pins"))
(doall (map #(add-map-pin (:latitude %) (:longitude %) (pin-image %) view) addresses))
(.addTo (.tileLayer js/L osm-url (.addTo (.tileLayer js/L osm-url
(clj->js {:attribution osm-attrib (clj->js {:attribution osm-attrib
:maxZoom 18})) :maxZoom 18}))
view) view)
;; (map #(add-map-pin (:latitude %) (:longitude %) (pin-image %) view) addresses)
)) ))