Using a renderIntent lib function instead of this identifier
A 'this' identifier is quite useless with compressed JavaScript, and in fact it turned out to fail in advanced mode when trying to access a feature's renderIntent property with it. The added renderIntent lib function as a Call expression does the job well.
This commit is contained in:
@@ -25,7 +25,7 @@ var vector = new ol.layer.Vector({
|
|||||||
style: new ol.style.Style({
|
style: new ol.style.Style({
|
||||||
rules: [
|
rules: [
|
||||||
new ol.style.Rule({
|
new ol.style.Rule({
|
||||||
filter: 'this.renderIntent == "selected"',
|
filter: 'renderIntent("selected")',
|
||||||
symbolizers: [
|
symbolizers: [
|
||||||
new ol.style.Fill({
|
new ol.style.Fill({
|
||||||
color: '#ffffff',
|
color: '#ffffff',
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ ol.expr.functions = {
|
|||||||
EXTENT: 'extent',
|
EXTENT: 'extent',
|
||||||
FID: 'fid',
|
FID: 'fid',
|
||||||
GEOMETRY_TYPE: 'geometryType',
|
GEOMETRY_TYPE: 'geometryType',
|
||||||
|
RENDER_INTENT: 'renderIntent',
|
||||||
INTERSECTS: 'intersects',
|
INTERSECTS: 'intersects',
|
||||||
CONTAINS: 'contains',
|
CONTAINS: 'contains',
|
||||||
DWITHIN: 'dwithin',
|
DWITHIN: 'dwithin',
|
||||||
@@ -252,6 +253,17 @@ ol.expr.lib[ol.expr.functions.GEOMETRY_TYPE] = function(type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a feature's renderIntent matches the given one.
|
||||||
|
* @param {string} renderIntent Render intent.
|
||||||
|
* @return {boolean} The feature's renderIntent matches the given one.
|
||||||
|
* @this {ol.Feature}
|
||||||
|
*/
|
||||||
|
ol.expr.lib[ol.expr.functions.RENDER_INTENT] = function(renderIntent) {
|
||||||
|
return this.renderIntent == renderIntent;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ol.expr.lib[ol.expr.functions.INTERSECTS] = function(geom, opt_projection,
|
ol.expr.lib[ol.expr.functions.INTERSECTS] = function(geom, opt_projection,
|
||||||
opt_attribute) {
|
opt_attribute) {
|
||||||
throw new Error('Spatial function not implemented: ' +
|
throw new Error('Spatial function not implemented: ' +
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ goog.provide('ol.expr.Math');
|
|||||||
goog.provide('ol.expr.MathOp');
|
goog.provide('ol.expr.MathOp');
|
||||||
goog.provide('ol.expr.Member');
|
goog.provide('ol.expr.Member');
|
||||||
goog.provide('ol.expr.Not');
|
goog.provide('ol.expr.Not');
|
||||||
goog.provide('ol.expr.ThisIdentifier');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -625,24 +624,3 @@ ol.expr.Not.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
|||||||
ol.expr.Not.prototype.getArgument = function() {
|
ol.expr.Not.prototype.getArgument = function() {
|
||||||
return this.argument_;
|
return this.argument_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An identifier for the 'this' keyword.
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.expr.Expression}
|
|
||||||
*/
|
|
||||||
ol.expr.ThisIdentifier = function() {};
|
|
||||||
goog.inherits(ol.expr.ThisIdentifier, ol.expr.Expression);
|
|
||||||
goog.addSingletonGetter(ol.expr.ThisIdentifier);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.expr.ThisIdentifier.prototype.evaluate =
|
|
||||||
function(opt_scope, opt_fns, opt_this) {
|
|
||||||
return opt_this;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -516,8 +516,7 @@ ol.expr.Lexer.prototype.scanIdentifier_ = function(code) {
|
|||||||
if (id.length === 1) {
|
if (id.length === 1) {
|
||||||
type = ol.expr.TokenType.IDENTIFIER;
|
type = ol.expr.TokenType.IDENTIFIER;
|
||||||
} else if (this.isKeyword_(id)) {
|
} else if (this.isKeyword_(id)) {
|
||||||
type = (id === 'this') ?
|
type = ol.expr.TokenType.KEYWORD;
|
||||||
ol.expr.TokenType.THIS_IDENTIFIER : ol.expr.TokenType.KEYWORD;
|
|
||||||
} else if (id === 'null') {
|
} else if (id === 'null') {
|
||||||
type = ol.expr.TokenType.NULL_LITERAL;
|
type = ol.expr.TokenType.NULL_LITERAL;
|
||||||
} else if (id === 'true' || id === 'false') {
|
} else if (id === 'true' || id === 'false') {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ goog.require('ol.expr.Math');
|
|||||||
goog.require('ol.expr.MathOp');
|
goog.require('ol.expr.MathOp');
|
||||||
goog.require('ol.expr.Member');
|
goog.require('ol.expr.Member');
|
||||||
goog.require('ol.expr.Not');
|
goog.require('ol.expr.Not');
|
||||||
goog.require('ol.expr.ThisIdentifier');
|
|
||||||
goog.require('ol.expr.Token');
|
goog.require('ol.expr.Token');
|
||||||
goog.require('ol.expr.TokenType');
|
goog.require('ol.expr.TokenType');
|
||||||
goog.require('ol.expr.UnexpectedToken');
|
goog.require('ol.expr.UnexpectedToken');
|
||||||
@@ -199,16 +198,6 @@ ol.expr.Parser.prototype.createMemberExpression_ = function(object,
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a 'this' identifier.
|
|
||||||
* @return {ol.expr.ThisIdentifier} The 'this' identifier.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ol.expr.Parser.prototype.createThisIdentifier_ = function() {
|
|
||||||
return ol.expr.ThisIdentifier.getInstance();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a unary expression. The only true unary operator supported here is
|
* Create a unary expression. The only true unary operator supported here is
|
||||||
* "!". For +/-, we apply the operator to literal expressions and return
|
* "!". For +/-, we apply the operator to literal expressions and return
|
||||||
@@ -445,8 +434,6 @@ ol.expr.Parser.prototype.parsePrimaryExpression_ = function(lexer) {
|
|||||||
expr = this.createLiteral_(token.value === 'true');
|
expr = this.createLiteral_(token.value === 'true');
|
||||||
} else if (type === ol.expr.TokenType.NULL_LITERAL) {
|
} else if (type === ol.expr.TokenType.NULL_LITERAL) {
|
||||||
expr = this.createLiteral_(null);
|
expr = this.createLiteral_(null);
|
||||||
} else if (type === ol.expr.TokenType.THIS_IDENTIFIER) {
|
|
||||||
expr = this.createThisIdentifier_();
|
|
||||||
} else {
|
} else {
|
||||||
throw new ol.expr.UnexpectedToken(token);
|
throw new ol.expr.UnexpectedToken(token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,12 +92,6 @@ describe('ol.expr.parse()', function() {
|
|||||||
expect(expr.evaluate(scope)).to.be(42);
|
expect(expr.evaluate(scope)).to.be(42);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parses member expressions in the \'this\' scope', function() {
|
|
||||||
var expr = ol.expr.parse('this.foo');
|
|
||||||
var thisScope = {foo: 'bar'};
|
|
||||||
expect(expr.evaluate(undefined, undefined, thisScope)).to.be('bar');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('consumes whitespace as expected', function() {
|
it('consumes whitespace as expected', function() {
|
||||||
var expr = ol.expr.parse(' foo . bar . baz ');
|
var expr = ol.expr.parse(' foo . bar . baz ');
|
||||||
expect(expr).to.be.a(ol.expr.Member);
|
expect(expr).to.be.a(ol.expr.Member);
|
||||||
@@ -878,6 +872,24 @@ describe('ol.expr.lib', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('renderIntent()', function() {
|
||||||
|
|
||||||
|
var feature = new ol.Feature();
|
||||||
|
feature.renderIntent = 'foo';
|
||||||
|
|
||||||
|
var isFoo = parse('renderIntent("foo")');
|
||||||
|
var isBar = parse('renderIntent("bar")');
|
||||||
|
|
||||||
|
it('True when renderIntent matches', function() {
|
||||||
|
expect(evaluate(isFoo, feature), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('False when renderIntent does not match', function() {
|
||||||
|
expect(evaluate(isBar, feature), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ol.expr.register()', function() {
|
describe('ol.expr.register()', function() {
|
||||||
|
|||||||
@@ -624,25 +624,6 @@ describe('ol.expr.Not', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('ol.expr.ThisIdentifier', function() {
|
|
||||||
|
|
||||||
describe('#getInstance()', function() {
|
|
||||||
it('has a getInstance method to return the singleton', function() {
|
|
||||||
expect(ol.expr.ThisIdentifier.getInstance())
|
|
||||||
.to.be.a(ol.expr.ThisIdentifier);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#evaluate()', function() {
|
|
||||||
it('evaluates to the passed scope', function() {
|
|
||||||
expect(ol.expr.ThisIdentifier.getInstance()
|
|
||||||
.evaluate(undefined, undefined, 'foo')).to.be('foo');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
goog.require('ol.expr.Call');
|
goog.require('ol.expr.Call');
|
||||||
goog.require('ol.expr.Comparison');
|
goog.require('ol.expr.Comparison');
|
||||||
goog.require('ol.expr.ComparisonOp');
|
goog.require('ol.expr.ComparisonOp');
|
||||||
@@ -655,4 +636,3 @@ goog.require('ol.expr.Math');
|
|||||||
goog.require('ol.expr.MathOp');
|
goog.require('ol.expr.MathOp');
|
||||||
goog.require('ol.expr.Member');
|
goog.require('ol.expr.Member');
|
||||||
goog.require('ol.expr.Not');
|
goog.require('ol.expr.Not');
|
||||||
goog.require('ol.expr.ThisIdentifier');
|
|
||||||
|
|||||||
Reference in New Issue
Block a user