Merge pull request #1356 from tonio/vector-api-multiplegeom

[vector-api] add support for features with multiples geometries
This commit is contained in:
Antoine Abt
2013-12-19 08:11:52 -08:00
3 changed files with 250 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.Feature
@exportProperty ol.Feature.prototype.getGeometry
@exportProperty ol.Feature.prototype.getGeometryName
@exportProperty ol.Feature.prototype.setGeometryName
@exportProperty ol.Feature.prototype.getId
@exportProperty ol.Feature.prototype.setId

View File

@@ -12,7 +12,6 @@ goog.require('ol.style.Style');
* @enum {string}
*/
ol.FeatureProperty = {
GEOMETRY: 'geometry',
STYLE_FUNCTION: 'styleFunction'
};
@@ -40,6 +39,12 @@ ol.Feature = function(opt_geometryOrValues) {
*/
this.id_ = undefined;
/**
* @type {string}
* @private
*/
this.geometryName_ = 'geometry';
/**
* @private
* @type {number}
@@ -53,7 +58,7 @@ ol.Feature = function(opt_geometryOrValues) {
this.geometryChangeKey_ = null;
goog.events.listen(
this, ol.Object.getChangeEventType(ol.FeatureProperty.GEOMETRY),
this, ol.Object.getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, false, this);
goog.events.listen(
this, ol.Object.getChangeEventType(ol.FeatureProperty.STYLE_FUNCTION),
@@ -89,7 +94,7 @@ ol.Feature.prototype.dispatchChangeEvent = function() {
*/
ol.Feature.prototype.getGeometry = function() {
return /** @type {ol.geom.Geometry|undefined} */ (
this.get(ol.FeatureProperty.GEOMETRY));
this.get(this.geometryName_));
};
goog.exportProperty(
ol.Feature.prototype,
@@ -105,6 +110,14 @@ ol.Feature.prototype.getId = function() {
};
/**
* @return {string} Geometry property name.
*/
ol.Feature.prototype.getGeometryName = function() {
return this.geometryName_;
};
/**
* @return {number} Revision.
*/
@@ -163,7 +176,7 @@ ol.Feature.prototype.handleStyleFunctionChange_ = function() {
* @param {ol.geom.Geometry|undefined} geometry Geometry.
*/
ol.Feature.prototype.setGeometry = function(geometry) {
this.set(ol.FeatureProperty.GEOMETRY, geometry);
this.set(this.geometryName_, geometry);
};
goog.exportProperty(
ol.Feature.prototype,
@@ -189,3 +202,18 @@ goog.exportProperty(
ol.Feature.prototype.setId = function(id) {
this.id_ = id;
};
/**
* @param {string} name Geometry property name.
*/
ol.Feature.prototype.setGeometryName = function(name) {
goog.events.unlisten(
this, ol.Object.getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, false, this);
this.geometryName_ = name;
goog.events.listen(
this, ol.Object.getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, false, this);
this.handleGeometryChanged_();
};