<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>(function() { &#187; markerclusterer</title>
	<atom:link href="http://maxb.net/blog/category/markerclusterer/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxb.net/blog</link>
	<description>// MAXB.NET LABS</description>
	<lastBuildDate>Mon, 16 May 2011 19:12:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Markerclusterer clearMarkers</title>
		<link>http://maxb.net/blog/2010/03/29/markerclusterer-clearmarkers/</link>
		<comments>http://maxb.net/blog/2010/03/29/markerclusterer-clearmarkers/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 14:23:08 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[gmaps]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[markerclusterer]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=567</guid>
		<description><![CDATA[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 &#8230; <a href="http://maxb.net/blog/2010/03/29/markerclusterer-clearmarkers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the last <a target="_blank" href="http://maxb.net/blog/2009/12/01/markerclusterer-clearmarkers-bugfix/">two</a> <a target="_blank" href="http://maxb.net/blog/2010/03/15/markerclusterer-clearmarkers-bug-demo/">posts</a>, I described a bug but later I realized it was a false positive.<br />
There was no bug in the library Markerclusterer (gmaps-utility-library-dev).</p>
<p>The false positive was mainly caused by my initial mistake.</p>
<p>Before explaining the initial mistake that could still be common, and lead others in &#8220;error&#8221;, I would like to clarify that both rev.1159 and rev.1214 (current) do not contain the bug I thought I had found.</p>
<p><strong>There is no need to patch the library by adding the destroy method.</strong></p>
<p>The library Markerclusterer already exposes a method to correctly destroy the clusters: <strong> clearMarkers </strong>.</p>
<h3>clearMarkers works</h3>
<p>The initial mistake I made was to isolate within a function instance</p>
<pre class="brush: jscript; title: ; notranslate">
var markerclusterer = new Markerclusterer(map, points);
</pre>
<p>Having Isolated markercluster in the function called by the form, at each form submit I wouldn&#8217;t be able to call clearMarkers methods, not having access to the previously created instances.</p>
<p><strong> map.clearOverlay() is not enough </strong>.</p>
<p>You have to remove the clusters explicitly otherwise the first trigger ZoomIn ZoomOut keys of the map would show clusters of the previous search.</p>
<p>To summarize, use the library Markerclusterer</p>
<p>1) before removing the clusters:</p>
<pre class="brush: jscript; title: ; notranslate">
markerclusterer.clearMarkers();
</pre>
<p>2) then wipe the map with</p>
<pre class="brush: jscript; title: ; notranslate">
map.clearOverlays();
</pre>
<p>For those who want to analyze the working code I release two demos that are going to overwrite the previous:</p>
<ul>
<li><a target="_blank" href="http://maxb.net/scripts/markerclusterer/bug.html">with a programming mistake not due to the library</a></li>
<li><a target="_blank" href="http://maxb.net/scripts/markerclusterer/fix.html">with a proper usage of clearMarkers</a></li>
</ul>
<p>Another thing that could lead to errors (more false positives) is that after a zoom in / out clusters might be slightly different.</p>
<ul>
<li><a target="_blank" href="http://maxb.net/scripts/markerclusterer/many.html">many clusters</a></li>
</ul>
<p>Searching &#8220;Test 2&#8243; you&#8217;ll find 3 clusters over the Western Alps</p>
<div><img class="alignnone size-full wp-image-537" title="clusterbug" src="http://maxb.net/blog/wp-content/uploads/2010/03/many1.png" alt=""  /></div>
<p>Triggering a ZoomOut and then a ZoomIn, the clusters will be slightly different than before. Increasing the number of clusters it&#8217;s clearer something went wrong.</p>
<div><img class="alignnone size-full wp-image-537" title="clusterbug" src="http://maxb.net/blog/wp-content/uploads/2010/03/many2.png" alt=""  /></div>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2010/03/29/markerclusterer-clearmarkers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Markerclusterer clearmarkers bug demo</title>
		<link>http://maxb.net/blog/2010/03/15/markerclusterer-clearmarkers-bug-demo/</link>
		<comments>http://maxb.net/blog/2010/03/15/markerclusterer-clearmarkers-bug-demo/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 10:31:51 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[gmaps]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[markerclusterer]]></category>
		<category><![CDATA[bugfix]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=536</guid>
		<description><![CDATA[ATTENTION : This post started from a mistake. Demos are updated with the correct use of clearMarkers (which is bug free). BUG FIX PATCH Carlo and I, working together on this application have met a problem hard to isolate and &#8230; <a href="http://maxb.net/blog/2010/03/15/markerclusterer-clearmarkers-bug-demo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div style="text-align:center;font-weight:bold;border:3px dashed red;padding:5px;">
ATTENTION : This post started from a <a href="http://maxb.net/blog/2010/03/29/markerclusterer-clearmarkers/">mistake</a>.<br />
Demos are updated with the correct use of clearMarkers (which is bug free).
</div>
<ul>
<li><a target="_blank" href="http://maxb.net/scripts/markerclusterer/bug.html">BUG</a></li>
<li><a target="_blank" href="http://maxb.net/scripts/markerclusterer/fix.html">FIX</a></li>
<li><a target="_blank" href="http://perassi.org/quickhacks/mkp/mk.diff">PATCH</a></li>
</ul>
<p><a target="_blank" href="http://perassi.org/2009/12/01/markerclusterer-clearmarkers-bugfix/">Carlo</a> and I, working together on <a target="_blank" href="http://www.piemonteitalia.eu/index.php?option=com_mappet">this application</a> have met a problem hard to isolate and solve.</p>
<p>Markerclusterer library (of <a target="_blank" href="http://code.google.com/p/gmaps-utility-library-dev/">gmaps-utility-library-dev</a>) has a bug.<br />
Let me try to explain the problem.</p>
<p>Each cluster has an event associated with it (in fact, the click event on the cluster triggers the &#8220;zoom in&#8221; on the map and the cluster splits itself in markers or smaller clusters).<br />
When, from the outside (for example, within a form), I clean the map &#8211; map.clearOverlays(); &#8211; and then I refill it with a new search, I&#8217;m not able anymore to destroy the clusters.<br />
It seems the clusters are disappeared but, in fact, zooming in or out, they come back.<br />
Look at the two following pictures.</p>
<h3>STEP 1</h3>
<div><img class="alignnone size-full wp-image-537" title="clusterbug" src="http://maxb.net/blog/wp-content/uploads/2010/03/bugstep1.png" alt="" /></div>
<h3>STEP 2</h3>
<div><img class="alignnone size-full wp-image-537" title="clusterbug" src="http://maxb.net/blog/wp-content/uploads/2010/03/bugstep2.png" alt=""  /></div>
<h3>ZOOM OUT</h3>
<div><img class="alignnone size-full wp-image-537" title="clusterbug" src="http://maxb.net/blog/wp-content/uploads/2010/03/bugstep3.png" alt=""  /></div>
<p>The first and second picture shows the clusters correctly.<br />
The third picture instead (<a target="_blank" href="http://maxb.net/scripts/markerclusterer/bug.html">demo bug</a>) shows the clusters of the second search <strong>AND</strong> the ones of the first (after having done &#8220;zoom out&#8221;).</p>
<p>The whole thing is due to a bug in the JavaScript garbage collection (I suppose&#8230;).<br />
The object has been &#8220;subscribed&#8221; to an event. The object is destroyed but after the first trigger of that event, the object come back.</p>
<p>To fix this strange bug (it&#8217;s even hard to reproduce it, without a form!) it&#8217;s mandatory to provide to the markerclusterer library a method to correctly destroy the clusters.<br />
The <a href="http://perassi.org/quickhacks/mkp/mk.diff" target="blank">patch</a> (the diff file has been written again the 1159 revision) adds the destroy method.<br />
Before doing a new search, it is required to call</p>
<pre class="brush: jscript; title: ; notranslate">
map.clearOverlays();
</pre>
<p>AND</p>
<pre class="brush: jscript; title: ; notranslate">
markerCluster.destroy();
</pre>
<p>where markerCluster is your instance of MarkerClusterer(map, points);</p>
<div>
The destroy() method calls:
</div>
<pre class="brush: jscript; title: ; notranslate">
this.clearMarkers();
GEvent.removeListener(mcfn_);
mcfn_ = null;
me_ = null;
</pre>
<p>I reported the <a href="http://code.google.com/p/gmaps-utility-library-dev/issues/detail?id=196" target="_blank">bug</a> 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.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2010/03/15/markerclusterer-clearmarkers-bug-demo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

