Using ol.expression.parse

This commit is contained in:
Tim Schaub
2013-06-12 17:45:17 -06:00
parent 53abedaada
commit 5e309e244b
13 changed files with 145 additions and 298 deletions
+28 -26
View File
@@ -3,8 +3,8 @@ goog.provide('ol.style.ShapeLiteral');
goog.provide('ol.style.ShapeType');
goog.require('goog.asserts');
goog.require('ol.Expression');
goog.require('ol.ExpressionLiteral');
goog.require('ol.expression.Expression');
goog.require('ol.expression.Literal');
goog.require('ol.style.Point');
goog.require('ol.style.PointLiteral');
@@ -106,22 +106,22 @@ ol.style.Shape = function(options) {
options.type : ol.style.ShapeDefaults.type);
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.size_ = !goog.isDef(options.size) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.size) :
(options.size instanceof ol.Expression) ?
options.size : new ol.ExpressionLiteral(options.size);
new ol.expression.Literal(ol.style.ShapeDefaults.size) :
(options.size instanceof ol.expression.Expression) ?
options.size : new ol.expression.Literal(options.size);
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.fillColor_ = !goog.isDefAndNotNull(options.fillColor) ?
null :
(options.fillColor instanceof ol.Expression) ?
options.fillColor : new ol.ExpressionLiteral(options.fillColor);
(options.fillColor instanceof ol.expression.Expression) ?
options.fillColor : new ol.expression.Literal(options.fillColor);
// stroke handling - if any stroke property is supplied, use defaults
var strokeColor = null,
@@ -131,24 +131,26 @@ ol.style.Shape = function(options) {
goog.isDefAndNotNull(options.strokeWidth)) {
strokeColor = !goog.isDefAndNotNull(options.strokeColor) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.strokeColor) :
(options.strokeColor instanceof ol.Expression) ?
options.strokeColor : new ol.ExpressionLiteral(options.strokeColor);
new ol.expression.Literal(ol.style.ShapeDefaults.strokeColor) :
(options.strokeColor instanceof ol.expression.Expression) ?
options.strokeColor :
new ol.expression.Literal(options.strokeColor);
strokeWidth = !goog.isDef(options.strokeWidth) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.strokeWidth) :
(options.strokeWidth instanceof ol.Expression) ?
options.strokeWidth : new ol.ExpressionLiteral(options.strokeWidth);
new ol.expression.Literal(ol.style.ShapeDefaults.strokeWidth) :
(options.strokeWidth instanceof ol.expression.Expression) ?
options.strokeWidth :
new ol.expression.Literal(options.strokeWidth);
}
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.strokeColor_ = strokeColor;
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.strokeWidth_ = strokeWidth;
@@ -159,13 +161,13 @@ ol.style.Shape = function(options) {
'Stroke or fill properties must be provided');
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.opacity_ = !goog.isDef(options.opacity) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.opacity) :
(options.opacity instanceof ol.Expression) ?
options.opacity : new ol.ExpressionLiteral(options.opacity);
new ol.expression.Literal(ol.style.ShapeDefaults.opacity) :
(options.opacity instanceof ol.expression.Expression) ?
options.opacity : new ol.expression.Literal(options.opacity);
};
@@ -181,22 +183,22 @@ ol.style.Shape.prototype.createLiteral = function(opt_feature) {
attrs = feature.getAttributes();
}
var size = this.size_.evaluate(feature, attrs);
var size = this.size_.evaluate(attrs, null, feature);
goog.asserts.assertNumber(size, 'size must be a number');
var fillColor = goog.isNull(this.fillColor_) ?
undefined :
/** @type {string} */ (this.fillColor_.evaluate(feature, attrs));
/** @type {string} */ (this.fillColor_.evaluate(attrs, null, feature));
goog.asserts.assert(!goog.isDef(fillColor) || goog.isString(fillColor));
var strokeColor = goog.isNull(this.strokeColor_) ?
undefined :
/** @type {string} */ (this.strokeColor_.evaluate(feature, attrs));
/** @type {string} */ (this.strokeColor_.evaluate(attrs, null, feature));
goog.asserts.assert(!goog.isDef(strokeColor) || goog.isString(strokeColor));
var strokeWidth = goog.isNull(this.strokeWidth_) ?
undefined :
/** @type {number} */ (this.strokeWidth_.evaluate(feature, attrs));
/** @type {number} */ (this.strokeWidth_.evaluate(attrs, null, feature));
goog.asserts.assert(!goog.isDef(strokeWidth) || goog.isNumber(strokeWidth));
goog.asserts.assert(
@@ -204,7 +206,7 @@ ol.style.Shape.prototype.createLiteral = function(opt_feature) {
(goog.isDef(strokeColor) && goog.isDef(strokeWidth)),
'either fill style or strokeColor and strokeWidth must be defined');
var opacity = this.opacity_.evaluate(feature, attrs);
var opacity = this.opacity_.evaluate(attrs, null, feature);
goog.asserts.assertNumber(opacity, 'opacity must be a number');
return new ol.style.ShapeLiteral({