http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94648

Revision: 94648
Author:   jeroendedauw
Date:     2011-08-16 15:51:30 +0000 (Tue, 16 Aug 2011)
Log Message:
-----------
google earth fixes

Modified Paths:
--------------
    trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js

Modified: 
trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js
===================================================================
--- trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js     
2011-08-16 15:41:02 UTC (rev 94647)
+++ trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js     
2011-08-16 15:51:30 UTC (rev 94648)
@@ -24,7 +24,6 @@
         */
        this.addMarker = function( markerData ) {
                var markerOptions = {
-                       map: this.map,
                        position: new google.maps.LatLng( markerData.lat , 
markerData.lon ),
                        title: markerData.title
                };
@@ -106,8 +105,31 @@
                }
        };
        
-       var showEarth = $.inArray( 'earth', options.types ); 
+       this.addOverlays = function() {
+               debugger;
+               for ( i in this.markers ) {
+                       this.markers[i].setMap( map );
+               }
+               
+               // Add the Google KML/KMZ layers.
+               for ( i = options.gkml.length - 1; i >= 0; i-- ) {
+                       var kmlLayer = new google.maps.KmlLayer( 
options.gkml[i], { map: map } );
+               }
+               
+               // If there are any non-Google KML/KMZ layers, load the geoxml 
library and use it to add these layers.
+               if ( options.kml.length != 0 ) {
+                       mw.loader.using( 'ext.maps.gm3.geoxml', function() {
+                               var geoXml = new geoXML3.parser( { map: map } );
+                               
+                               for ( i = options.kml.length - 1; i >= 0; i-- ) 
{
+                                       geoXml.parse( options.kml[i] );
+                               }
+                       } );            
+               }               
+       };
        
+       var showEarth = $.inArray( 'earth', options.types ) !== -1; 
+       
        // If there are any non-Google KML/KMZ layers, load the geoxml library 
and use it to add these layers.
        if ( showEarth ) {
                this.removeEarthType();
@@ -140,52 +162,15 @@
        var map = new google.maps.Map( this.get( 0 ), mapOptions );
        this.map = map;
        
-       var markers = [];
        if ( !options.locations ) {
                options.locations = [];
        }
        
        // Add the markers.
        for ( var i = options.locations.length - 1; i >= 0; i-- ) {
-               markers.push( this.addMarker( options.locations[i] ) );
+               this.addMarker( options.locations[i] );
        }
        
-       // Add the Google KML/KMZ layers.
-       for ( i = options.gkml.length - 1; i >= 0; i-- ) {
-               var kmlLayer = new google.maps.KmlLayer( options.gkml[i], { 
map: map } );
-       }
-       
-       // If there are any non-Google KML/KMZ layers, load the geoxml library 
and use it to add these layers.
-       if ( options.kml.length != 0 ) {
-               mw.loader.using( 'ext.maps.gm3.geoxml', function() {
-                       var geoXml = new geoXML3.parser( { map: map } );
-                       
-                       for ( i = options.kml.length - 1; i >= 0; i-- ) {
-                               geoXml.parse( options.kml[i] );
-                       }
-               } );            
-       }
-       
-       if ( showEarth ) {
-               $.getScript(
-                       'https://www.google.com/jsapi?key=' + mw.config.get( 
'egGoogleJsApiKey' ),
-                       function( data, textStatus ) {
-                               google.load( 'earth', '1', { callback: 
function() {
-                                       mw.loader.using( 'ext.maps.gm3.earth', 
function() {
-                                               if ( google.earth.isSupported() 
) {
-                                                       var ge = new 
GoogleEarth( map );
-                                                       
-                                                       var lookAt = 
ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
-
-                                                       
lookAt.setTilt(lookAt.getTilt() + options.tilt);
-                                                       
ge.getView().setAbstractView(lookAt);                                           
        
-                                               }
-                                       } );    
-                               } } );
-                       }
-               );
-       }
-       
        for ( i = options.fusiontables.length - 1; i >= 0; i-- ) {
                var ftLayer = new google.maps.FusionTablesLayer( 
options.fusiontables[i], { map: map } );
        }
@@ -205,8 +190,8 @@
        if ( ( options.centre === false || options.zoom === false ) && 
options.locations.length > 1 ) {
                bounds = new google.maps.LatLngBounds();
 
-               for ( var i = markers.length - 1; i >= 0; i-- ) {
-                       bounds.extend( markers[i].getPosition() );
+               for ( var i = this.markers.length - 1; i >= 0; i-- ) {
+                       bounds.extend( this.markers[i].getPosition() );
                }
        }
        
@@ -236,9 +221,34 @@
        
        map.setCenter( centre );
        
+       if ( showEarth ) {
+               $.getScript(
+                       'https://www.google.com/jsapi?key=' + mw.config.get( 
'egGoogleJsApiKey' ),
+                       function( data, textStatus ) {
+                               google.load( 'earth', '1', { callback: 
function() {
+                                       mw.loader.using( 'ext.maps.gm3.earth', 
function() {
+                                               if ( google.earth.isSupported() 
) {
+                                                       var ge = new 
GoogleEarth( map );
+                                                       
+                                                       var lookAt = 
ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
+
+                                                       
lookAt.setTilt(lookAt.getTilt() + options.tilt);
+                                                       
ge.getView().setAbstractView(lookAt);                                           
        
+                                               }
+                                               debugger;
+                                               _this.addOverlays();
+                                       } );    
+                               } } );
+                       }
+               );
+       }
+       else {
+               google.maps.event.addListenerOnce( map, 'tilesloaded', 
function() { _this.addOverlays(); } );
+       }
+       
        if ( options.autoinfowindows ) {
-               for ( var i = markers.length - 1; i >= 0; i-- ) {
-                       google.maps.event.trigger( markers[i], 'click' );
+               for ( var i = this.markers.length - 1; i >= 0; i-- ) {
+                       google.maps.event.trigger( this.markers[i], 'click' );
                }               
        }
        


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to