Merge pull request #6258 from ahocevar/set-geometry-name

Set geometry name properly
This commit is contained in:
Andreas Hocevar
2016-12-15 18:44:42 +01:00
committed by GitHub
2 changed files with 35 additions and 7 deletions
+6 -7
View File
@@ -53,10 +53,9 @@ ol.format.MVT = function(opt_options) {
/** /**
* @private * @private
* @type {string} * @type {string|undefined}
*/ */
this.geometryName_ = options.geometryName ? this.geometryName_ = options.geometryName;
options.geometryName : 'geometry';
/** /**
* @private * @private
@@ -95,15 +94,15 @@ ol.format.MVT.prototype.readFeature_ = function(
var id = rawFeature.id; var id = rawFeature.id;
var values = rawFeature.properties; var values = rawFeature.properties;
values[this.layerName_] = layer; values[this.layerName_] = layer;
if (this.geometryName_) {
feature.setGeometryName(this.geometryName_);
}
var geometry = ol.format.Feature.transformWithOptions( var geometry = ol.format.Feature.transformWithOptions(
ol.format.MVT.readGeometry_(rawFeature), false, ol.format.MVT.readGeometry_(rawFeature), false,
this.adaptOptions(opt_options)); this.adaptOptions(opt_options));
if (geometry) { feature.setGeometry(geometry);
values[this.geometryName_] = geometry;
}
feature.setId(id); feature.setId(id);
feature.setProperties(values); feature.setProperties(values);
feature.setGeometryName(this.geometryName_);
return feature; return feature;
}; };
+29
View File
@@ -4,6 +4,7 @@ goog.require('ol.Feature');
goog.require('ol.ext.pbf'); goog.require('ol.ext.pbf');
goog.require('ol.ext.vectortile'); goog.require('ol.ext.vectortile');
goog.require('ol.format.MVT'); goog.require('ol.format.MVT');
goog.require('ol.geom.Point');
goog.require('ol.render.Feature'); goog.require('ol.render.Feature');
where('ArrayBuffer.isView').describe('ol.format.MVT', function() { where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
@@ -83,3 +84,31 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
}); });
}); });
describe('ol.format.MVT', function() {
describe('#readFeature_', function() {
it('accepts a geometryName', function() {
var format = new ol.format.MVT({
featureClass: ol.Feature,
geometryName: 'myGeom'
});
var rawFeature = {
id: 1,
properties: {
geometry: 'foo'
},
type: 1,
loadGeometry: function() {
return [[0, 0]];
}
};
var feature = format.readFeature_(rawFeature, 'mapbox');
var geometry = feature.getGeometry();
expect(geometry).to.be.a(ol.geom.Point);
expect(feature.get('myGeom')).to.equal(geometry);
expect(feature.get('geometry')).to.be('foo');
});
});
});