1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
 
   2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
 
   3  * text of the license. */
 
   4 // @require: OpenLayers/Layer.js
 
   6 // load Google map control script
 
   7 // this key was generated for: http://openlayers.python-hosting.com/testing/euzuro/
 
   8 document.write("<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAmQ3udCHPQVB_9T_edFZ7YRRRlP-tOiFgaSzksg_0w1dphL9c5BTfdJMKT91b0UJGibNcWEM0Q5-O1w'></script>");
 
  13 OpenLayers.Layer.Google = Class.create();
 
  14 OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
 
  19     /** @type GMap2 gmap stores the Google Map element */
 
  28      * @param {String} name
 
  30     initialize: function(name) {
 
  31         OpenLayers.Layer.prototype.initialize.apply(this, [name]);
 
  35      * @param {OpenLayers.Map} map
 
  37     setMap:function(map) {
 
  38         OpenLayers.Layer.prototype.setMap.apply(this, arguments);
 
  40         // once our layer has been added to the map, we can create the vemap
 
  41         this.map.events.register("addlayer", this, this.loadGMap);
 
  44     /** Google layer is always a base class.
 
  47     isBaseLayer: function() {
 
  52      * @param {OpenLayers.Bounds} bounds
 
  53      * @param {int} zoomChanged
 
  55     moveTo:function(bounds,zoomChanged) {
 
  57         if ((this.gmap != null) && (!this.dragging)) {
 
  59             var olCenter = this.map.getCenter();
 
  60             var gCenter = this.getGMapCenter();
 
  62             var olZoom = this.map.getZoom();
 
  63             var gZoom = this.gmap.getZoom();
 
  65             if ((!olCenter.equals(gCenter)) || ((olZoom +1) != gZoom)) {
 
  66                 this.gmap.setCenter(new GLatLng(olCenter.lat, olCenter.lon), 
 
  76         // create div and set to same size as map
 
  77         var gDiv = OpenLayers.Util.createDiv(this.name);
 
  78         var sz = this.map.getSize();
 
  79         gDiv.style.width = sz.w;
 
  80         gDiv.style.height = sz.h;
 
  81         this.div.appendChild(gDiv);
 
  83         // create GMap, hide nav controls
 
  84         this.gmap = new GMap2(this.div);
 
  87         // catch pans and zooms from GMap
 
  88         GEvent.addListener(this.gmap, 
 
  90                            this.catchPanZoom.bindAsEventListener(this)); 
 
  93         // attach to the drag start and end and we´ll set a flag so that
 
  94         //  we dont get recursivity. this is because the events fall through
 
  95         //  the gmaps div and into the main layer div
 
  96         GEvent.addListener(this.gmap, 
 
  98                            this.dragStart.bindAsEventListener(this)); 
 
 100         GEvent.addListener(this.gmap, 
 
 102                            this.dragEnd.bindAsEventListener(this)); 
 
 109     dragStart: function() {
 
 110         this.dragging = true;
 
 116     dragEnd: function() {
 
 117         this.dragging = false;
 
 125     catchPanZoom: function(e) { 
 
 126         var olCenter = this.getGMapCenter();
 
 127         var gZoom = this.gmap.getZoom();
 
 129         this.map.setCenter(olCenter, gZoom - 1);
 
 136      * @returns An OpenLayers.LonLat with the center of the gmap, or null if 
 
 137      *           the GMap has not been centered yet
 
 138      * @type OpenLayers.LonLat
 
 140     getGMapCenter:function() {
 
 142         var gCenter = this.gmap.getCenter();
 
 143         if (gCenter != null) {
 
 144             olCenter = new OpenLayers.LonLat(gCenter.lng(), gCenter.lat());
 
 150     /** @final @type String */
 
 151     CLASS_NAME: "OpenLayers.Layer.Google"