Allow geometryFunction to return undefined

This commit is contained in:
Andreas Hocevar
2014-12-16 01:12:08 +01:00
parent 6478454a93
commit af30b88413
5 changed files with 12 additions and 13 deletions

View File

@@ -6075,7 +6075,7 @@ olx.style.TextOptions.prototype.stroke;
/** /**
* @typedef {{geometry: (undefined|string|ol.geom.Geometry|function(ol.Feature): ol.geom.Geometry), * @typedef {{geometry: (undefined|string|ol.geom.Geometry|function(ol.Feature): (ol.geom.Geometry|undefined)),
* fill: (ol.style.Fill|undefined), * fill: (ol.style.Fill|undefined),
* image: (ol.style.Image|undefined), * image: (ol.style.Image|undefined),
* stroke: (ol.style.Stroke|undefined), * stroke: (ol.style.Stroke|undefined),
@@ -6089,7 +6089,7 @@ olx.style.StyleOptions;
/** /**
* Feature property or geometry or function returning a geometry to render * Feature property or geometry or function returning a geometry to render
* for this style. * for this style.
* @type {undefined|string|ol.geom.Geometry|function(ol.Feature): ol.geom.Geometry} * @type {undefined|string|ol.geom.Geometry|function(ol.Feature): (ol.geom.Geometry|undefined)}
* @api * @api
*/ */
olx.style.StyleOptions.prototype.geometry; olx.style.StyleOptions.prototype.geometry;

View File

@@ -478,7 +478,7 @@ ol.render.canvas.Immediate.prototype.drawCircleGeometry =
*/ */
ol.render.canvas.Immediate.prototype.drawFeature = function(feature, style) { ol.render.canvas.Immediate.prototype.drawFeature = function(feature, style) {
var geometry = style.getGeometryFunction()(feature); var geometry = style.getGeometryFunction()(feature);
if (goog.isNull(geometry) || if (!goog.isDefAndNotNull(geometry) ||
!ol.extent.intersects(this.extent_, geometry.getExtent())) { !ol.extent.intersects(this.extent_, geometry.getExtent())) {
return; return;
} }

View File

@@ -124,7 +124,7 @@ ol.renderer.vector.renderFeature = function(
ol.renderer.vector.renderFeature_ = function( ol.renderer.vector.renderFeature_ = function(
replayGroup, feature, style, squaredTolerance) { replayGroup, feature, style, squaredTolerance) {
var geometry = style.getGeometryFunction()(feature); var geometry = style.getGeometryFunction()(feature);
if (goog.isNull(geometry)) { if (!goog.isDefAndNotNull(geometry)) {
return; return;
} }
var simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance); var simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);

View File

@@ -119,7 +119,7 @@ ol.render.webgl.Immediate.prototype.drawCircleGeometry =
*/ */
ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) { ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) {
var geometry = style.getGeometryFunction()(feature); var geometry = style.getGeometryFunction()(feature);
if (goog.isNull(geometry) || if (!goog.isDefAndNotNull(geometry) ||
!ol.extent.intersects(this.extent_, geometry.getExtent())) { !ol.extent.intersects(this.extent_, geometry.getExtent())) {
return; return;
} }

View File

@@ -30,7 +30,7 @@ ol.style.Style = function(opt_options) {
* Function that is called with a feature and returns the geometry to render * Function that is called with a feature and returns the geometry to render
* for this style. * for this style.
* @private * @private
* @type {!function(ol.Feature): ol.geom.Geometry} * @type {!function(ol.Feature): (ol.geom.Geometry|undefined)}
*/ */
this.geometryFunction_ = ol.style.defaultGeometryFunction; this.geometryFunction_ = ol.style.defaultGeometryFunction;
@@ -72,9 +72,9 @@ ol.style.Style = function(opt_options) {
/** /**
* @return {!function(ol.Feature): ol.geom.Geometry} Function that is called * @return {!function(ol.Feature): (ol.geom.Geometry|undefined)} Function that
* with a feature and returns the geometry to render instead of the feature's * is called with a feature and returns the geometry to render instead of the
* geometry. * feature's geometry.
*/ */
ol.style.Style.prototype.getGeometryFunction = function() { ol.style.Style.prototype.getGeometryFunction = function() {
return this.geometryFunction_; return this.geometryFunction_;
@@ -129,7 +129,7 @@ ol.style.Style.prototype.getZIndex = function() {
/** /**
* Set a geometry that is rendered instead of the feature's geometry. * Set a geometry that is rendered instead of the feature's geometry.
* *
* @param {string|ol.geom.Geometry|function(ol.Feature): ol.geom.Geometry} geometry * @param {string|ol.geom.Geometry|function(ol.Feature): (ol.geom.Geometry|undefined)} geometry
* Feature property or geometry or function returning a geometry to render * Feature property or geometry or function returning a geometry to render
* for this style. * for this style.
* @api * @api
@@ -318,10 +318,9 @@ ol.style.createDefaultEditingStyles = function() {
/** /**
* @param {ol.Feature} feature Feature to get the geometry for. * @param {ol.Feature} feature Feature to get the geometry for.
* @return {ol.geom.Geometry} Geometry to render. * @return {ol.geom.Geometry|undefined} Geometry to render.
*/ */
ol.style.defaultGeometryFunction = function(feature) { ol.style.defaultGeometryFunction = function(feature) {
goog.asserts.assert(!goog.isNull(feature)); goog.asserts.assert(!goog.isNull(feature));
var geometry = feature.getGeometry(); return feature.getGeometry();
return goog.isDef(geometry) ? geometry : null;
}; };