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

Summary
OpenLayers. Layer. Vector Instances of OpenLayers.Layer.Vector are used to render vector data from a variety of sources.
Properties
events {OpenLayers.Events}
isBaseLayer {Boolean} The layer is a base layer.
isFixed {Boolean} Whether the layer remains in one place while dragging the map.
features {Array(OpenLayers.Feature.Vector)}
reportError {Boolean} report friendly error message when loading of renderer fails.
style {Object} Default style for the layer
rendererOptions {Object} Options for the renderer.
geometryType {String} geometryType allows you to limit the types of geometries this layer supports.
ratio {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map.
Constructor
OpenLayers. Layer. Vector Create a new vector layer
Functions
destroy Destroy this layer
display Hide or show the Layer
addFeatures Add Features to the layer.
removeFeatures Remove features from the layer.
removeAllFeatures Remove all features from the layer.
destroyFeatures Erase and destroy features on the layer.
drawFeature Draw (or redraw) a feature on the layer.
getFeatureBy Given a property value, return the feature if it exists in the features array
getFeatureById Given a feature id, return the feature if it exists in the features array
getFeatureByFid Given a feature fid, return the feature if it exists in the features array
getFeaturesByAttribute Returns an array of features that have the given attribute key set to the given value.
onFeatureInsert method called after a feature is inserted.
preFeatureInsert method called before a feature is inserted.
getDataExtent Calculates the max extent which includes all of the features.

Properties

events

{OpenLayers.Events}

Register a listener for a particular event with the following syntax

layer.events.register(type, obj, listener);

Listeners will be called with a reference to an event object.  The properties of this event depends on exactly what happened.

All event objects have at least the following properties

object {Object} A reference to layer.events.object.
element {DOMElement} A reference to layer.events.element.

Supported map event types (in addition to those from OpenLayers.Layer.events)

beforefeatureadded Triggered before a feature is added.  Listeners will receive an object with a feature property referencing the feature to be added.  To stop the feature from being added, a listener should return false.
beforefeaturesadded Triggered before an array of features is added.  Listeners will receive an object with a features property referencing the feature to be added.  To stop the features from being added, a listener should return false.
featureadded Triggered after a feature is added.  The event object passed to listeners will have a feature property with a reference to the added feature.
featuresadded Triggered after features are added.  The event object passed to listeners will have a features property with a reference to an array of added features.
beforefeatureremoved Triggered before a feature is removed.  Listeners will receive an object with a feature property referencing the feature to be removed.
beforefeaturesremoved Triggered before multiple features are removed.  Listeners will receive an object with a features property referencing the features to be removed.
featureremoved Triggerd after a feature is removed.  The event object passed to listeners will have a feature property with a reference to the removed feature.
featuresremoved Triggered after features are removed.  The event object passed to listeners will have a features property with a reference to an array of removed features.
beforefeatureselected Triggered before a feature is selected.  Listeners will receive an object with a feature property referencing the feature to be selected.  To stop the feature from being selectd, a listener should return false.
featureselected Triggered after a feature is selected.  Listeners will receive an object with a feature property referencing the selected feature.
featureunselected Triggered after a feature is unselected.  Listeners will receive an object with a feature property referencing the unselected feature.
beforefeaturemodified Triggered when a feature is selected to be modified.  Listeners will receive an object with a feature property referencing the selected feature.
featuremodified Triggered when a feature has been modified.  Listeners will receive an object with a feature property referencing the modified feature.
afterfeaturemodified Triggered when a feature is finished being modified.  Listeners will receive an object with a feature property referencing the modified feature.
vertexmodified Triggered when a vertex within any feature geometry has been modified.  Listeners will receive an object with a feature property referencing the modified feature, a vertex property referencing the vertex modified (always a point geometry), and a pixel property referencing the pixel location of the modification.
vertexremoved Triggered when a vertex within any feature geometry has been deleted.  Listeners will receive an object with a feature property referencing the modified feature, a vertex property referencing the vertex modified (always a point geometry), and a pixel property referencing the pixel location of the removal.
sketchstarted Triggered when a feature sketch bound for this layer is started.  Listeners will receive an object with a feature property referencing the new sketch feature and a vertex property referencing the creation point.
sketchmodified Triggered when a feature sketch bound for this layer is modified.  Listeners will receive an object with a vertex property referencing the modified vertex and a feature property referencing the sketch feature.
sketchcomplete Triggered when a feature sketch bound for this layer is complete.  Listeners will receive an object with a feature property referencing the sketch feature.  By returning false, a listener can stop the sketch feature from being added to the layer.
refresh Triggered when something wants a strategy to ask the protocol for a new set of features.

isBaseLayer

{Boolean} The layer is a base layer.  Default is false.  Set this property in the layer options.

isFixed

{Boolean} Whether the layer remains in one place while dragging the map.  Note that setting this to true will move the layer to the bottom of the layer stack.

features

reportError

{Boolean} report friendly error message when loading of renderer fails.

style

{Object} Default style for the layer

rendererOptions

{Object} Options for the renderer.  See {OpenLayers.Renderer} for supported options.

geometryType

{String} geometryType allows you to limit the types of geometries this layer supports.  This should be set to something like “OpenLayers.Geometry.Point” to limit types.

ratio

{Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map.

Constructor

OpenLayers. Layer. Vector

Create a new vector layer

Parameters

name {String} A name for the layer
options {Object} Optional object with non-default properties to set on the layer.

Returns

{OpenLayers.Layer.Vector} A new vector layer

Functions

destroy

destroy: function()

Destroy this layer

display

display: function( display )

Hide or show the Layer

Parameters

display {Boolean}

addFeatures

addFeatures: function( features,
options )

Add Features to the layer.

Parameters

features {Array(OpenLayers.Feature.Vector)}
options {Object}

removeFeatures

removeFeatures: function( features,
options )

Remove features from the layer.  This erases any drawn features and removes them from the layer’s control.  The beforefeatureremoved and featureremoved events will be triggered for each feature.  The featuresremoved event will be triggered after all features have been removed.  To supress event triggering, use the silent option.

Parameters

features {Array(OpenLayers.Feature.Vector)} List of features to be removed.
options {Object} Optional properties for changing behavior of the removal.

Valid options

silent {Boolean} Supress event triggering.  Default is false.

removeAllFeatures

removeAllFeatures: function( options )

Remove all features from the layer.

Parameters

options {Object} Optional properties for changing behavior of the removal.

Valid options

silent {Boolean} Supress event triggering.  Default is false.

destroyFeatures

destroyFeatures: function( features,
options )

Erase and destroy features on the layer.

Parameters

features {Array(OpenLayers.Feature.Vector)} An optional array of features to destroy.  If not supplied, all features on the layer will be destroyed.
options {Object}

drawFeature

drawFeature: function( feature,
style )

Draw (or redraw) a feature on the layer.  If the optional style argument is included, this style will be used.  If no style is included, the feature’s style will be used.  If the feature doesn’t have a style, the layer’s style will be used.

This function is not designed to be used when adding features to the layer (use addFeatures instead).  It is meant to be used when the style of a feature has changed, or in some other way needs to visually updated after it has already been added to a layer.  You must add the feature to the layer for most layer-related events to happen.

Parameters

feature {OpenLayers.Feature.Vector}
style {String | Object} Named render intent or full symbolizer object.

getFeatureBy

getFeatureBy: function( property,
value )

Given a property value, return the feature if it exists in the features array

Parameters

property {String}
value {String}

Returns

{OpenLayers.Feature.Vector} A feature corresponding to the given property value or null if there is no such feature.

getFeatureById

getFeatureById: function( featureId )

Given a feature id, return the feature if it exists in the features array

Parameters

featureId {String}

Returns

{OpenLayers.Feature.Vector} A feature corresponding to the given featureId or null if there is no such feature.

getFeatureByFid

getFeatureByFid: function( featureFid )

Given a feature fid, return the feature if it exists in the features array

Parameters

featureFid {String}

Returns

{OpenLayers.Feature.Vector} A feature corresponding to the given featureFid or null if there is no such feature.

getFeaturesByAttribute

getFeaturesByAttribute: function( attrName,
attrValue )

Returns an array of features that have the given attribute key set to the given value.  Comparison of attribute values takes care of datatypes, e.g. the string ‘1234’ is not equal to the number 1234.

Parameters

attrName {String}
attrValue {Mixed}

Returns

Array({OpenLayers.Feature.Vector}) An array of features that have the passed named attribute set to the given value.

onFeatureInsert

onFeatureInsert: function( feature )

method called after a feature is inserted.  Does nothing by default.  Override this if you need to do something on feature updates.

Parameters

feature {OpenLayers.Feature.Vector}

preFeatureInsert

preFeatureInsert: function( feature )

method called before a feature is inserted.  Does nothing by default.  Override this if you need to do something when features are first added to the layer, but before they are drawn, such as adjust the style.

Parameters

feature {OpenLayers.Feature.Vector}

getDataExtent

getDataExtent: function ()

Calculates the max extent which includes all of the features.

Returns

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

Vector features use the OpenLayers.Geometry classes as geometry description.
destroy: function()
Destroy this layer
display: function( display )
Hide or show the Layer
addFeatures: function( features,
options )
Add Features to the layer.
removeFeatures: function( features,
options )
Remove features from the layer.
removeAllFeatures: function( options )
Remove all features from the layer.
destroyFeatures: function( features,
options )
Erase and destroy features on the layer.
drawFeature: function( feature,
style )
Draw (or redraw) a feature on the layer.
getFeatureBy: function( property,
value )
Given a property value, return the feature if it exists in the features array
getFeatureById: function( featureId )
Given a feature id, return the feature if it exists in the features array
getFeatureByFid: function( featureFid )
Given a feature fid, return the feature if it exists in the features array
getFeaturesByAttribute: function( attrName,
attrValue )
Returns an array of features that have the given attribute key set to the given value.
onFeatureInsert: function( feature )
method called after a feature is inserted.
preFeatureInsert: function( feature )
method called before a feature is inserted.
getDataExtent: function ()
Calculates the max extent which includes all of the features.
Create a new vector layer
{OpenLayers.Events}
This is the base class for all renderers.
Instances of this class represent bounding boxes.
Close