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 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();

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

Hierarchy

Constructors

  • Parameters

    • Optional opt_geometryOrProperties: ol.geom.Geometry | {
          [k: string]: any;
      }

      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.

    Returns ol.Feature

    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 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();

    Api

    stable

Methods

  • Increases the revision counter and dispatches a 'change' event.

    Returns void

    Api

  • Clone this feature. If the original feature has a geometry it is also cloned. The feature id is not set in the clone.

    Returns ol.Feature

    The clone.

    Api

    stable

  • Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a type property.

    Parameters

    Returns void

    Function

    Api

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

    Api

    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.

    Returns ol.geom.Geometry

    The default geometry for the feature.

    Api

    stable

    Observable

  • Get the name of the feature's default geometry. By default, the default geometry is named geometry.

    Returns string

    Get the property name associated with the default geometry for this feature.

    Api

    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.

    Returns string | number

    Id.

    Api

    stable

    Observable

  • Get a list of object property names.

    Returns string[]

    List of property names.

    Api

    stable

  • Get an object of all property names and values.

    Returns {
        [k: string]: any;
    }

    Object.

    • [k: string]: any

    Api

    stable

  • Get the version number for this object. Each time the object is modified, its version number will be incremented.

    Returns number

    Revision.

    Api

  • Get the feature's style function.

    Returns FeatureStyleFunction

    Return a function representing the current style of this feature.

    Api

    stable

  • Listen for a certain type of event.

    Parameters

    • type: string | string[]

      The event type or array of event types.

    • listener: Function

      The listener function.

    • Optional opt_this: Object

      The object to use as this in listener.

    Returns Object | Object[]

    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.

    Api

    stable

  • Listen once for a certain type of event.

    Parameters

    • type: string | string[]

      The event type or array of event types.

    • listener: Function

      The listener function.

    • Optional opt_this: Object

      The object to use as this in listener.

    Returns Object | Object[]

    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.

    Api

    stable

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optional opt_silent: boolean

      Update without triggering an event.

    Returns void

    Api

    stable

  • Set the default geometry for the feature. This will update the property with the name returned by ol.Feature#getGeometryName.

    Parameters

    Returns void

    Api

    stable

    Observable

  • 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.

    Parameters

    • name: string

      The property name of the default geometry.

    Returns void

    Api

    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.

    Parameters

    • id: string | number

      The feature id.

    Returns void

    Api

    stable

    Observable

  • 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).

    Parameters

    • values: {
          [k: string]: any;
      }

      Values.

      • [k: string]: any
    • Optional opt_silent: boolean

      Update without triggering an event.

    Returns void

    Api

    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).

    Parameters

    Returns void

    Api

    stable

    Observable

  • Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      The event type or array of event types.

    • listener: Function

      The listener function.

    • Optional opt_this: Object

      The object which was used as this by the listener.

    Returns void

    Api

    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.

    Parameters

    • key: Object | Object[]

      The key returned by on() or once() (or an array of keys).

    Returns void

    Function

    Api

    stable

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optional opt_silent: boolean

      Unset without triggering an event.

    Returns void

    Api

    stable

  • Removes an event listener using the key returned by on() or once().

    Parameters

    • key: Object | Object[]

      The key returned by on() or once() (or an array of keys).

    Returns void

    Api

    stable

Generated using TypeDoc