Skip to content

Commit

Permalink
Added two working tile layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie committed Nov 22, 2011
1 parent f544ab3 commit d1f7639
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
23 changes: 19 additions & 4 deletions resources/public/cljs/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12859,14 +12859,29 @@ contour.util.clj__GT_js = function clj__GT_js(b) {
contour.repl = {};
clojure.browser.repl.connect.call(null, "http://localhost:9000/repl");
contour.mapview = {};
contour.mapview.default_opts = cljs.core.ObjMap.fromObject(["\ufdd0'zoom", "\ufdd0'mapTypeId", "\ufdd0'center"], {"\ufdd0'zoom":8, "\ufdd0'mapTypeId":google.maps.MapTypeId.ROADMAP, "\ufdd0'center":new google.maps.LatLng(-34.397, 150.644)});
contour.mapview.iucn_root = "http://184.73.201.235/blue/";
contour.mapview.forma_root = "http://formatiles.s3.amazonaws.com/tiles/forma";
contour.mapview.forma_tile_url = function(a, b) {
var c = Math.pow.call(null, 2, b);
return cljs.core.str.call(null, contour.mapview.forma_root, b, "/", Math.abs.call(null, a.x), "/", cljs.core._.call(null, c, a.y, 1), ".png")
};
contour.mapview.iucn_tile_url = function(a, b) {
return cljs.core.str.call(null, contour.mapview.iucn_root, b, "/", a.x, "/", a.y)
};
contour.mapview.overlay_defaults = cljs.core.ObjMap.fromObject(["\ufdd0'minZ", "\ufdd0'maxZ", "\ufdd0'tileSize"], {"\ufdd0'minZ":3, "\ufdd0'maxZ":10, "\ufdd0'tileSize":new google.maps.Size(256, 256)});
contour.mapview.mk_overlay = function(a, b, c) {
a = contour.util.clj__GT_js.call(null, cljs.core.merge.call(null, contour.mapview.overlay_defaults, cljs.core.ObjMap.fromObject(["\ufdd0'name", "\ufdd0'opacity", "\ufdd0'getTileUrl"], {"\ufdd0'name":a, "\ufdd0'opacity":c, "\ufdd0'getTileUrl":b})));
return new google.maps.ImageMapType(a)
};
contour.mapview.map_opts = cljs.core.ObjMap.fromObject(["\ufdd0'zoom", "\ufdd0'mapTypeId", "\ufdd0'center"], {"\ufdd0'zoom":8, "\ufdd0'mapTypeId":google.maps.MapTypeId.ROADMAP, "\ufdd0'center":new google.maps.LatLng(-34.397, 150.644)});
contour.mapview.init_map = function(a) {
var b = contour.util.clj__GT_js.call(null, contour.mapview.default_opts);
return new google.maps.Map(a, b)
var b = contour.util.clj__GT_js.call(null, contour.mapview.map_opts), a = new google.maps.Map(a, b), b = a.overlayMapTypes;
b.insertAt(0, contour.mapview.mk_overlay.call(null, "iucn", contour.mapview.iucn_tile_url, 0.5));
b.insertAt(1, contour.mapview.mk_overlay.call(null, "forma", contour.mapview.forma_tile_url, 1));
return a
};
contour.mapview._STAR_map_STAR_ = null;
contour.mapview.map_load = function() {
return contour.mapview._STAR_map_STAR_ = contour.mapview.init_map.call(null, goog.dom.getElement.call(null, "map_canvas"))
};
goog.exportSymbol("contour.mapview.map_load", contour.mapview.map_load);
goog.events.listen.call(null, window, "load", contour.mapview.map_load);
53 changes: 45 additions & 8 deletions src/cljs/contour/mapview.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,58 @@
[goog.events :as events]
[goog.style :as style]))

(def default-opts
(def iucn-root "http://184.73.201.235/blue/")
(def forma-root "http://formatiles.s3.amazonaws.com/tiles/forma")

(defn forma-tile-url [coord zoom]
(let [bound (Math/pow 2 zoom)]
(str forma-root
zoom "/"
(Math/abs (.x coord)) "/"
(- bound (.y coord) 1) ".png")))

(defn iucn-tile-url [coord zoom]
(str iucn-root
zoom "/"
(.x coord) "/"
(.y coord)))

(def overlay-defaults
{:minZ 3
:maxZ 10
:tileSize (google.maps.Size. 256 256)})

(defn mk-overlay
[name-str url-func opacity]
(let [opts (u/clj->js
(merge overlay-defaults
{:name name-str
:opacity opacity
:getTileUrl url-func}))]
(google.maps.ImageMapType. opts)))

;; Default initial map options.
(def map-opts
{:zoom 8
:mapTypeId google.maps.MapTypeId.ROADMAP
:center (google.maps.LatLng. -34.397, 150.644)})

(defn init-map [element]
(let [options (u/clj->js default-opts)]
(google.maps.Map. element options)))
(let [options (u/clj->js map-opts)
map (google.maps.Map. element options)]
(doto (.overlayMapTypes map)
(. (insertAt 0 (mk-overlay "iucn" iucn-tile-url 0.5)))
(. (insertAt 1 (mk-overlay "forma" forma-tile-url 1))))
map))

;; We don't really need to bind this to anything, but it helps to have
;; a reference to it from the callback for later coding.
(def *map* nil)

(defn ^:export map-load []
(defn map-load []
(set! *map* (init-map
(goog.dom/getElement
"map_canvas"))))
(goog.dom/getElement "map_canvas"))))

;; Sets the whole business in motion.
(events/listen js/window "load" map-load)
;; Callback!
(events/listen js/window "load"
map-load)

0 comments on commit d1f7639

Please sign in to comment.