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
+25 -24
View File
@@ -3,8 +3,8 @@ goog.provide('ol.style.IconLiteral');
goog.provide('ol.style.IconType');
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');
@@ -69,47 +69,47 @@ ol.style.Icon = function(options) {
goog.asserts.assert(options.url, 'url must be set');
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.url_ = (options.url instanceof ol.Expression) ?
options.url : new ol.ExpressionLiteral(options.url);
this.url_ = (options.url instanceof ol.expression.Expression) ?
options.url : new ol.expression.Literal(options.url);
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.width_ = !goog.isDef(options.width) ?
null :
(options.width instanceof ol.Expression) ?
options.width : new ol.ExpressionLiteral(options.width);
(options.width instanceof ol.expression.Expression) ?
options.width : new ol.expression.Literal(options.width);
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.height_ = !goog.isDef(options.height) ?
null :
(options.height instanceof ol.Expression) ?
options.height : new ol.ExpressionLiteral(options.height);
(options.height instanceof ol.expression.Expression) ?
options.height : new ol.expression.Literal(options.height);
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.opacity_ = !goog.isDef(options.opacity) ?
new ol.ExpressionLiteral(ol.style.IconDefaults.opacity) :
(options.opacity instanceof ol.Expression) ?
options.opacity : new ol.ExpressionLiteral(options.opacity);
new ol.expression.Literal(ol.style.IconDefaults.opacity) :
(options.opacity instanceof ol.expression.Expression) ?
options.opacity : new ol.expression.Literal(options.opacity);
/**
* @type {ol.Expression}
* @type {ol.expression.Expression}
* @private
*/
this.rotation_ = !goog.isDef(options.rotation) ?
new ol.ExpressionLiteral(ol.style.IconDefaults.rotation) :
(options.rotation instanceof ol.Expression) ?
options.rotation : new ol.ExpressionLiteral(options.rotation);
new ol.expression.Literal(ol.style.IconDefaults.rotation) :
(options.rotation instanceof ol.expression.Expression) ?
options.rotation : new ol.expression.Literal(options.rotation);
};
@@ -121,24 +121,25 @@ ol.style.Icon = function(options) {
ol.style.Icon.prototype.createLiteral = function(feature) {
var attrs = feature && feature.getAttributes();
var url = /** @type {string} */ (this.url_.evaluate(feature, attrs));
var url = /** @type {string} */ (this.url_.evaluate(attrs, null, feature));
goog.asserts.assert(goog.isString(url) && url != '#', 'url must be a string');
var width = /** @type {number|undefined} */ (goog.isNull(this.width_) ?
undefined : this.width_.evaluate(feature, attrs));
undefined : this.width_.evaluate(attrs, null, feature));
goog.asserts.assert(!goog.isDef(width) || goog.isNumber(width),
'width must be undefined or a number');
var height = /** @type {number|undefined} */ (goog.isNull(this.height_) ?
undefined : this.height_.evaluate(feature, attrs));
undefined : this.height_.evaluate(attrs, null, feature));
goog.asserts.assert(!goog.isDef(height) || goog.isNumber(height),
'height must be undefined or a number');
var opacity = /** {@type {number} */ (this.opacity_.evaluate(feature, attrs));
var opacity = /** {@type {number} */ (this.opacity_.evaluate(attrs, null,
feature));
goog.asserts.assertNumber(opacity, 'opacity must be a number');
var rotation =
/** {@type {number} */ (this.rotation_.evaluate(feature, attrs));
/** {@type {number} */ (this.rotation_.evaluate(attrs, null, feature));
goog.asserts.assertNumber(rotation, 'rotation must be a number');
return new ol.style.IconLiteral({