Add getId() method for ol.render.Feature
This commit is contained in:
@@ -1981,9 +1981,9 @@ olx.format.MVTOptions;
|
||||
* {@link ol.Feature} to get full editing and geometry support at the cost of
|
||||
* decreased rendering performance. The default is {@link ol.render.Feature},
|
||||
* which is optimized for rendering and hit detection.
|
||||
* @type {undefined|function((ol.geom.Geometry|Object.<string, *>)=)|
|
||||
* @type {undefined|function((ol.geom.Geometry|Object.<string,*>)=)|
|
||||
* function(ol.geom.GeometryType,Array.<number>,
|
||||
* (Array.<number>|Array.<Array.<number>>),Object.<string, *>)}
|
||||
* (Array.<number>|Array.<Array.<number>>),Object.<string,*>,number)}
|
||||
* @api
|
||||
*/
|
||||
olx.format.MVTOptions.prototype.featureClass;
|
||||
|
||||
@@ -44,9 +44,9 @@ ol.format.MVT = function(opt_options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function((ol.geom.Geometry|Object.<string, *>)=)|
|
||||
* @type {function((ol.geom.Geometry|Object.<string,*>)=)|
|
||||
* function(ol.geom.GeometryType,Array.<number>,
|
||||
* (Array.<number>|Array.<Array.<number>>),Object.<string, *>)}
|
||||
* (Array.<number>|Array.<Array.<number>>),Object.<string,*>,number)}
|
||||
*/
|
||||
this.featureClass_ = options.featureClass ?
|
||||
options.featureClass : ol.render.Feature;
|
||||
@@ -137,8 +137,9 @@ ol.format.MVT.prototype.readRenderFeature_ = function(rawFeature, layer) {
|
||||
|
||||
var values = rawFeature.properties;
|
||||
values[this.layerName_] = layer;
|
||||
var id = rawFeature.id;
|
||||
|
||||
return new this.featureClass_(geometryType, flatCoordinates, ends, values);
|
||||
return new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -16,14 +16,21 @@ goog.require('ol.geom.GeometryType');
|
||||
* to be right-handed for polygons.
|
||||
* @param {Array.<number>|Array.<Array.<number>>} ends Ends or Endss.
|
||||
* @param {Object.<string, *>} properties Properties.
|
||||
* @param {number|string|undefined} id Feature id.
|
||||
*/
|
||||
ol.render.Feature = function(type, flatCoordinates, ends, properties) {
|
||||
ol.render.Feature = function(type, flatCoordinates, ends, properties, id) {
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Extent|undefined}
|
||||
*/
|
||||
this.extent_;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|string|undefined}
|
||||
*/
|
||||
this.id_ = id;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.geom.GeometryType}
|
||||
@@ -85,6 +92,16 @@ ol.render.Feature.prototype.getExtent = function() {
|
||||
return this.extent_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the feature identifier. This is a stable identifier for the feature and
|
||||
* is set when reading data from a remote source.
|
||||
* @return {number|string|undefined} Id.
|
||||
* @api
|
||||
*/
|
||||
ol.render.Feature.prototype.getId = function() {
|
||||
return this.id_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
|
||||
@@ -73,12 +73,19 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
|
||||
});
|
||||
|
||||
it('parses id property', function() {
|
||||
// ol.Feature
|
||||
var format = new ol.format.MVT({
|
||||
featureClass: ol.Feature,
|
||||
layers: ['building']
|
||||
});
|
||||
var features = format.readFeatures(data);
|
||||
expect(features[0].getId()).to.be(2);
|
||||
// ol.render.Feature
|
||||
format = new ol.format.MVT({
|
||||
layers: ['building']
|
||||
});
|
||||
features = format.readFeatures(data);
|
||||
expect(features[0].getId()).to.be(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('ol.render.Feature', function() {
|
||||
describe('Constructor', function() {
|
||||
it('creates an instance', function() {
|
||||
renderFeature =
|
||||
new ol.render.Feature(type, flatCoordinates, ends, properties);
|
||||
new ol.render.Feature(type, flatCoordinates, ends, properties, 'foo');
|
||||
expect(renderFeature).to.be.a(ol.render.Feature);
|
||||
});
|
||||
});
|
||||
@@ -57,6 +57,12 @@ describe('ol.render.Feature', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getId()', function() {
|
||||
it('returns the feature id', function() {
|
||||
expect(renderFeature.getId()).to.be('foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getProperties()', function() {
|
||||
it('returns the properties it was created with', function() {
|
||||
expect(renderFeature.getProperties()).to.equal(properties);
|
||||
|
||||
Reference in New Issue
Block a user