scottpunshon / google-maps-utility-library-v3

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

MarkerClusterer Plus: Clusters disappear when map.fitBounds is called twice #252

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When you call map.fitBounds([someBounds]) once on a map with clusters, it will 
correctly fit the map bounds. If you however try to call fitBounds once more 
with the same bounds, all the clusters magically disappears! They reappear if 
you pan/zoom the map.

To recreate:

1. Go to the example app: 
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererpl
us/examples/advanced_example.html?

2. Open the console and run this line of code twice:
map.fitBounds(new google.maps.LatLngBounds(new google.maps.LatLng(60,10),new 
google.maps.LatLng(40,0)))

Expected result:
The map is unchanged the second time, with clusters intact.

Actual result:
The clusters disappear. Only reappears when you pan/zoom the map.

Version: 
MarkerClustererPlus v 2.0.15

Browser / Operating System:
Chrome and IE9 on Windows 7

Original issue reported on code.google.com by knutmar...@gmail.com on 30 Apr 2013 at 8:58

GoogleCodeExporter commented 9 years ago
I will look into it, thanks.

Original comment by brett.mc...@gmail.com on 16 Jul 2013 at 2:37

GoogleCodeExporter commented 9 years ago

Original comment by brett.mc...@gmail.com on 16 Jul 2013 at 3:32

GoogleCodeExporter commented 9 years ago
Hello,

I'm using MarkerClustererPlus version 2.1.1 [November 4, 2013], and I have 
exactly the same issue explained in #0. Is there any purposed solution?

Regards.

Original comment by christia...@gmail.com on 11 Mar 2014 at 5:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This problem is related to the way the "zoom_changed" is handled in 
MarkerClustererPlus.
If the zoom changes, MarkerClustererPlus will need to redraw. In anticipation, 
it clears all the markers and waits for a corresponding 'idle' event.

Unfortunately, there's 2 cases that I know of when this isn't occurring.
1) When you call setZoom with the current zoom level
2) Calling fitBounds and the zoom does not change

Related:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=4557

Without changing MarkerClustererPlus code, you can create a workaround by 
listening to the 'zoom_changed' event and when the zoom has not changed, you 
can artificially trigger an 'idle' event. This 'idle' event must be triggered 
on it's own callstack (e.g. using setTimeout), so that you can ensure that it 
is handled after MarkerClustererPlus's own 'zoom_changed' handler.
Be aware that this workaround can cause the cluster icons to momentarily flash.

Original comment by andrew.w...@gmail.com on 20 Mar 2014 at 12:21

GoogleCodeExporter commented 9 years ago
here's a quickie workaround:
after map.fitBounds(bounds) add:

mapcenter = map.getCenter();
map.setCenter(new google.maps.LatLng((mapcenter.lat() + 0.0000001), 
mapcenter.lng()));

it shifts the map by a very small amount that is not visible even at the 
highest zoom level and gets rid of this bug...

Original comment by yiorgost...@gmail.com on 14 Aug 2014 at 10:36