gmaps, javascript, markerclusterer

Markerclusterer clearMarkers

03.29.10 | 2 Comments

In the last two posts, I described a bug but later I realized it was a false positive.
There was no bug in the library Markerclusterer (gmaps-utility-library-dev).

The false positive was mainly caused by my initial mistake.

Before explaining the initial mistake that could still be common, and lead others in “error”, I would like to clarify that both rev.1159 and rev.1214 (current) do not contain the bug I thought I had found.

There is no need to patch the library by adding the destroy method.

The library Markerclusterer already exposes a method to correctly destroy the clusters: clearMarkers .

clearMarkers works

The initial mistake I made was to isolate within a function instance

var markerclusterer = new Markerclusterer(map, points);

Having Isolated markercluster in the function called by the form, at each form submit I wouldn’t be able to call clearMarkers methods, not having access to the previously created instances.

map.clearOverlay() is not enough .

You have to remove the clusters explicitly otherwise the first trigger ZoomIn ZoomOut keys of the map would show clusters of the previous search.

To summarize, use the library Markerclusterer

1) before removing the clusters:

markerclusterer.clearMarkers();

2) then wipe the map with

map.clearOverlays();

For those who want to analyze the working code I release two demos that are going to overwrite the previous:

Another thing that could lead to errors (more false positives) is that after a zoom in / out clusters might be slightly different.

Searching “Test 2″ you’ll find 3 clusters over the Western Alps

Triggering a ZoomOut and then a ZoomIn, the clusters will be slightly different than before. Increasing the number of clusters it’s clearer something went wrong.

Popularity: 25% [?]

2 Trackbacks

  1. [...] clearmarkers bug demo 03.15.10 | 2 Comments ATTENTION : This post started from a mistake. Demos are updated with the correct use of clearMarkers (which is bug [...]

  2. [...] clearMarkers bugfix 12.01.09 | 11 Comments ATTENTION : This post started from a mistake. Demos are updated with the correct use of clearMarkers (which is bug [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*