hack, javascript

MarkerClusterer clearMarkers bugfix

12.01.09 | 12 Comments
ATTENTION : This post started from a mistake.
Demos are updated with the correct use of clearMarkers (which is bug free).

(This should be a crosspost written with Carlo)

It seems that MarkerClusterer has a bug, fixed with this patch (*) written by me while I was hunting with Carlo for it on this application (now working fine): after the ajax submit and zooming out, the library was still displaying old clusters and markers, because, after destroying MarkerClusterer, the event assigned to GEvent wasn’t correctly removed.

(*) the patch is created against the r1159 version on gmaps-utility-library-dev.

Popularity: 12% [?]

10 Comments

  1. Dani
    Posted 9 December 2009 at 12:02 | Permalink

    Hi,
    is there a way to show in JGcharts the X_axis verticaly and not horizontaly?
    Thanks in advance,
    Dani.

  2. Posted 15 December 2009 at 00:03 | Permalink

    Thank You.I wasted two days to debug this issue. Hope ur bug fix helps.

  3. Posted 15 December 2009 at 00:30 | Permalink

    I modified the markerclusterer.js with this patch. but think something is missing.cant figure out where are you calling the destroy.Is it possible to get the complete updated version of js file.could not find it on gmaps-utility-library-dev.

    Thanks,
    Neerju

  4. Posted 15 December 2009 at 09:51 | Permalink

    @NeerjuGupta: you can download the original js at the following uri

    http://code.google.com/p/gmaps-utility-library-dev/source/browse/trunk/markerclusterer/src/markerclusterer.js

  5. Posted 15 December 2009 at 19:45 | Permalink

    Hi,

    Faced few more issues after applying above patch. I was trying to clear the markers and readd them based on some criteria.Problem was after calling ‘destroy’ it removed the listener and never added it back.So for newly added markers cluster stopped redrawing itself.have fixed the issues as follows.

    3.38 @@ -375,22 +379,43 @@
    3.39 * @param {Array of GMarker} markers The markers you want to add.
    3.40 */
    3.41 this.addMarkers = function (markers) {
    3.42 -
    3.43 for (var i = 0; i < markers.length; ++i) {
    3.44 this.addMarker(markers[i], true);
    3.45 }
    3.46 this.redraw_();
    3.47 + //##neerjug fixed for clearMarkers.
    3.48 + if (!mcfn_ || mcfn_=== null) {
    3.49 + mcfn_ = GEvent.addListener(map_, "moveend", function(){
    3.50 + me_.resetViewport();
    3.51 + });
    3.52 + }
    3.53 };
    3.54
    3.55 // initialize
    3.56 if (typeof opt_markers === "object" && opt_markers !== null) {
    3.57 this.addMarkers(opt_markers);
    3.58 +
    3.59 }
    3.60 + // when map move end, regroup.
    3.61 + //neerjug modified.it was a bug. moveend was not behaving properly after clearmarkers if fired.
    3.62 +// mcfn_ = GEvent.addListener(map_, "moveend", function(){
    3.63 +// me_.resetViewport();
    3.64 +// });
    3.65 + //###max
    3.66 + this.destroy = function(){
    3.67 + this.clearMarkers();
    3.68 + if (mcfn_ != null) {
    3.69 + GEvent.removeListener(mcfn_);
    3.70 + mcfn_ = null;
    3.71 + //me_ = null;
    3.72 + }
    3.73 +
    3.74 +
    3.75 + }
    3.76 + //###max
    3.77
    3.78 – // when map move end, regroup.
    3.79 – mcfn_ = GEvent.addListener(map_, "moveend", function () {
    3.80 – me_.resetViewport();
    3.81 – });
    3.82 + //##neerjug end of fixes for clear markers.
    3.83 +
    3.84 }

  6. Posted 7 January 2010 at 20:08 | Permalink

    Hi
    I’m using the MarkerClusterer to display my photos. At one point I always have to completely recreate the clusterer, because the clearMarkersMarkers() method doesn’t seem to work. Searching google I found your patch. I added you patch, but It doesn’t seem to make a difference. as NeerjuGupta I don’t understand your code. You added:

    ...
     this.destroy = function() {
    		this.clearMarkers();
    		GEvent.removeListener(mcfn_);
    		mcfn_ = null;
    		me_ = null;
    	}
    ...
    

    but this.destroy get’s never called?

  7. Posted 15 January 2010 at 11:28 | Permalink

    @simon

    see here
    http://www.piemonteitalia.eu/index.php?option=com_mappet

    the “main” of the application is here:
    http://www.piemonteitalia.eu/components/com_mappet/views/mappet/js/mappet.js

    when i submit the form I invoke processJson
    in function “processJson” I call
    markerCluster.destroy();

    I hope I have been of help to you

  8. Nick
    Posted 13 March 2010 at 04:21 | Permalink

    I just wanted to say a deep and heartfelt thanks for this patch! This issue was driving me crazy today.

    Have you submitted this or a bug report to the project? The fact the documented call is not functional will likely hit others it would be great to see this fix incorporated.

  9. Posted 15 March 2010 at 16:05 | Permalink

    @Nick

    http://maxb.net/blog/2010/03/15/markerclusterer-clearmarkers-bug-demo/

    http://code.google.com/p/gmaps-utility-library-dev/issues/detail?id=196

  10. Nick
    Posted 15 March 2010 at 18:41 | Permalink

    Thanks for that additional information.

    I just saw this:

    http://code.google.com/p/gmaps-utility-library-dev/source/detail?r=1214

    It appears the bug may have been addressed in r1214 which was just committed last week.

    I’m going to check out 1214 now and see how it goes.

    Cheers

2 Trackbacks

  1. By MarkerClusterer clearMarkers bugfix on 1 December 2009 at 15:36

    [...] (This should be a crosspost written with Massimiliano) [...]

  2. [...] the last two posts, I described a bug but later I realized it was a false positive. There was no bug in the [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*