Add a getGeometry method
This commit is contained in:
+25
-7
@@ -26,6 +26,12 @@ ol.style.Style = function(opt_options) {
|
|||||||
|
|
||||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {string|ol.geom.Geometry|ol.style.GeometryFunction}
|
||||||
|
*/
|
||||||
|
this.geometry_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {!ol.style.GeometryFunction}
|
* @type {!ol.style.GeometryFunction}
|
||||||
@@ -70,9 +76,20 @@ ol.style.Style = function(opt_options) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {!ol.style.GeometryFunction} Function that
|
* @return {string|ol.geom.Geometry|ol.style.GeometryFunction}
|
||||||
* is called with a feature and returns the geometry to render instead of the
|
* Feature property or geometry or function that returns the geometry that will
|
||||||
* feature's geometry.
|
* be rendered with this style.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.style.Style.prototype.getGeometry = function() {
|
||||||
|
return this.geometry_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {!ol.style.GeometryFunction} Function that is called with a feature
|
||||||
|
* and returns the geometry to render instead of the feature's geometry.
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.style.Style.prototype.getGeometryFunction = function() {
|
ol.style.Style.prototype.getGeometryFunction = function() {
|
||||||
return this.geometryFunction_;
|
return this.geometryFunction_;
|
||||||
@@ -143,14 +160,15 @@ ol.style.Style.prototype.setGeometry = function(geometry) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
} else if (goog.isNull(geometry)) {
|
||||||
|
this.geometryFunction_ = ol.style.defaultGeometryFunction;
|
||||||
} else if (goog.isDef(geometry)) {
|
} else if (goog.isDef(geometry)) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry);
|
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry);
|
||||||
this.geometryFunction_ = function() {
|
this.geometryFunction_ = function() {
|
||||||
return geometry;
|
return geometry;
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
this.geometryFunction_ = ol.style.defaultGeometryFunction;
|
|
||||||
}
|
}
|
||||||
|
this.geometry_ = geometry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -319,8 +337,8 @@ ol.style.createDefaultEditingStyles = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that takes an `{ol.Feature}` as argument and returns a geometry
|
* A function that takes an {@link ol.Feature} as argument and returns an
|
||||||
* that will be rendered and styled for the feature.
|
* {@link ol.geom.Geometry} that will be rendered and styled for the feature.
|
||||||
*
|
*
|
||||||
* @typedef {function(ol.Feature): (ol.geom.Geometry|undefined)}
|
* @typedef {function(ol.Feature): (ol.geom.Geometry|undefined)}
|
||||||
* @api
|
* @api
|
||||||
|
|||||||
@@ -40,6 +40,24 @@ describe('ol.style.Style', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getGeometry', function() {
|
||||||
|
|
||||||
|
it('returns whatever was passed to setGeometry', function() {
|
||||||
|
var style = new ol.style.Style();
|
||||||
|
style.setGeometry('foo');
|
||||||
|
expect(style.getGeometry()).to.eql('foo');
|
||||||
|
var geom = new ol.geom.Point([1, 2]);
|
||||||
|
style.setGeometry(geom);
|
||||||
|
expect(style.getGeometry()).to.eql(geom);
|
||||||
|
var fn = function() { return geom; };
|
||||||
|
style.setGeometry(fn);
|
||||||
|
expect(style.getGeometry()).to.eql(fn);
|
||||||
|
style.setGeometry(null);
|
||||||
|
expect(style.getGeometry()).to.eql(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ol.style.createStyleFunction()', function() {
|
describe('ol.style.createStyleFunction()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user