A vector object for geographic features with a geometry and other attribute properties, similar to the features in vector file formats like GeoJSON.
Features can be styled individually with setStyle
; otherwise they use the
style of their vector layer.
Note that attribute properties are set as ol.Object properties on the feature object, so they are observable, and have get/set accessors.
Typically, a feature has a single geometry property. You can set the
geometry using the setGeometry
method and get it with getGeometry
.
It is possible to store more than one geometry on a feature using attribute
properties. By default, the geometry used for rendering is identified by
the property name geometry
. If you want to use another geometry property
for rendering, use the setGeometryName
method to change the attribute
property associated with the geometry for the feature. For example:
var feature = new ol.Feature({
geometry: new ol.geom.Polygon(polyCoords),
labelPoint: new ol.geom.Point(labelCoords),
name: 'My Polygon'
});
// get the polygon geometry
var poly = feature.getGeometry();
// Render the feature as a point using the coordinates from labelPoint
feature.setGeometryName('labelPoint');
// get the point geometry
var point = feature.getGeometry();
stable
Get the feature's default geometry. A feature may have any number of named geometries. The "default" geometry (the one that is rendered by default) is set when calling ol.Feature#setGeometry.
The default geometry for the feature.
stable
Get the feature identifier. This is a stable identifier for the feature and is either set when reading data from a remote source or set explicitly by calling ol.Feature#setId.
Id.
stable
Get the feature's style. This return for this method depends on what was provided to the ol.Feature#setStyle method.
The feature style.
stable
Get the feature's style function.
Return a function representing the current style of this feature.
stable
Listen for a certain type of event.
The event type or array of event types.
The listener function.
Optional
opt_this: ObjectThe object to use as this
in listener
.
Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.
stable
Listen once for a certain type of event.
The event type or array of event types.
The listener function.
Optional
opt_this: ObjectThe object to use as this
in listener
.
Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.
stable
Set the default geometry for the feature. This will update the property with the name returned by ol.Feature#getGeometryName.
stable
Set the property name to be used when getting the feature's default geometry. When calling ol.Feature#getGeometry, the value of the property with this name will be returned.
The property name of the default geometry.
stable
Set the feature id. The feature id is considered stable and may be used when requesting features or comparing identifiers returned from a remote source. The feature id can be used with the ol.source.Vector#getFeatureById method.
The feature id.
stable
Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).
Values.
Optional
opt_silent: booleanUpdate without triggering an event.
stable
Set the style for the feature. This can be a single style object, an array
of styles, or a function that takes a resolution and returns an array of
styles. If it is null
the feature has no style (a null
style).
Style for this feature.
stable
Removes an event listener using the key returned by on()
or once()
.
Note that using the ol.Observable.unByKey static function is to
be preferred.
stable
Static
unGenerated using TypeDoc
Classdesc
A vector object for geographic features with a geometry and other attribute properties, similar to the features in vector file formats like GeoJSON.
Features can be styled individually with
setStyle
; otherwise they use the style of their vector layer.Note that attribute properties are set as ol.Object properties on the feature object, so they are observable, and have get/set accessors.
Typically, a feature has a single geometry property. You can set the geometry using the
setGeometry
method and get it withgetGeometry
. It is possible to store more than one geometry on a feature using attribute properties. By default, the geometry used for rendering is identified by the property namegeometry
. If you want to use another geometry property for rendering, use thesetGeometryName
method to change the attribute property associated with the geometry for the feature. For example:Param: opt_geometryOrProperties
You may pass a Geometry object directly, or an object literal containing properties. If you pass an object literal, you may include a Geometry associated with a
geometry
key.Api
stable