Skip to content

Instantly share code, notes, and snippets.

@LispyAriaro
Forked from stepankuzmin/geolocation.cljs
Last active August 29, 2015 14:15
Show Gist options
  • Save LispyAriaro/76865206564d3308bd8a to your computer and use it in GitHub Desktop.
Save LispyAriaro/76865206564d3308bd8a to your computer and use it in GitHub Desktop.
(def urls (array "http://a.tile.openstreetmap.org/${z}/${x}/${y}.png"
"http://b.tile.openstreetmap.org/${z}/${x}/${y}.png"
"http://c.tile.openstreetmap.org/${z}/${x}/${y}.png"))
(def OSM (js/OpenLayers.Layer.XYZ. "OSM (with buffer)" urls (extend-object! (js-obj) {"transitionEffect" "resize"
"buffer" 2
"wrapDateLine" true
"sphericalMercator" true})))
(def plot (js/OpenLayers.Map. (extend-object! (js-obj) {"div" "plot"
"layers" (array OSM)
"center" (array 0 0)
"zoom" 3
"controls" (array (js/OpenLayers.Control.Navigation. (extend-object! (js-obj) {"dragPanOptions" (extend-object! (js-obj) {"enableKinetic" true})}))
(js/OpenLayers.Control.PanZoom.)
(js/OpenLayers.Control.LayerSwitcher.))})))
; Geolocation
(defn geolocation [position]
(def longitude (.-longitude js/position.coords))
(def latitude (.-latitude js/position.coords))
(def projection (js/OpenLayers.Projection. "EPSG:4326"))
(def center (.transform (js/OpenLayers.LonLat. longitude latitude) projection (.getProjectionObject plot)))
(.setCenter plot center 18))
(.getCurrentPosition js/navigator.geolocation. geolocation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment