<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.5726" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009>I hacked Cluster.js to get the behavior i was
expecting.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN class=359462220-01042009>I
changed the cacheFeatures function to retain previous features, instead of
clearing them out.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009>and i changed the cluster function to recluster when no
event is passed, which only happens when it is called from
cacheFeatures.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009>making these changes allows me to addFeatures to my
clustering layer at different intervals without all my previous features being
cleared.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009></SPAN></FONT><FONT face=Arial size=2><SPAN
class=359462220-01042009>function cacheFeatures:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009>ORIGIONAL:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009>cacheFeatures: function(event)
{<BR> var propagate =
true;<BR> if(!this.clustering)
{<BR>
this.clearCache();<BR>
this.features =
event.features;<BR>
this.cluster();<BR>
propagate = false;<BR>
}<BR> return
propagate;<BR> },</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009>MINE:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009>cacheFeatures: function(event)
{<BR> var propagate =
true;<BR> if(!this.clustering)
{<BR>
//this.clearCache();<BR>
if(this.features ===
null){<BR>
this.features =
[];<BR>
}<BR>
this.features =
this.features.concat(event.features);<BR>
this.cluster();<BR>
propagate = false;<BR>
}<BR> return
propagate;<BR> },</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=359462220-01042009><FONT face=Arial size=2>function
cluster:</FONT></SPAN></DIV>
<DIV><SPAN class=359462220-01042009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009><SPAN
class=359462220-01042009>ORIGIONAL:</SPAN></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009><SPAN class=359462220-01042009>if(resolution !=
this.resolution || !this.clustersExist()) {</SPAN></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009><SPAN
class=359462220-01042009></SPAN></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009><SPAN
class=359462220-01042009>MINE:</SPAN></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009>if(!event || resolution != this.resolution ||
!this.clustersExist()) {</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=359462220-01042009>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009> <FONT color=#000000>If you do this, try not to
addFeatures one feature at a time to the layer, <SPAN
class=359462220-01042009>its going to recluster everytime you
addFeatures.</SPAN></FONT></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=359462220-01042009><FONT color=#000000><SPAN
class=359462220-01042009></SPAN></FONT></SPAN></FONT> </DIV></SPAN></FONT></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> users-bounces@openlayers.org
[mailto:users-bounces@openlayers.org] <B>On Behalf Of </B>Heidt, Christopher
M.<BR><B>Sent:</B> Wednesday, April 01, 2009 2:03 PM<BR><B>To:</B>
users@openlayers.org<BR><B>Subject:</B> [OpenLayers-Users] Add features to a
clustering layer on interval<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><SPAN class=798504317-01042009>i use this
layer:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=798504317-01042009></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2>_clusterStrategy = new
OpenLayers.Strategy.Cluster({distance:20})<BR> _featureLayer = new
OpenLayers.Layer.Vector(" Features of
Interest",{<BR> projection:
_map.projection,<BR> styleMap:
featureStyles,<BR> strategies:
[_clusterStrategy]<BR> });</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>and i have a store
that pulls from the server and then adds the records to the layer above with
this function:</FONT></SPAN></DIV><SPAN class=798504317-01042009><FONT
face=Arial size=2></FONT></SPAN>
<DIV><BR><FONT face=Arial color=#0000ff size=2>function _createFeatures(records,
animate)<BR> { <BR> var features = [];<BR> var
wktFormat = new OpenLayers.Format.WKT({<BR> externalProjection:
_map.displayProjection,<BR> internalProjection:
_map.projection<BR> });<BR> Ext.each(records,
function(record){<BR> var feature =
wktFormat.read(record.get('featureGeom'));<BR> feature.id =
record.get('featureId');<BR> features.push(feature);<BR> });<BR> _featureLayer.addFeatures(features);<BR> }</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>this works great the
first time i get records, but i have an interval running that polls my
server</FONT></SPAN></DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>for new stuff and
then i call the function above to add those to the map as
well.</FONT></SPAN></DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>the issue is that it
seems to be impossible to add new features to a clustered layer after the
initial load.</FONT></SPAN></DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>I need a way to add
features to a vector layer using a clustering strategy that doesnt make all my
previous clustered features vanish.</FONT></SPAN></DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>I would even
understand it if it didnt visibly recalulate the clusters untill i changed my
zoom lvl,</FONT></SPAN></DIV>
<DIV><SPAN class=798504317-01042009><FONT face=Arial size=2>but it definitly
shouldnt make everything disaper when i add new
features.</FONT></SPAN></DIV></BODY></HTML>