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