OpenLayers. Geometry. Collection

A Collection is exactly what it sounds like: A collection of different Geometries.  These are stored in the local parameter components (which can be passed as a parameter to the constructor).

As new geometries are added to the collection, they are NOT cloned.  When removing geometries, they need to be specified by reference (ie you have to pass in the exact geometry to be removed).

The getArea and getLength functions here merely iterate through the components, summing their respective areas and lengths.

Create a new instance with the OpenLayers.Geometry.Collection constructor.

Inerhits from

Summary
A Collection is exactly what it sounds like: A collection of different Geometries.
{Array(OpenLayers.Geometry)} The component parts of this geometry
Creates a Geometry Collection -- a list of geoms.
Destroy this geometry.
Clone this geometry.
Get a string representing the components for this collection
Recalculate the bounds by iterating through the components and calling calling extendBounds() on each item
Add components to this geometry.
Add a new component (geometry) to the collection.
Remove components from this geometry.
Remove a component from this geometry.
Calculate the length of this geometry
Calculate the area of this geometry.
Moves a collection in place
Tests for equivalent geometries
{String} Name of class.

Properties

components

{Array(OpenLayers.Geometry)} The component parts of this geometry

Functions

OpenLayers. Geometry. Collection

Creates a Geometry Collection -- a list of geoms.

Parameters

components{Array(OpenLayers.Geometry)} Optional array of geometries

Returns

{OpenLayers.Geometry.Collection} A new geometry collection

destroy

destroy: function ()

Destroy this geometry.

clone

clone: function()

Clone this geometry.

Return

{OpenLayers.Geometry.Collection} An exact clone of this collection

getComponentsString

getComponentsString: function()

Get a string representing the components for this collection

Return

{String} A string representation of the components of this geometry

calculateBounds

calculateBounds: function()

Recalculate the bounds by iterating through the components and calling calling extendBounds() on each item

addComponents

addComponents: function(components)

Add components to this geometry.

Parameters

components{Array(OpenLayers.Geometry)} An array of geometries to add

addComponent

addComponent: function(component,
index)

Add a new component (geometry) to the collection.  If this.componentTypes is set, then the component class name must be in the componentTypes array.

The bounds cache is reset.

Parameters

component{OpenLayers.Geometry} A geometry to add
index{int} Optional index into the array to insert the component

Return

{Boolean} The component geometry was successfully added

removeComponents

removeComponents: function(components)

Remove components from this geometry.

Parameters

components{Array(OpenLayers.Geometry)} The components to be removed

removeComponent

removeComponent: function(component)

Remove a component from this geometry.

Parameters

component{OpenLayers.Geometry}

getLength

getLength: function()

Calculate the length of this geometry

Return

{Number} The length of the geometry

getArea

getArea: function()

Calculate the area of this geometry.  Note how this function is overridden in OpenLayers.Geometry.Polygon.

Return

{Number} The area of the collection by summing its parts

move

move: function(x,
y)

Moves a collection in place

Parameters

x{Number} The x-displacement (in map units)
y{Number} The y-displacement (in map units)

equals

equals: function(geometry)

Tests for equivalent geometries

Parameters

geometry{OpenLayers.Geometry}

Return

{Boolean} The coordinates are equivalent

Constants

CLASS_NAME

{String} Name of class.

A Geometry is a description of a geographic object.
destroy: function ()
Destroy this geometry.
clone: function()
Clone this geometry.
getComponentsString: function()
Get a string representing the components for this collection
calculateBounds: function()
Recalculate the bounds by iterating through the components and calling calling extendBounds() on each item
addComponents: function(components)
Add components to this geometry.
addComponent: function(component,
index)
Add a new component (geometry) to the collection.
removeComponents: function(components)
Remove components from this geometry.
removeComponent: function(component)
Remove a component from this geometry.
getLength: function()
Calculate the length of this geometry
getArea: function()
Calculate the area of this geometry.
move: function(x,
y)
Moves a collection in place
equals: function(geometry)
Tests for equivalent geometries
{Array(OpenLayers.Geometry)} The component parts of this geometry
Creates a Geometry Collection -- a list of geoms.
Polygon is a collection of Geometry.LinearRings.