Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created May 13, 2012 04:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stepankuzmin/2680992 to your computer and use it in GitHub Desktop.
Save stepankuzmin/2680992 to your computer and use it in GitHub Desktop.
Geolocation using ClojureScript
(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