(function() {

// MAXB.NET LABS

})();

gmaps, hack, javascript, markerclusterer

Markerclusterer clearmarkers bug demo

Posted on by Massimiliano Balestrieri | Comments
ATTENTION : This post started from a mistake.
Demos are updated with the correct use of clearMarkers (which is bug free).

Carlo and I, working together on this application have met a problem hard to isolate and solve.

Markerclusterer library (of gmaps-utility-library-dev) has a bug.
Let me try to explain the problem.

Each cluster has an event associated with it (in fact, the click event on the cluster triggers the “zoom in” on the map and the cluster splits itself in markers or smaller clusters).
When, from the outside (for example, within a form), I clean the map – map.clearOverlays(); – and then I refill it with a new search, I’m not able anymore to destroy the clusters.
It seems the clusters are disappeared but, in fact, zooming in or out, they come back.
Look at the two following pictures.

STEP 1

STEP 2

ZOOM OUT

The first and second picture shows the clusters correctly.
The third picture instead (demo bug) shows the clusters of the second search AND the ones of the first (after having done “zoom out”).

The whole thing is due to a bug in the JavaScript garbage collection (I suppose…).
The object has been “subscribed” to an event. The object is destroyed but after the first trigger of that event, the object come back.

To fix this strange bug (it’s even hard to reproduce it, without a form!) it’s mandatory to provide to the markerclusterer library a method to correctly destroy the clusters.
The patch (the diff file has been written again the 1159 revision) adds the destroy method.
Before doing a new search, it is required to call

map.clearOverlays();

AND

markerCluster.destroy();

where markerCluster is your instance of MarkerClusterer(map, points);

The destroy() method calls:
this.clearMarkers();
GEvent.removeListener(mcfn_);
mcfn_ = null;
me_ = null;

I reported the bug to the developers with a demo of the bug itself (and a second demo with the fix). I hope my patch could help people to not get mad on it.

This entry was posted in gmaps, hack, javascript, markerclusterer and tagged , , , . Bookmark the permalink.

2 Comments

  1. justin
    Posted 25 March 2010 at 20:18 | Permalink

    I am having the same issue. Hoping you can help….

    This post started from a mistake and I’m writing a post to explain it.
    Demos are updated with the correct use of clearMarkers (which is bug free).

    1. What is the correct use of clearMarkers?
    2. What demos are you referring to?
    3. When do expect to complete your post?

  2. Posted 26 March 2010 at 12:56 | Permalink

    @justin

    1) the correct use is here:

    http://maxb.net/scripts/markerclusterer/fix.html

    js: http://maxb.net/scripts/markerclusterer/lib/mappet_fix.js

    function : processJson

    if (markerCluster && markerCluster.clearMarkers)
        markerCluster.clearMarkers();
    
    map.clearOverlays();
    
    markerCluster = new MarkerClusterer(map, points);//new search
    

    2) demos are here (a) and here (b):

    a) http://maxb.net/scripts/markerclusterer/bug.html (i don’t use markerCluster.clearMarkers();)
    b) http://maxb.net/scripts/markerclusterer/fix.html

    3) time