/** * @module ol/Feature */ import {assert} from './asserts.js'; import {listen, unlisten, unlistenByKey} from './events.js'; import EventType from './events/EventType.js'; import BaseObject, {getChangeEventType} from './Object.js'; import Geometry from './geom/Geometry.js'; import Style from './style/Style.js'; /** * @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 {@link module: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: * * ```js * * import Feature from 'ol/Feature'; * import Polygon from 'ol/geom/Polygon'; * import Point from 'ol/geom/Point'; * * var feature = new Feature({ * geometry: new Polygon(polyCoords), * labelPoint: new 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 */ class Feature extends BaseObject { /** * @param {Geometry|Object=} 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. */ constructor(opt_geometryOrProperties) { super(); /** * @private * @type {number|string|undefined} */ this.id_ = undefined; /** * @type {string} * @private */ this.geometryName_ = 'geometry'; /** * User provided style. * @private * @type {Style|Array