title: How do I pass google map objects to members in a jQuery namespace?
body: <p>I am spinning my tires while beginning to build a jQuery plugin for Google Maps v3. I have read through: <a href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern#closure" rel="nofollow">"A Plugin Development Pattern"</a>, <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">Plugins/Authoring</a>, and looked over a number of plugins for v2, but I am stuck on how to properly initialize the map, so that I can meet these three objectives:</p>
  
  <ol>
  <li>Only create a new Map if there isn't one in the selected element.</li>
  <li>Allow chaining on any existing Map.</li>
  <li>Have the methods callable on the object (e.g. <code>$.gmap.method()</code> instead of <code>$.gmap('method')</code>). </li>
  </ol>
  
  <p>Apologies if this is poorly phrased, but basically I want a wrapper around the Map object, so that I can build out Google Maps with similar data much more quickly.</p>
  
  <p>Here is what I've got so far:</p>
  
  <pre><code>
  (function ($) {
      $.fn.gmap = function(options) {
          var opts = $.extend({}, $.fn.gmap.defaults, options);
  
          return this.each(function(){
              $gmap = new google.maps.Map(this, opts);
              return $gmap;
          });
      };
  
      $.fn.gmap.go = function(){
          return this.setCenter(new google.maps.LatLng(10,10));
      };
  
      $.fn.gmap.defaults = {
          zoom: 2,
          center: new google.maps.LatLng(0,0),
          mapTypeId: google.maps.MapTypeId.TERRAIN
      };
  
  })(jQuery);
  
  $('map_canvas').gmap();
  </code></pre>
  
  <p>Sorry, I know it's not very far along, but basically if someone can just nudge me over the edge where a call to <code>$('map_canvas').gmap().go()</code> or <code>$('map_canvas').gmap.go()</code> tries to call <code>Map.setCenter()</code> and does not create a new instance, then I can work through the rest.</p>
  
  <p>P.S. if anyone has already written a plugin like this, pointing that out would be even better.</p>
  
  <p>P.S.S. I have already ordered <em>jQuery Plugin Development Beginner's Guide</em>, but I really would rather get started on this before it's delivered. Other suggested reading is more than welcome.</p>
  
  <p>Thanks for any help.</p>