jenkins-bot has submitted this change and it was merged.

Change subject: Rescale map after adding markers with labels
......................................................................


Rescale map after adding markers with labels

Markers with labels are added through callback to mw.loader.
Which means that they are not available when the map is scaled
to show all markers. Therefore I have extracted the rescaling code
into two functions (getBounds and setZoom) which can be called at the
original location for this code and after adding marker with label.
Split into two functions as code for centering the map also
needs the bounds object.

This commit was merged in Oct 2012, but for some reason it doesn't
exist on master (or 3.0.x), so I'm submitting it again

Fixes bug 40791

Change-Id: I61dbd498461c82fc04d622b5a2f7937d7f660af9
---
M includes/services/GoogleMaps3/jquery.googlemap.js
1 file changed, 26 insertions(+), 16 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/services/GoogleMaps3/jquery.googlemap.js 
b/includes/services/GoogleMaps3/jquery.googlemap.js
index c90b9a1..188949e 100644
--- a/includes/services/GoogleMaps3/jquery.googlemap.js
+++ b/includes/services/GoogleMaps3/jquery.googlemap.js
@@ -51,6 +51,28 @@
                this.imageoverlays = [];
 
 
+               var getBounds = function() {
+                       if (( options.centre === false || options.zoom === 
false ) && options.locations.length > 1) {
+                               bounds = new google.maps.LatLngBounds();
+
+                               for (var i = _this.markers.length - 1; i >= 0; 
i--) {
+                                       
bounds.extend(_this.markers[i].getPosition());
+                               }
+                               return bounds;
+                       }
+                       return null;
+               };
+
+               var setZoom = function(bounds) {
+                               if (options.zoom === false) {
+                               _this.map.fitBounds(bounds);
+                       }
+                       else {
+                               _this.map.setZoom(options.zoom);
+                       }
+               };
+
+
                /**
                 * Creates a new marker with the provided data,
                 * adds it to the map, and returns it.
@@ -111,7 +133,8 @@
                                        'ext.maps.gm3.markerwithlabel',
                                        function() {
                                                marker = new MarkerWithLabel( 
markerOptions );
-                                               return addToMapAndHandlers( 
marker );
+                                               addToMapAndHandlers( marker );
+                                               setZoom(getBounds());
                                        }
                                );
                        }
@@ -501,22 +524,9 @@
                                layer.setMap(map);
                        }
 
-                       var bounds;
+                       var bounds = getBounds();
 
-                       if (( options.centre === false || options.zoom === 
false ) && options.locations.length > 1) {
-                               bounds = new google.maps.LatLngBounds();
-
-                               for (var i = this.markers.length - 1; i >= 0; 
i--) {
-                                       
bounds.extend(this.markers[i].getPosition());
-                               }
-                       }
-
-                       if (options.zoom === false) {
-                               map.fitBounds(bounds);
-                       }
-                       else {
-                               map.setZoom(options.zoom);
-                       }
+                       setZoom(bounds);
 
                        var centre;
 

-- 
To view, visit https://gerrit.wikimedia.org/r/89605
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I61dbd498461c82fc04d622b5a2f7937d7f660af9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Maps
Gerrit-Branch: master
Gerrit-Owner: MathiasLidal <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Netbrain <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to