Skip to content

Instantly share code, notes, and snippets.

@maleghast
Last active November 27, 2017 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maleghast/386abf921d54840f06682e27d81223e5 to your computer and use it in GitHub Desktop.
Save maleghast/386abf921d54840f06682e27d81223e5 to your computer and use it in GitHub Desktop.
Adding markers to maps, LeafletJS and ClojureScript...
(defn re-leaflet-update-markers
[mapatom mapname markers]
(let [mapinst @mapatom]
(doall
(for [marker (get markers mapname)]
(-> (js/L.marker
(array
(:lat marker)
(:long marker))
#js {:marker (case (:icon marker)
"dark" (js/L.icon (clj->js
{:shadowUrl "/public/icon/map_markers/shadow.png"
:iconUrl "/public/icon/map_markers/dark.png"
:iconSize [86 146]
:shadowSize [124 160]
:iconAnchor [43 145]
:shadowAnchor [1 159]
:popupAnchor [43 43]}))
"red" (js/L.icon (clj->js
{:shadowUrl "/public/icon/map_markers/shadow.png"
:iconUrl "/public/icon/map_markers/red.png"
:iconSize [86 146]
:shadowSize [124 160]
:iconAnchor [43 145]
:shadowAnchor [1 159]
:popupAnchor [43 43]}))
"orange" (js/L.icon (clj->js
{:shadowUrl "/public/icon/map_markers/shadow.png"
:iconUrl "/public/icon/map_markers/orange.png"
:iconSize [86 146]
:shadowSize [124 160]
:iconAnchor [43 145]
:shadowAnchor [1 159]
:popupAnchor [43 43]}))
"green" (js/L.icon (clj->js
{:shadowUrl "/public/icon/map_markers/shadow.png"
:iconUrl "/public/icon/map_markers/green.png"
:iconSize [86 146]
:shadowSize [124 160]
:iconAnchor [43 145]
:shadowAnchor [1 159]
:popupAnchor [43 43]}))
(js/L.icon (clj->js
{:shadowUrl "/public/icon/map_markers/shadow.png"
:iconUrl "/public/icon/map_markers/green.png"
:iconSize [86 146]
:shadowSize [124 160]
:iconAnchor [43 145]
:shadowAnchor [1 159]
:popupAnchor [43 43]})))})
(.addTo mapinst)
(.bindPopup (:name marker)))))
(reset! mapatom mapinst)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment