[OpenLayers-Users] Add features to a clustering layer on interval

Heidt, Christopher M. CHRISTOPHER.M.HEIDT at saic.com
Wed Apr 1 16:38:35 EDT 2009


I hacked Cluster.js to get the behavior i was expecting.
 
I changed the cacheFeatures function to retain previous features,
instead of clearing them out.
and i changed the cluster function to recluster when no event is passed,
which only happens when it is called from cacheFeatures.
 
making these changes allows me to addFeatures to my clustering layer at
different intervals without all my previous features being cleared.
 
 
function cacheFeatures:
 
ORIGIONAL:
cacheFeatures: function(event) {
        var propagate = true;
        if(!this.clustering) {
            this.clearCache();
            this.features = event.features;
            this.cluster();
            propagate = false;
        }
        return propagate;
    },
 
MINE:
cacheFeatures: function(event) {
        var propagate = true;
        if(!this.clustering) {
            //this.clearCache();
            if(this.features === null){
                this.features = [];
            }
            this.features = this.features.concat(event.features);
            this.cluster();
            propagate = false;
        }
        return propagate;
    },
 
 
function cluster:
 
ORIGIONAL:
if(resolution != this.resolution || !this.clustersExist()) {
 
MINE:
if(!event || resolution != this.resolution || !this.clustersExist()) {
 
 
 If you do this, try not to addFeatures one feature at a time to the
layer, its going to recluster everytime you addFeatures.
 

________________________________

From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of Heidt, Christopher M.
Sent: Wednesday, April 01, 2009 2:03 PM
To: users at openlayers.org
Subject: [OpenLayers-Users] Add features to a clustering layer on
interval


i use this layer:
 
_clusterStrategy = new OpenLayers.Strategy.Cluster({distance:20})
  _featureLayer = new OpenLayers.Layer.Vector(" Features of Interest",{
   projection: _map.projection,
   styleMap: featureStyles,
   strategies: [_clusterStrategy]
  });
 
and i have a store that pulls from the server and then adds the records
to the layer above with this function:

function _createFeatures(records, animate)
 { 
  var features = [];
  var wktFormat = new OpenLayers.Format.WKT({
   externalProjection: _map.displayProjection,
   internalProjection: _map.projection
  });
  Ext.each(records, function(record){
   var feature = wktFormat.read(record.get('featureGeom'));
   feature.id = record.get('featureId');
   features.push(feature);
  });
  _featureLayer.addFeatures(features);
 }
 
this works great the first time i get records, but i have an interval
running that polls my server
for new stuff and then i call the function above to add those to the map
as well.
 
the issue is that it seems to be impossible to add new features to a
clustered layer after the initial load.
I need a way to add features to a vector layer using a clustering
strategy that doesnt make all my previous clustered features vanish.
 
I would even understand it if it didnt visibly recalulate the clusters
untill i changed my zoom lvl,
but it definitly shouldnt make everything disaper when i add new
features.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090401/fa334e0f/attachment.html


More information about the Users mailing list