@@ -17,18 +17,46 @@ goog.require('ol.style.Style');
17
17
18
18
/**
19
19
* @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
21
21
* attribute properties, similar to the features in vector file formats like
22
22
* GeoJSON.
23
+ *
23
24
* 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
+ * ```
26
52
*
27
53
* @constructor
28
54
* @extends {ol.Object }
29
55
* @fires change Triggered when the geometry or style of the feature changes.
30
56
* @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.
32
60
* @api
33
61
*/
34
62
ol . Feature = function ( opt_geometryOrProperties ) {
@@ -109,7 +137,10 @@ ol.Feature.prototype.clone = function() {
109
137
110
138
111
139
/**
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`.
113
144
* @api
114
145
* @observable
115
146
*/
@@ -133,7 +164,9 @@ ol.Feature.prototype.getId = function() {
133
164
134
165
135
166
/**
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`.
137
170
* @api
138
171
*/
139
172
ol . Feature . prototype . getGeometryName = function ( ) {
@@ -143,7 +176,9 @@ ol.Feature.prototype.getGeometryName = function() {
143
176
144
177
/**
145
178
* @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.
147
182
* @api
148
183
*/
149
184
ol . Feature . prototype . getStyle = function ( ) {
@@ -152,7 +187,8 @@ ol.Feature.prototype.getStyle = function() {
152
187
153
188
154
189
/**
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.
156
192
* @api
157
193
*/
158
194
ol . Feature . prototype . getStyleFunction = function ( ) {
@@ -186,7 +222,10 @@ ol.Feature.prototype.handleGeometryChanged_ = function() {
186
222
187
223
188
224
/**
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`.
190
229
* @api
191
230
* @observable
192
231
*/
@@ -201,7 +240,7 @@ goog.exportProperty(
201
240
202
241
/**
203
242
* @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 .
205
244
* @api
206
245
*/
207
246
ol . Feature . prototype . setStyle = function ( style ) {
@@ -212,7 +251,9 @@ ol.Feature.prototype.setStyle = function(style) {
212
251
213
252
214
253
/**
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.
216
257
* @api
217
258
*/
218
259
ol . Feature . prototype . setId = function ( id ) {
@@ -222,7 +263,8 @@ ol.Feature.prototype.setId = function(id) {
222
263
223
264
224
265
/**
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`.
226
268
* @api
227
269
*/
228
270
ol . Feature . prototype . setGeometryName = function ( name ) {
0 commit comments