kstukstu / google-maps-utility-library-v3

Automatically exported from code.google.com/p/google-maps-utility-library-v3
0 stars 0 forks source link

bug in MarkerClusterer breaks multiple clusterers sharing a single map #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Demo link or sample code:
http://intwoplacesatonce.com/marker_clusterer/markerclusterer/examples/example_t
wo_cluster
ers.html

What steps will reproduce the problem?
1. Create an app which uses more than one MarkerClusterer on a single map. 
Navigate to the app.
2. Zoom in on a cluster repeatedly by clicking on it.
3.

Expected result:
No matter which Clusterer owns the cluster being zoomed in to, the cluster 
should break up in to 
smaller clusters as the map zooms in.

Actual result:
Only clusters owned by the "first" clusterer break in to smaller clusters.

Version: svn rev 110

Browser / Operating System:
Chrome / Mac OS X

Additional comments:
Fix for the bug is to correct 'zoom_changed' handler added in MarkerClusterer's 
constructor. 'this' 
is used where 'that' should be used. prevZoom_ ends up being stored on the Map 
object itself. On 
the second and subsequent MarkerClusterers to have their zoom_changed handler 
called, 
prevZoom_ is not != that.map_.getZoom() and the code doesn't run.

Current code:
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    if (this.prevZoom_ != that.map_.getZoom()) {
      this.prevZoom_ = that.map_.getZoom();
      that.resetViewport();
    }
  });

Minimal fix:
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    if (that.prevZoom_ != that.map_.getZoom()) {
      that.prevZoom_ = that.map_.getZoom();
      that.resetViewport();
    }
  });

Fix with a possibly stylistically broken attempt at clarifying what is going on:
  var clusterer = this;
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    var map = this;
    if (clusterer.prevZoom_ != map.getZoom()) {
      clusterer.prevZoom_ = map.getZoom();
      clusterer.resetViewport();
    }
  });

Original issue reported on code.google.com by dave.bc on 16 May 2010 at 5:47

GoogleCodeExporter commented 9 years ago
I meant to take it one step further and just have the equality check as an 
affirmative guard clause.

Fix with a possibly stylistically broken attempt at clarifying what is going on:
  var clusterer = this;
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    var map = this;
    if (clusterer.prevZoom_ == map.getZoom()) return;

    clusterer.prevZoom_ = map.getZoom();
    clusterer.resetViewport();
  });

Original comment by dave.bc on 16 May 2010 at 5:56

GoogleCodeExporter commented 9 years ago
I don't see any problems using two markerclusterers on a single map.

Original comment by lu...@google.com on 31 Mar 2011 at 6:18

GoogleCodeExporter commented 9 years ago

Original comment by lu...@google.com on 31 Mar 2011 at 6:18