OpenLayers.Strategy.CenteredCluster

Strategy for vector feature clustering.

NOTE: This code includes a patch for OpenLayers.Layer.Vector.getDataExtent function.

Inherits from

  • <OpenLayers.Strategy>
Summary
OpenLayers.Strategy.CenteredClusterStrategy for vector feature clustering.
Properties
centered{Boolean}
enabled{Boolean}
zoomSettings{Boolean}
candidateMatches{Function}
distance{Integer} Pixel distance between features that should be considered a single cluster.
threshold{Integer} Optional threshold below which original features will be added to the layer instead of clusters.
features{Array(<OpenLayers.Feature.Vector>)} Cached features.
clustering{Boolean} The strategy is currently clustering features.
resolution{Float} The resolution (map units per pixel) of the current cluster set.
defaultSettings{Object} Internal use only.
Constructor
OpenLayers.Strategy.CenteredClusterCreate a new CenteredCluster strategy.
Properties
_candidateMatches{Function} Set by _createClusters method.
_resDistance2{Fload} Set by _createClusters method, and used in _withinDistance.
Functions
_addFeatureAdd the feature to the cluster
_centerClustercluster -{Object}
_trimCluster
_groupFeaturesclusters -Array({Object}) Initial and calculated clusters at the end.
_groupClusters
_createClusters
clusterCluster features based on some threshold distance.
onMoveend
activateActivate the strategy.
deactivateDeactivate the strategy.
cacheFeaturesCache features before they are added to the layer.
refreshCacheRefresh the cached features.
unclusterUncluster features.
OpenLayers.Layer.VectorInstances of OpenLayers.Layer.Vector are used to render vector data from a variety of sources.
Functions
getDataExtentCalculates the max extent which includes all of the features, even if they are clustered.

Properties

centered

{Boolean}

enabled

{Boolean}

zoomSettings

{Boolean}

candidateMatches

{Function}

distance

{Integer} Pixel distance between features that should be considered a single cluster.  Default is 20 pixels.

threshold

{Integer} Optional threshold below which original features will be added to the layer instead of clusters.  For example, a threshold of 3 would mean that any time there are 2 or fewer features in a cluster, those features will be added directly to the layer instead of a cluster representing those features.  Default is null (which is equivalent to 1 - meaning that clusters may contain just one feature)

features

{Array(<OpenLayers.Feature.Vector>)} Cached features.

clustering

{Boolean} The strategy is currently clustering features.

resolution

{Float} The resolution (map units per pixel) of the current cluster set.

defaultSettings

{Object} Internal use only.

Constructor

OpenLayers.Strategy.CenteredCluster

Create a new CenteredCluster strategy.

Parameters

options{Object} Optional object whose properties will be set on the instance.

Properties

_candidateMatches

{Function} Set by _createClusters method.

_resDistance2

{Fload} Set by _createClusters method, and used in _withinDistance.

Functions

_addFeature

var _addFeature = function(cluster,
feature,
fCenter)

Add the feature to the cluster

Parameters

cluster -{Object} feature - {<OpenLayers.Feature.Vector>} fCenter - {OpenLayers.LonLat} Center of de feature.

_centerCluster

var _centerCluster = function(cluster)

Parameters

cluster -{Object}

_trimCluster

var _trimCluster = function(rejections,
cluster)

Parameters

rejectionsArray({<OpenLayers.Feature.Vector>}) cluster -{Object} Calculated cluster.

_groupFeatures

var _groupFeatures = function(clusters,
features)

Parameters

clusters -Array({Object}) Initial and calculated clusters at the end. features -Array({<OpenLayers.Feature.Vector>}) To cluster features.

_groupClusters

var _groupClusters = function(remainingStart,
clusters,
candidates)

Parameters

remainingStart{Integer}
clustersArray({Object}) Calculated clusters at the end.
candidatesArray({<OpenLayers.Feature.Vector>}) Initial calculated clusters.

_createClusters

var _self = this; var _createClusters = function(resolution)

Parameters

resolution{Fload}

cluster

var cluster = function(event)

Cluster features based on some threshold distance.

Parameters

event{Object} The event received when cluster is called as a result of a moveend event.

onMoveend

onMoveend: function(event)

activate

activate: function()

Activate the strategy.  Register any listeners, do appropriate setup.

Returns

{Boolean} The strategy was successfully activated.

deactivate

deactivate: function()

Deactivate the strategy.  Unregister any listeners, do appropriate tear-down.

Returns

{Boolean} The strategy was successfully deactivated.

cacheFeatures

cacheFeatures: function(event)

Cache features before they are added to the layer.

Parameters

event{Object} The event that this was listening for.  This will come with a batch of features to be clustered.

Returns

{Boolean} False to stop features from being added to the layer.

refreshCache

refreshCache: function()

Refresh the cached features.

uncluster

uncluster: function()

Uncluster features.  Internal use!

Warning: methods that call this function should monitor that `this.features` has value.

OpenLayers.Layer.Vector

Instances of OpenLayers.Layer.Vector are used to render vector data from a variety of sources.  Create a new vector layer with the OpenLayers.Layer.Vector constructor.

Inherits from

  • <OpenLayers.Layer>
Summary
Functions
getDataExtentCalculates the max extent which includes all of the features, even if they are clustered.

Functions

getDataExtent

OpenLayers.Layer.Vector.prototype.getDataExtent = function()

Calculates the max extent which includes all of the features, even if they are clustered.

Returns

{<OpenLayers.Bounds>} or null if the layer has no features with geometries.

var _addFeature = function(cluster,
feature,
fCenter)
Add the feature to the cluster
var _centerCluster = function(cluster)
cluster -{Object}
var _trimCluster = function(rejections,
cluster)
var _groupFeatures = function(clusters,
features)
clusters -Array({Object}) Initial and calculated clusters at the end.
var _groupClusters = function(remainingStart,
clusters,
candidates)
var _self = this; var _createClusters = function(resolution)
var cluster = function(event)
Cluster features based on some threshold distance.
onMoveend: function(event)
activate: function()
Activate the strategy.
deactivate: function()
Deactivate the strategy.
cacheFeatures: function(event)
Cache features before they are added to the layer.
refreshCache: function()
Refresh the cached features.
uncluster: function()
Uncluster features.
OpenLayers.Layer.Vector.prototype.getDataExtent = function()
Calculates the max extent which includes all of the features, even if they are clustered.
Instances of OpenLayers.Layer.Vector are used to render vector data from a variety of sources.
Close