Re: Google Maps in Clojurescript

2011-11-22 Thread Chris Gray
Hi,

Just to add another way of doing the same thing, I used the following
when I was using Google Maps in Clojurescript:

(def map-opts (extend-object! (js-obj) {"zoom" 4
"center" center-of-us
"mapTypeId" types/ROADMAP}))

The strange thing (to me) is that extend-object! is defined with defn-
in cljs.core, but it works in other namespaces.  However, it is not used
anywhere else in cljs.core, so I'm wondering if it should be made public
or just gotten rid of.

Cheers,
Chris

On Tue, 22 Nov 2011 14:07:59 -0500, Sam Ritchie  wrote:
> Roman, I apologize, I never thanked you for this. I finally got around to
> trying this out last night and put together this small project for anyone
> else interested:
> 
> https://github.com/sritchie/contour
> 
> I'm using Noir server-side. This is just a demo now, but we'll see what
> comes of it. Here's what it looks like in the wild:
> 
> http://contour.herokuapp.com/.
> 
> On Sun, Oct 9, 2011 at 6:27 AM, r0man wrote:
> 
> > Forgot to mention my init-map fn:
> >
> > (defn init-map [element]
> >   (let [options (h/clj->js {:zoom 1 :mapTypeId
> > google.maps.MapTypeId.ROADMAP})
> > parent-size (style/getSize (. element parentNode))
> > element-size (style/getSize element)
> > map (doto (google.maps.Map. element options)
> >   (. (setCenter (to-lat-lng *location*)))
> >   (. (setZoom 10)))]
> > (style/setSize element (. element-size width) (. parent-size height))
> > (events/listen
> >  viewport-monitor
> >  events/EventType.RESIZE
> >  (fn [event] (google.maps.event/trigger map "resize")
> >
> >
> >  --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> >
> 
> 
> 
> -- 
> Sam Ritchie, Twitter Inc
> 703.662.1337
> @sritchie09
> 
> (Too brief? Here's why! http://emailcharter.org)
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=enNon-text part: text/html

-- 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Google Maps in Clojurescript

2011-11-22 Thread Sam Ritchie
Roman, I apologize, I never thanked you for this. I finally got around to
trying this out last night and put together this small project for anyone
else interested:

https://github.com/sritchie/contour

I'm using Noir server-side. This is just a demo now, but we'll see what
comes of it. Here's what it looks like in the wild:

http://contour.herokuapp.com/.

On Sun, Oct 9, 2011 at 6:27 AM, r0man wrote:

> Forgot to mention my init-map fn:
>
> (defn init-map [element]
>   (let [options (h/clj->js {:zoom 1 :mapTypeId
> google.maps.MapTypeId.ROADMAP})
> parent-size (style/getSize (. element parentNode))
> element-size (style/getSize element)
> map (doto (google.maps.Map. element options)
>   (. (setCenter (to-lat-lng *location*)))
>   (. (setZoom 10)))]
> (style/setSize element (. element-size width) (. parent-size height))
> (events/listen
>  viewport-monitor
>  events/EventType.RESIZE
>  (fn [event] (google.maps.event/trigger map "resize")
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>



-- 
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie09

(Too brief? Here's why! http://emailcharter.org)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Google Maps in Clojurescript

2011-10-09 Thread r0man
Forgot to mention my init-map fn:

(defn init-map [element]
  (let [options (h/clj->js {:zoom 1 :mapTypeId 
google.maps.MapTypeId.ROADMAP})
parent-size (style/getSize (. element parentNode))
element-size (style/getSize element)
map (doto (google.maps.Map. element options)
  (. (setCenter (to-lat-lng *location*)))
  (. (setZoom 10)))]
(style/setSize element (. element-size width) (. parent-size height))
(events/listen
 viewport-monitor
 events/EventType.RESIZE
 (fn [event] (google.maps.event/trigger map "resize")

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Google Maps in Clojurescript

2011-10-09 Thread r0man
Hi Sam,

this is how I use Google Maps with Clojurescript. In the html
page I load Google's Loader library, the Google Closure base.js
file and the deps.js file which is the one cljsc spit out.

(defhtml javascripts []
  (html
   (include-js (str "https://www.google.com/jsapi?key="; (google-api-key)))
   (if (development?) (include-js "/javascripts/goog/base.js"))
   (include-js "/javascripts/deps.js")
   (if (development?) (javascript-tag 
"goog.require('burningswell.application');"

After those have been loaded I require my application namespace,
which calls the start fn at the end of the file. Something like
this:

(defn ^:export start []
  (. js/google (load "maps" "3.6", (h/clj->js {:other_params 
"sensor=false"})))
  (. js/google
 (setOnLoadCallback
  (fn []
 (set! *map* (init-map (goog.dom/getElement "map")))

(start)

I compile Clojurescript files with this command:

cljsc src/cljs '{:externs 
["closure-compiler/contrib/externs/maps/google_maps_api_v3_6.js" 
"closure-compiler/contrib/externs/google_loader_api.js"] :output-dir 
"resources/public/javascripts"}' > resources/public/javascripts/deps.js

The important stuff is the externs option when using advanced
mode. This worked for me quiet well so far. I used this way
because I want to access the user's client location via Google's
loader API.

A simpler way is to include only the Google Maps javascript file
and it's extern file. That used to work also fine ...

Hope this helps, Roman.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en