Uniformly support evaluating symbolizers without features
In combination with a (not yet implemented) `Symbolizer#isLiteral` method, calling `Symbolizer#evaluate` without a feature is the fast track for rendering batches of like-styled features. This change also simplifies the handling of undefined symbolizer literal properties (where stroke or fill properties are optional).
This commit is contained in:
@@ -16,12 +16,18 @@ goog.require('ol.geom.GeometryType');
|
|||||||
* function scope. The feature itself will be used as the `this` argument.
|
* function scope. The feature itself will be used as the `this` argument.
|
||||||
*
|
*
|
||||||
* @param {ol.expression.Expression} expr The expression.
|
* @param {ol.expression.Expression} expr The expression.
|
||||||
* @param {ol.Feature} feature The feature.
|
* @param {ol.Feature=} opt_feature The feature.
|
||||||
* @return {*} The result of the expression.
|
* @return {*} The result of the expression.
|
||||||
*/
|
*/
|
||||||
ol.expression.evaluateFeature = function(expr, feature) {
|
ol.expression.evaluateFeature = function(expr, opt_feature) {
|
||||||
return expr.evaluate(
|
var result;
|
||||||
feature.getAttributes(), ol.expression.lib, feature);
|
if (goog.isDef(opt_feature)) {
|
||||||
|
result = expr.evaluate(
|
||||||
|
opt_feature.getAttributes(), ol.expression.lib, opt_feature);
|
||||||
|
} else {
|
||||||
|
result = expr.evaluate();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-16
@@ -3,6 +3,7 @@ goog.provide('ol.style.IconLiteral');
|
|||||||
goog.provide('ol.style.IconType');
|
goog.provide('ol.style.IconType');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('ol.expression');
|
||||||
goog.require('ol.expression.Expression');
|
goog.require('ol.expression.Expression');
|
||||||
goog.require('ol.expression.Literal');
|
goog.require('ol.expression.Literal');
|
||||||
goog.require('ol.style.Point');
|
goog.require('ol.style.Point');
|
||||||
@@ -118,28 +119,28 @@ ol.style.Icon = function(options) {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @return {ol.style.IconLiteral} Literal shape symbolizer.
|
* @return {ol.style.IconLiteral} Literal shape symbolizer.
|
||||||
*/
|
*/
|
||||||
ol.style.Icon.prototype.createLiteral = function(feature) {
|
ol.style.Icon.prototype.createLiteral = function(opt_feature) {
|
||||||
var attrs = feature && feature.getAttributes();
|
|
||||||
|
|
||||||
var url = /** @type {string} */ (this.url_.evaluate(attrs, null, feature));
|
var url = ol.expression.evaluateFeature(this.url_, opt_feature);
|
||||||
goog.asserts.assert(goog.isString(url) && url != '#', 'url must be a string');
|
goog.asserts.assertString(url, 'url must be a string');
|
||||||
|
goog.asserts.assert(url != '#', 'url must not be "#"');
|
||||||
|
|
||||||
var width = /** @type {number|undefined} */ (goog.isNull(this.width_) ?
|
var width;
|
||||||
undefined : this.width_.evaluate(attrs, null, feature));
|
if (!goog.isNull(this.width_)) {
|
||||||
goog.asserts.assert(!goog.isDef(width) || goog.isNumber(width),
|
width = ol.expression.evaluateFeature(this.width_, opt_feature);
|
||||||
'width must be undefined or a number');
|
goog.asserts.assertNumber(width, 'width must be a number');
|
||||||
|
}
|
||||||
|
|
||||||
var height = /** @type {number|undefined} */ (goog.isNull(this.height_) ?
|
var height;
|
||||||
undefined : this.height_.evaluate(attrs, null, feature));
|
if (!goog.isNull(this.height_)) {
|
||||||
goog.asserts.assert(!goog.isDef(height) || goog.isNumber(height),
|
height = ol.expression.evaluateFeature(this.height_, opt_feature);
|
||||||
'height must be undefined or a number');
|
goog.asserts.assertNumber(height, 'height must be a number');
|
||||||
|
}
|
||||||
|
|
||||||
var opacity = /** {@type {number} */ (this.opacity_.evaluate(attrs, null,
|
var opacity = ol.expression.evaluateFeature(this.opacity_, opt_feature);
|
||||||
feature));
|
|
||||||
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
||||||
|
|
||||||
var rotation =
|
var rotation = ol.expression.evaluateFeature(this.rotation_, opt_feature);
|
||||||
/** {@type {number} */ (this.rotation_.evaluate(attrs, null, feature));
|
|
||||||
goog.asserts.assertNumber(rotation, 'rotation must be a number');
|
goog.asserts.assertNumber(rotation, 'rotation must be a number');
|
||||||
|
|
||||||
return new ol.style.IconLiteral({
|
return new ol.style.IconLiteral({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ goog.provide('ol.style.Line');
|
|||||||
goog.provide('ol.style.LineLiteral');
|
goog.provide('ol.style.LineLiteral');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('ol.expression');
|
||||||
goog.require('ol.expression.Expression');
|
goog.require('ol.expression.Expression');
|
||||||
goog.require('ol.expression.Literal');
|
goog.require('ol.expression.Literal');
|
||||||
goog.require('ol.style.Symbolizer');
|
goog.require('ol.style.Symbolizer');
|
||||||
@@ -98,19 +99,16 @@ goog.inherits(ol.style.Line, ol.style.Symbolizer);
|
|||||||
* @return {ol.style.LineLiteral} Literal line symbolizer.
|
* @return {ol.style.LineLiteral} Literal line symbolizer.
|
||||||
*/
|
*/
|
||||||
ol.style.Line.prototype.createLiteral = function(opt_feature) {
|
ol.style.Line.prototype.createLiteral = function(opt_feature) {
|
||||||
var attrs,
|
|
||||||
feature = opt_feature;
|
|
||||||
if (goog.isDef(feature)) {
|
|
||||||
attrs = feature.getAttributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
var strokeColor = this.strokeColor_.evaluate(attrs, null, feature);
|
var strokeColor = ol.expression.evaluateFeature(
|
||||||
|
this.strokeColor_, opt_feature);
|
||||||
goog.asserts.assertString(strokeColor, 'strokeColor must be a string');
|
goog.asserts.assertString(strokeColor, 'strokeColor must be a string');
|
||||||
|
|
||||||
var strokeWidth = this.strokeWidth_.evaluate(attrs, null, feature);
|
var strokeWidth = ol.expression.evaluateFeature(
|
||||||
|
this.strokeWidth_, opt_feature);
|
||||||
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
|
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
|
||||||
|
|
||||||
var opacity = this.opacity_.evaluate(attrs, null, feature);
|
var opacity = ol.expression.evaluateFeature(this.opacity_, opt_feature);
|
||||||
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
||||||
|
|
||||||
return new ol.style.LineLiteral({
|
return new ol.style.LineLiteral({
|
||||||
|
|||||||
+18
-19
@@ -2,6 +2,7 @@ goog.provide('ol.style.Polygon');
|
|||||||
goog.provide('ol.style.PolygonLiteral');
|
goog.provide('ol.style.PolygonLiteral');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('ol.expression');
|
||||||
goog.require('ol.expression.Expression');
|
goog.require('ol.expression.Expression');
|
||||||
goog.require('ol.expression.Literal');
|
goog.require('ol.expression.Literal');
|
||||||
goog.require('ol.style.Symbolizer');
|
goog.require('ol.style.Symbolizer');
|
||||||
@@ -149,33 +150,31 @@ goog.inherits(ol.style.Polygon, ol.style.Symbolizer);
|
|||||||
* @return {ol.style.PolygonLiteral} Literal shape symbolizer.
|
* @return {ol.style.PolygonLiteral} Literal shape symbolizer.
|
||||||
*/
|
*/
|
||||||
ol.style.Polygon.prototype.createLiteral = function(opt_feature) {
|
ol.style.Polygon.prototype.createLiteral = function(opt_feature) {
|
||||||
var attrs,
|
|
||||||
feature = opt_feature;
|
var fillColor;
|
||||||
if (goog.isDef(feature)) {
|
if (!goog.isNull(this.fillColor_)) {
|
||||||
attrs = feature.getAttributes();
|
fillColor = ol.expression.evaluateFeature(this.fillColor_, opt_feature);
|
||||||
|
goog.asserts.assertString(fillColor, 'fillColor must be a string');
|
||||||
}
|
}
|
||||||
|
|
||||||
var fillColor = goog.isNull(this.fillColor_) ?
|
var strokeColor;
|
||||||
undefined :
|
if (!goog.isNull(this.strokeColor_)) {
|
||||||
/** @type {string} */ (this.fillColor_.evaluate(attrs, null, feature));
|
strokeColor = ol.expression.evaluateFeature(this.strokeColor_, opt_feature);
|
||||||
goog.asserts.assert(!goog.isDef(fillColor) || goog.isString(fillColor));
|
goog.asserts.assertString(strokeColor, 'strokeColor must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
var strokeColor = goog.isNull(this.strokeColor_) ?
|
var strokeWidth;
|
||||||
undefined :
|
if (!goog.isNull(this.strokeWidth_)) {
|
||||||
/** @type {string} */ (this.strokeColor_.evaluate(attrs, null, feature));
|
strokeWidth = ol.expression.evaluateFeature(this.strokeWidth_, opt_feature);
|
||||||
goog.asserts.assert(!goog.isDef(strokeColor) || goog.isString(strokeColor));
|
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
|
||||||
|
}
|
||||||
var strokeWidth = goog.isNull(this.strokeWidth_) ?
|
|
||||||
undefined :
|
|
||||||
/** @type {number} */ (this.strokeWidth_.evaluate(attrs, null, feature));
|
|
||||||
goog.asserts.assert(!goog.isDef(strokeWidth) || goog.isNumber(strokeWidth));
|
|
||||||
|
|
||||||
goog.asserts.assert(
|
goog.asserts.assert(
|
||||||
goog.isDef(fillColor) ||
|
goog.isDef(fillColor) ||
|
||||||
(goog.isDef(strokeColor) && goog.isDef(strokeWidth)),
|
(goog.isDef(strokeColor) && goog.isDef(strokeWidth)),
|
||||||
'either fill style or strokeColor and strokeWidth must be defined');
|
'either fillColor or strokeColor and strokeWidth must be defined');
|
||||||
|
|
||||||
var opacity = this.opacity_.evaluate(attrs, null, feature);
|
var opacity = ol.expression.evaluateFeature(this.opacity_, opt_feature);
|
||||||
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
||||||
|
|
||||||
return new ol.style.PolygonLiteral({
|
return new ol.style.PolygonLiteral({
|
||||||
|
|||||||
+19
-20
@@ -3,6 +3,7 @@ goog.provide('ol.style.ShapeLiteral');
|
|||||||
goog.provide('ol.style.ShapeType');
|
goog.provide('ol.style.ShapeType');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('ol.expression');
|
||||||
goog.require('ol.expression.Expression');
|
goog.require('ol.expression.Expression');
|
||||||
goog.require('ol.expression.Literal');
|
goog.require('ol.expression.Literal');
|
||||||
goog.require('ol.style.Point');
|
goog.require('ol.style.Point');
|
||||||
@@ -184,36 +185,34 @@ ol.style.Shape = function(options) {
|
|||||||
* @return {ol.style.ShapeLiteral} Literal shape symbolizer.
|
* @return {ol.style.ShapeLiteral} Literal shape symbolizer.
|
||||||
*/
|
*/
|
||||||
ol.style.Shape.prototype.createLiteral = function(opt_feature) {
|
ol.style.Shape.prototype.createLiteral = function(opt_feature) {
|
||||||
var attrs,
|
|
||||||
feature = opt_feature;
|
|
||||||
if (goog.isDef(feature)) {
|
|
||||||
attrs = feature.getAttributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
var size = this.size_.evaluate(attrs, null, feature);
|
var size = ol.expression.evaluateFeature(this.size_, opt_feature);
|
||||||
goog.asserts.assertNumber(size, 'size must be a number');
|
goog.asserts.assertNumber(size, 'size must be a number');
|
||||||
|
|
||||||
var fillColor = goog.isNull(this.fillColor_) ?
|
var fillColor;
|
||||||
undefined :
|
if (!goog.isNull(this.fillColor_)) {
|
||||||
/** @type {string} */ (this.fillColor_.evaluate(attrs, null, feature));
|
fillColor = ol.expression.evaluateFeature(this.fillColor_, opt_feature);
|
||||||
goog.asserts.assert(!goog.isDef(fillColor) || goog.isString(fillColor));
|
goog.asserts.assertString(fillColor, 'fillColor must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
var strokeColor = goog.isNull(this.strokeColor_) ?
|
var strokeColor;
|
||||||
undefined :
|
if (!goog.isNull(this.strokeColor_)) {
|
||||||
/** @type {string} */ (this.strokeColor_.evaluate(attrs, null, feature));
|
strokeColor = ol.expression.evaluateFeature(this.strokeColor_, opt_feature);
|
||||||
goog.asserts.assert(!goog.isDef(strokeColor) || goog.isString(strokeColor));
|
goog.asserts.assertString(strokeColor, 'strokeColor must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
var strokeWidth = goog.isNull(this.strokeWidth_) ?
|
var strokeWidth;
|
||||||
undefined :
|
if (!goog.isNull(this.strokeWidth_)) {
|
||||||
/** @type {number} */ (this.strokeWidth_.evaluate(attrs, null, feature));
|
strokeWidth = ol.expression.evaluateFeature(this.strokeWidth_, opt_feature);
|
||||||
goog.asserts.assert(!goog.isDef(strokeWidth) || goog.isNumber(strokeWidth));
|
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
|
||||||
|
}
|
||||||
|
|
||||||
goog.asserts.assert(
|
goog.asserts.assert(
|
||||||
goog.isDef(fillColor) ||
|
goog.isDef(fillColor) ||
|
||||||
(goog.isDef(strokeColor) && goog.isDef(strokeWidth)),
|
(goog.isDef(strokeColor) && goog.isDef(strokeWidth)),
|
||||||
'either fill style or strokeColor and strokeWidth must be defined');
|
'either fillColor or strokeColor and strokeWidth must be defined');
|
||||||
|
|
||||||
var opacity = this.opacity_.evaluate(attrs, null, feature);
|
var opacity = ol.expression.evaluateFeature(this.opacity_, opt_feature);
|
||||||
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
||||||
|
|
||||||
return new ol.style.ShapeLiteral({
|
return new ol.style.ShapeLiteral({
|
||||||
|
|||||||
+6
-10
@@ -2,6 +2,7 @@ goog.provide('ol.style.Text');
|
|||||||
goog.provide('ol.style.TextLiteral');
|
goog.provide('ol.style.TextLiteral');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('ol.expression');
|
||||||
goog.require('ol.expression.Expression');
|
goog.require('ol.expression.Expression');
|
||||||
goog.require('ol.expression.Literal');
|
goog.require('ol.expression.Literal');
|
||||||
goog.require('ol.style.Symbolizer');
|
goog.require('ol.style.Symbolizer');
|
||||||
@@ -121,25 +122,20 @@ goog.inherits(ol.style.Text, ol.style.Symbolizer);
|
|||||||
* @return {ol.style.TextLiteral} Literal text symbolizer.
|
* @return {ol.style.TextLiteral} Literal text symbolizer.
|
||||||
*/
|
*/
|
||||||
ol.style.Text.prototype.createLiteral = function(opt_feature) {
|
ol.style.Text.prototype.createLiteral = function(opt_feature) {
|
||||||
var attrs,
|
|
||||||
feature = opt_feature;
|
|
||||||
if (goog.isDef(feature)) {
|
|
||||||
attrs = feature.getAttributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
var color = this.color_.evaluate(attrs, null, feature);
|
var color = ol.expression.evaluateFeature(this.color_, opt_feature);
|
||||||
goog.asserts.assertString(color, 'color must be a string');
|
goog.asserts.assertString(color, 'color must be a string');
|
||||||
|
|
||||||
var fontFamily = this.fontFamily_.evaluate(attrs, null, feature);
|
var fontFamily = ol.expression.evaluateFeature(this.fontFamily_, opt_feature);
|
||||||
goog.asserts.assertString(fontFamily, 'fontFamily must be a string');
|
goog.asserts.assertString(fontFamily, 'fontFamily must be a string');
|
||||||
|
|
||||||
var fontSize = this.fontSize_.evaluate(attrs, null, feature);
|
var fontSize = ol.expression.evaluateFeature(this.fontSize_, opt_feature);
|
||||||
goog.asserts.assertNumber(fontSize, 'fontSize must be a number');
|
goog.asserts.assertNumber(fontSize, 'fontSize must be a number');
|
||||||
|
|
||||||
var text = this.text_.evaluate(attrs, null, feature);
|
var text = ol.expression.evaluateFeature(this.text_, opt_feature);
|
||||||
goog.asserts.assertString(text, 'text must be a string');
|
goog.asserts.assertString(text, 'text must be a string');
|
||||||
|
|
||||||
var opacity = this.opacity_.evaluate(attrs, null, feature);
|
var opacity = ol.expression.evaluateFeature(this.opacity_, opt_feature);
|
||||||
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
goog.asserts.assertNumber(opacity, 'opacity must be a number');
|
||||||
|
|
||||||
return new ol.style.TextLiteral({
|
return new ol.style.TextLiteral({
|
||||||
|
|||||||
Reference in New Issue
Block a user