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
{Array(String)} An array of class names representing the types of components that the collection can include.
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
Rotate a geometry around some origin
Resize a geometry relative to some origin.
Tests for equivalent geometries

Properties

components

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

componentTypes

{Array(String)} An array of class names representing the types of components that the collection can include.  A null value means the component types are not restricted.

Constructor

OpenLayers. Geometry. Collection

Creates a Geometry Collection -- a list of geoms.

Parameters

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

Functions

destroy

destroy: function ()

Destroy this geometry.

clone

clone: function()

Clone this geometry.

Returns

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

getComponentsString

getComponentsString: function()

Get a string representing the components for this collection

Returns

{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

Returns

{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

Returns

{Float} The length of the geometry

getArea

getArea: function()

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

Returns

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

move

move: function(x,
y)

Moves a collection in place

Parameters

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

rotate

rotate: function(angle,
origin)

Rotate a geometry around some origin

Parameters

angle{Float} Rotation angle in degrees (measured counterclockwise from the positive x-axis)
origin{OpenLayers.Geometry.Point} Center point for the rotation

resize

resize: function(scale,
origin)

Resize a geometry relative to some origin.  Use this method to apply a uniform scaling to a geometry.

Parameters

scale{Float} Factor by which to scale the geometry.  A scale of 2 doubles the size of the geometry in each dimension (lines, for example, will be twice as long, and polygons will have four times the area).
origin{OpenLayers.Geometry.Point} Point of origin for resizing

equals

equals: function(geometry)

Tests for equivalent geometries

Parameters

geometry{OpenLayers.Geometry}

Returns

{Boolean} The coordinates are equivalent

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
rotate: function(angle,
origin)
Rotate a geometry around some origin
resize: function(scale,
origin)
Resize a geometry relative to some origin.
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.
Point geometry class.