Skip to content

Commit 38b36a0

Browse files
committed
Merge pull request openlayers#2378 from pagameba/doc-feature
Improve documentation for ol.Feature
2 parents b96fb6a + 685265e commit 38b36a0

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

src/ol/feature.js

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,46 @@ goog.require('ol.style.Style');
1717

1818
/**
1919
* @classdesc
20-
* A vector object for geographical features with a geometry and other
20+
* A vector object for geographic features with a geometry and other
2121
* attribute properties, similar to the features in vector file formats like
2222
* GeoJSON.
23+
*
2324
* Features can be styled individually or use the style of their vector layer.
24-
* Note that attribute properties are set as {@link ol.Object} properties on the
25-
* feature object, so they are observable, and have get/set accessors.
25+
* Note that attribute properties are set as {@link ol.Object} properties on
26+
* the feature object, so they are observable, and have get/set accessors.
27+
*
28+
* Typically, a feature has a single geometry property. You can set the
29+
* geometry using the `setGeometry` method and get it with `getGeometry`.
30+
* It is possible to store more than one geometry on a feature using attribute
31+
* properties. By default, the geometry used for rendering is identified by
32+
* the property name `geometry`. If you want to use another geometry property
33+
* for rendering, use the `setGeometryName` method to change the attribute
34+
* property associated with the geometry for the feature. For example:
35+
*
36+
* ```js
37+
* var feature = new ol.Feature({
38+
* geometry: new ol.geom.Polygon(polyCoords),
39+
* labelPoint: new ol.geom.Point(labelCoords),
40+
* name: 'My Polygon'
41+
* });
42+
*
43+
* // get the polygon geometry
44+
* var poly = feature.getGeometry();
45+
*
46+
* // Render the feature as a point using the coordinates from labelPoint
47+
* feature.setGeometryName('labelPoint');
48+
*
49+
* // get the point geometry
50+
* var point = feature.getGeometry();
51+
* ```
2652
*
2753
* @constructor
2854
* @extends {ol.Object}
2955
* @fires change Triggered when the geometry or style of the feature changes.
3056
* @param {ol.geom.Geometry|Object.<string, *>=} opt_geometryOrProperties
31-
* Geometry or properties.
57+
* You may pass a Geometry object directly, or an object literal
58+
* containing properties. If you pass an object literal, you may
59+
* include a Geometry associated with a `geometry` key.
3260
* @api
3361
*/
3462
ol.Feature = function(opt_geometryOrProperties) {
@@ -109,7 +137,10 @@ ol.Feature.prototype.clone = function() {
109137

110138

111139
/**
112-
* @return {ol.geom.Geometry|undefined} Geometry.
140+
* @return {ol.geom.Geometry|undefined} Returns the Geometry associated
141+
* with this feature using the current geometry name property. By
142+
* default, this is `geometry` but it may be changed by calling
143+
* `setGeometryName`.
113144
* @api
114145
* @observable
115146
*/
@@ -133,7 +164,9 @@ ol.Feature.prototype.getId = function() {
133164

134165

135166
/**
136-
* @return {string} Geometry property name.
167+
* @return {string} Get the property name associated with the geometry for
168+
* this feature. By default, this is `geometry` but it may be changed by
169+
* calling `setGeometryName`.
137170
* @api
138171
*/
139172
ol.Feature.prototype.getGeometryName = function() {
@@ -143,7 +176,9 @@ ol.Feature.prototype.getGeometryName = function() {
143176

144177
/**
145178
* @return {ol.style.Style|Array.<ol.style.Style>|
146-
* ol.feature.FeatureStyleFunction} User provided style.
179+
* ol.feature.FeatureStyleFunction} Return the style provided in the
180+
* constructor options or the last call to setStyle in the same format
181+
* that it was provided in.
147182
* @api
148183
*/
149184
ol.Feature.prototype.getStyle = function() {
@@ -152,7 +187,8 @@ ol.Feature.prototype.getStyle = function() {
152187

153188

154189
/**
155-
* @return {ol.feature.FeatureStyleFunction|undefined} Style function.
190+
* @return {ol.feature.FeatureStyleFunction|undefined} Return a function
191+
* representing the current style of this feature.
156192
* @api
157193
*/
158194
ol.Feature.prototype.getStyleFunction = function() {
@@ -186,7 +222,10 @@ ol.Feature.prototype.handleGeometryChanged_ = function() {
186222

187223

188224
/**
189-
* @param {ol.geom.Geometry|undefined} geometry Geometry.
225+
* @param {ol.geom.Geometry|undefined} geometry Set the geometry for this
226+
* feature. This will update the property associated with the current
227+
* geometry property name. By default, this is `geometry` but it can be
228+
* changed by calling `setGeometryName`.
190229
* @api
191230
* @observable
192231
*/
@@ -201,7 +240,7 @@ goog.exportProperty(
201240

202241
/**
203242
* @param {ol.style.Style|Array.<ol.style.Style>|
204-
* ol.feature.FeatureStyleFunction} style Feature style.
243+
* ol.feature.FeatureStyleFunction} style Set the style for this feature.
205244
* @api
206245
*/
207246
ol.Feature.prototype.setStyle = function(style) {
@@ -212,7 +251,9 @@ ol.Feature.prototype.setStyle = function(style) {
212251

213252

214253
/**
215-
* @param {number|string|undefined} id Id.
254+
* @param {number|string|undefined} id Set a unique id for this feature.
255+
* The id may be used to retrieve a feature from a vector source with the
256+
* {@link ol.source.Vector#getFeatureById} method.
216257
* @api
217258
*/
218259
ol.Feature.prototype.setId = function(id) {
@@ -222,7 +263,8 @@ ol.Feature.prototype.setId = function(id) {
222263

223264

224265
/**
225-
* @param {string} name Geometry property name.
266+
* @param {string} name Set the property name from which this feature's
267+
* geometry will be fetched when calling `getGeometry`.
226268
* @api
227269
*/
228270
ol.Feature.prototype.setGeometryName = function(name) {

0 commit comments

Comments
 (0)