From baf817a26596532b3fd2c877653c856647a9c136 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Wed, 13 Feb 2019 14:27:38 +0100 Subject: [PATCH 1/8] Cesium3DTileStyle.style is reactive --- Source/Scene/Cesium3DTileStyle.js | 59 ++++++++++++++++--------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index f6b2ed67949c..c8e4b433992b 100644 --- a/Source/Scene/Cesium3DTileStyle.js +++ b/Source/Scene/Cesium3DTileStyle.js @@ -159,11 +159,14 @@ define([ that._ready = true; } - function getExpression(tileStyle, value) { + function getExpression(tileStyle, value, key) { var defines = defaultValue(tileStyle._style, defaultValue.EMPTY_OBJECT).defines; if (!defined(value)) { + delete tileStyle._style[key]; return undefined; - } else if (typeof value === 'boolean' || typeof value === 'number') { + } + tileStyle._style[key] = value; + if (typeof value === 'boolean' || typeof value === 'number') { return new Expression(String(value)); } else if (typeof value === 'string') { return new Expression(value, defines); @@ -294,7 +297,7 @@ define([ return this._show; }, set : function(value) { - this._show = getExpression(this, value); + this._show = getExpression(this, value, 'show'); this._showShaderFunctionReady = false; } }, @@ -356,7 +359,7 @@ define([ return this._color; }, set : function(value) { - this._color = getExpression(this, value); + this._color = getExpression(this, value, 'color'); this._colorShaderFunctionReady = false; } }, @@ -423,7 +426,7 @@ define([ return this._pointSize; }, set : function(value) { - this._pointSize = getExpression(this, value); + this._pointSize = getExpression(this, value, 'pointSize'); this._pointSizeShaderFunctionReady = false; } }, @@ -472,7 +475,7 @@ define([ return this._pointOutlineColor; }, set : function(value) { - this._pointOutlineColor = getExpression(this, value); + this._pointOutlineColor = getExpression(this, value, 'pointOutlineColor'); } }, @@ -520,7 +523,7 @@ define([ return this._pointOutlineWidth; }, set : function(value) { - this._pointOutlineWidth = getExpression(this, value); + this._pointOutlineWidth = getExpression(this, value, 'pointOutlineWidth'); } }, @@ -568,7 +571,7 @@ define([ return this._labelColor; }, set : function(value) { - this._labelColor = getExpression(this, value); + this._labelColor = getExpression(this, value, 'labelColor'); } }, @@ -616,7 +619,7 @@ define([ return this._labelOutlineColor; }, set : function(value) { - this._labelOutlineColor = getExpression(this, value); + this._labelOutlineColor = getExpression(this, value, 'labelOutlineColor'); } }, @@ -664,7 +667,7 @@ define([ return this._labelOutlineWidth; }, set : function(value) { - this._labelOutlineWidth = getExpression(this, value); + this._labelOutlineWidth = getExpression(this, value, 'labelOutlineWidth'); } }, @@ -712,7 +715,7 @@ define([ return this._font; }, set : function(value) { - this._font = getExpression(this, value); + this._font = getExpression(this, value, 'font'); } }, @@ -760,7 +763,7 @@ define([ return this._labelStyle; }, set : function(value) { - this._labelStyle = getExpression(this, value); + this._labelStyle = getExpression(this, value, 'labelStyle'); } }, @@ -808,7 +811,7 @@ define([ return this._labelText; }, set : function(value) { - this._labelText = getExpression(this, value); + this._labelText = getExpression(this, value, 'labelText'); } }, @@ -856,7 +859,7 @@ define([ return this._backgroundColor; }, set : function(value) { - this._backgroundColor = getExpression(this, value); + this._backgroundColor = getExpression(this, value, 'backgroundColor'); } }, @@ -895,7 +898,7 @@ define([ return this._backgroundPadding; }, set : function(value) { - this._backgroundPadding = getExpression(this, value); + this._backgroundPadding = getExpression(this, value, 'backgroundPadding'); } }, @@ -943,7 +946,7 @@ define([ return this._backgroundEnabled; }, set : function(value) { - this._backgroundEnabled = getExpression(this, value); + this._backgroundEnabled = getExpression(this, value, 'backgroundEnabled'); } }, @@ -982,7 +985,7 @@ define([ return this._scaleByDistance; }, set : function(value) { - this._scaleByDistance = getExpression(this, value); + this._scaleByDistance = getExpression(this, value, 'scaleByDistance'); } }, @@ -1021,7 +1024,7 @@ define([ return this._translucencyByDistance; }, set : function(value) { - this._translucencyByDistance = getExpression(this, value); + this._translucencyByDistance = getExpression(this, value, 'translucencyByDistance'); } }, @@ -1060,7 +1063,7 @@ define([ return this._distanceDisplayCondition; }, set : function(value) { - this._distanceDisplayCondition = getExpression(this, value); + this._distanceDisplayCondition = getExpression(this, value, 'distanceDisplayCondition'); } }, @@ -1108,7 +1111,7 @@ define([ return this._heightOffset; }, set : function(value) { - this._heightOffset = getExpression(this, value); + this._heightOffset = getExpression(this, value, 'heightOffset'); } }, @@ -1156,7 +1159,7 @@ define([ return this._anchorLineEnabled; }, set : function(value) { - this._anchorLineEnabled = getExpression(this, value); + this._anchorLineEnabled = getExpression(this, value, 'anchorLineEnabled'); } }, @@ -1204,7 +1207,7 @@ define([ return this._anchorLineColor; }, set : function(value) { - this._anchorLineColor = getExpression(this, value); + this._anchorLineColor = getExpression(this, value, 'anchorLineColor'); } }, @@ -1252,7 +1255,7 @@ define([ return this._image; }, set : function(value) { - this._image = getExpression(this, value); + this._image = getExpression(this, value, 'image'); } }, @@ -1291,7 +1294,7 @@ define([ return this._disableDepthTestDistance; }, set : function(value) { - this._disableDepthTestDistance = getExpression(this, value); + this._disableDepthTestDistance = getExpression(this, value, 'disableDepthTestDistance'); } }, @@ -1339,7 +1342,7 @@ define([ return this._horizontalOrigin; }, set : function(value) { - this._horizontalOrigin = getExpression(this, value); + this._horizontalOrigin = getExpression(this, value, 'horizontalOrigin'); } }, @@ -1387,7 +1390,7 @@ define([ return this._verticalOrigin; }, set : function(value) { - this._verticalOrigin = getExpression(this, value); + this._verticalOrigin = getExpression(this, value, 'verticalOrigin'); } }, @@ -1435,7 +1438,7 @@ define([ return this._labelHorizontalOrigin; }, set : function(value) { - this._labelHorizontalOrigin = getExpression(this, value); + this._labelHorizontalOrigin = getExpression(this, value, 'labelHorizontalOrigin'); } }, @@ -1483,7 +1486,7 @@ define([ return this._labelVerticalOrigin; }, set : function(value) { - this._labelVerticalOrigin = getExpression(this, value); + this._labelVerticalOrigin = getExpression(this, value, 'labelVerticalOrigin'); } }, From e6f454ec7d06e4a0b45ca151abda9dbc2aed8075 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Feb 2019 14:20:23 +0100 Subject: [PATCH 2/8] handle empty style object --- Source/Scene/Cesium3DTileStyle.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index c8e4b433992b..e55880c6067e 100644 --- a/Source/Scene/Cesium3DTileStyle.js +++ b/Source/Scene/Cesium3DTileStyle.js @@ -161,6 +161,9 @@ define([ function getExpression(tileStyle, value, key) { var defines = defaultValue(tileStyle._style, defaultValue.EMPTY_OBJECT).defines; + if (!defined(tileStyle._style)) { + tileStyle._style = {}; + } if (!defined(value)) { delete tileStyle._style[key]; return undefined; From 3537582ed082b20b8865e480f4460d81aa406f13 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Feb 2019 14:20:47 +0100 Subject: [PATCH 3/8] setting of expressions on the style object --- Source/Scene/Cesium3DTileStyle.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index e55880c6067e..ead6e760f00d 100644 --- a/Source/Scene/Cesium3DTileStyle.js +++ b/Source/Scene/Cesium3DTileStyle.js @@ -167,14 +167,21 @@ define([ if (!defined(value)) { delete tileStyle._style[key]; return undefined; - } - tileStyle._style[key] = value; - if (typeof value === 'boolean' || typeof value === 'number') { + } else if (typeof value === 'boolean' || typeof value === 'number') { + tileStyle._style[key] = value; return new Expression(String(value)); } else if (typeof value === 'string') { + tileStyle._style[key] = value; return new Expression(value, defines); } else if (defined(value.conditions)) { + tileStyle._style[key] = clone(value, true); return new ConditionsExpression(value, defines); + } else if (defined(value.expression)) { + tileStyle._style[key] = value.expression; + return value; + } else if (defined(value.conditionsExpression)) { + tileStyle._style[key] = value.conditionsExpression; + return value; } return value; } From 3771fac51bc0cf4716cd5783bbc28c0bfc999c7a Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Feb 2019 14:20:53 +0100 Subject: [PATCH 4/8] spec update --- Specs/Scene/Cesium3DTileStyleSpec.js | 1022 +++++++++++++++++++++++++- 1 file changed, 1008 insertions(+), 14 deletions(-) diff --git a/Specs/Scene/Cesium3DTileStyleSpec.js b/Specs/Scene/Cesium3DTileStyleSpec.js index 3f477c4255b4..14815732e699 100644 --- a/Specs/Scene/Cesium3DTileStyleSpec.js +++ b/Specs/Scene/Cesium3DTileStyleSpec.js @@ -287,6 +287,28 @@ defineSuite([ expect(style.show).toBeUndefined(); }); + it('sets style.show values in setter', function() { + var style = new Cesium3DTileStyle({}); + style.show = '${height} * ${showFactor} >= 1000'; + expect(style.style.show).toEqual('${height} * ${showFactor} >= 1000'); + + style.show = false; + expect(style.style.show).toEqual(false); + + var jsonExp = { + conditions : [ + ['${height} > ${showFactor}', 'false'], + ['true', 'true'] + ] + }; + + style.show = jsonExp; + expect(style.style.show).toEqual(jsonExp); + + style.show = undefined; + expect(style.style.show).toBeUndefined(); + }); + it('sets color value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.color).toBeUndefined(); @@ -347,6 +369,27 @@ defineSuite([ expect(style.color).toBeUndefined(); }); + it('sets style.color expression in setter', function() { + var style = new Cesium3DTileStyle(); + + var stringExp = 'color("red")'; + style.color = new Expression(stringExp); + expect(style.style.color).toEqual(stringExp); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("blue")'] + ] + }; + + style.color = new ConditionsExpression(jsonExp); + expect(style.style.color).toEqual(jsonExp); + + style.color = undefined; + expect(style.style.color).toBeUndefined(); + }); + it('sets color values in setter', function() { var defines = { 'targetColor': 'red' @@ -367,6 +410,23 @@ defineSuite([ expect(style.color).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.color values in setter', function() { + var style = new Cesium3DTileStyle(); + + style.color = 'color("${targetColor}")'; + expect(style.style.color).toEqual('color("${targetColor}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("${targetColor}")'] + ] + }; + + style.color = jsonExp; + expect(style.style.color).toEqual(jsonExp); + }); + it('sets pointSize value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.pointSize).toBeUndefined(); @@ -430,6 +490,25 @@ defineSuite([ expect(style.pointSize).toBeUndefined(); }); + it('sets style.pointSize expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.pointSize = new Expression('2'); + expect(style.style.pointSize).toEqual('2'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '2.0'] + ] + }; + style.pointSize = new ConditionsExpression(jsonExp); + expect(style.style.pointSize).toEqual(jsonExp); + + style.pointSize = undefined; + expect(style.style.pointSize).toBeUndefined(); + }); + it('sets pointSize values in setter', function() { var defines = { 'targetPointSize': '2.0' @@ -453,6 +532,29 @@ defineSuite([ expect(style.pointSize).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.pointSize values in setter', function() { + var defines = { + 'targetPointSize': '2.0' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.pointSize = 2; + expect(style.style.pointSize).toEqual(2); + + style.pointSize = '${targetPointSize} + 1.0'; + expect(style.style.pointSize).toEqual('${targetPointSize} + 1.0'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '${targetPointSize}'] + ] + }; + + style.pointSize = jsonExp; + expect(style.style.pointSize).toEqual(jsonExp); + }); + it('sets pointOutlineColor value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.pointOutlineColor).toBeUndefined(); @@ -513,6 +615,26 @@ defineSuite([ expect(style.pointOutlineColor).toBeUndefined(); }); + it('sets style.pointOutlineColor expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.pointOutlineColor = new Expression('color("red")'); + expect(style.style.pointOutlineColor).toEqual('color("red")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("blue")'] + ] + }; + + style.pointOutlineColor = new ConditionsExpression(jsonExp); + expect(style.style.pointOutlineColor).toEqual(jsonExp); + + style.pointOutlineColor = undefined; + expect(style.style.pointOutlineColor).toBeUndefined(); + }); + it('sets pointOutlineColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -533,6 +655,26 @@ defineSuite([ expect(style.pointOutlineColor).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.pointOutlineColor values in setter', function() { + var defines = { + 'targetColor': 'red' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.pointOutlineColor = 'color("${targetColor}")'; + expect(style.style.pointOutlineColor).toEqual('color("${targetColor}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("${targetColor}")'] + ] + }; + + style.pointOutlineColor = jsonExp; + expect(style.style.pointOutlineColor).toEqual(jsonExp); + }); + it('sets pointOutlineWidth value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.pointOutlineWidth).toBeUndefined(); @@ -596,6 +738,25 @@ defineSuite([ expect(style.pointOutlineWidth).toBeUndefined(); }); + it('sets style.pointOutlineWidth expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.pointOutlineWidth = new Expression('2'); + expect(style.style.pointOutlineWidth).toEqual('2'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '2.0'] + ] + }; + style.pointOutlineWidth = new ConditionsExpression(jsonExp); + expect(style.style.pointOutlineWidth).toEqual(jsonExp); + + style.pointOutlineWidth = undefined; + expect(style.style.pointOutlineWidth).toBeUndefined(); + }); + it('sets pointOutlineWidth values in setter', function() { var defines = { 'targetPointSize': '2.0' @@ -619,6 +780,29 @@ defineSuite([ expect(style.pointOutlineWidth).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.pointOutlineWidth values in setter', function() { + var defines = { + 'targetPointSize': '2.0' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.pointOutlineWidth = 2; + expect(style.style.pointOutlineWidth).toEqual(2); + + style.pointOutlineWidth = '${targetPointSize} + 1.0'; + expect(style.style.pointOutlineWidth).toEqual('${targetPointSize} + 1.0'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '${targetPointSize}'] + ] + }; + + style.pointOutlineWidth = jsonExp; + expect(style.style.pointOutlineWidth).toEqual(jsonExp); + }); + it('sets labelColor value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.labelColor).toBeUndefined(); @@ -679,6 +863,25 @@ defineSuite([ expect(style.labelColor).toBeUndefined(); }); + it('sets style.labelColor expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelColor = new Expression('color("red")'); + expect(style.style.labelColor).toEqual('color("red")'); + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("blue")'] + ] + }; + + style.labelColor = new ConditionsExpression(jsonExp); + expect(style.style.labelColor).toEqual(jsonExp); + + style.labelColor = undefined; + expect(style.style.labelColor).toBeUndefined(); + }); + it('sets labelColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -699,6 +902,26 @@ defineSuite([ expect(style.labelColor).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelColor values in setter', function() { + var defines = { + 'targetColor': 'red' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelColor = 'color("${targetColor}")'; + expect(style.style.labelColor).toEqual('color("${targetColor}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("${targetColor}")'] + ] + }; + + style.labelColor = jsonExp; + expect(style.style.labelColor).toEqual(jsonExp); + }); + it('sets labelOutlineColor value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.labelOutlineColor).toBeUndefined(); @@ -759,6 +982,26 @@ defineSuite([ expect(style.labelOutlineColor).toBeUndefined(); }); + it('sets style.labelOutlineColor expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelOutlineColor = new Expression('color("red")'); + expect(style.style.labelOutlineColor).toEqual('color("red")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("blue")'] + ] + }; + + style.labelOutlineColor = new ConditionsExpression(jsonExp); + expect(style.style.labelOutlineColor).toEqual(jsonExp); + + style.labelOutlineColor = undefined; + expect(style.style.labelOutlineColor).toBeUndefined(); + }); + it('sets labelOutlineColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -779,6 +1022,26 @@ defineSuite([ expect(style.labelOutlineColor).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelOutlineColor values in setter', function() { + var defines = { + 'targetColor': 'red' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelOutlineColor = 'color("${targetColor}")'; + expect(style.style.labelOutlineColor).toEqual('color("${targetColor}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("${targetColor}")'] + ] + }; + + style.labelOutlineColor = jsonExp; + expect(style.style.labelOutlineColor).toEqual(jsonExp); + }); + it('sets labelOutlineWidth value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.labelOutlineWidth).toBeUndefined(); @@ -842,6 +1105,24 @@ defineSuite([ expect(style.labelOutlineWidth).toBeUndefined(); }); + it('sets style.labelOutlineWidth expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelOutlineWidth = new Expression('2'); + expect(style.style.labelOutlineWidth).toEqual('2'); + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '2.0'] + ] + }; + style.labelOutlineWidth = new ConditionsExpression(jsonExp); + expect(style.style.labelOutlineWidth).toEqual(jsonExp); + + style.labelOutlineWidth = undefined; + expect(style.style.labelOutlineWidth).toBeUndefined(); + }); + it('sets labelOutlineWidth values in setter', function() { var defines = { 'targetLabelSize': '2.0' @@ -865,6 +1146,29 @@ defineSuite([ expect(style.labelOutlineWidth).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelOutlineWidth values in setter', function() { + var defines = { + 'targetLabelSize': '2.0' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelOutlineWidth = 2; + expect(style.style.labelOutlineWidth).toEqual(2); + + style.labelOutlineWidth = '${targetLabelSize} + 1.0'; + expect(style.style.labelOutlineWidth).toEqual('${targetLabelSize} + 1.0'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '${targetLabelSize}'] + ] + }; + + style.labelOutlineWidth = jsonExp; + expect(style.style.labelOutlineWidth).toEqual(jsonExp); + }); + it('sets font value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.font).toBeUndefined(); @@ -928,6 +1232,26 @@ defineSuite([ expect(style.font).toBeUndefined(); }); + it('sets style.font expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.font = new Expression('\'24px Helvetica\''); + expect(style.style.font).toEqual('\'24px Helvetica\''); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'30px Helvetica\''], + ['true', '\'24px Helvetica\''] + ] + }; + + style.font = new ConditionsExpression(jsonExp); + expect(style.style.font).toEqual(jsonExp); + + style.font = undefined; + expect(style.style.font).toBeUndefined(); + }); + it('sets font values in setter', function() { var defines = { 'targetFont': '\'30px Helvetica\'' @@ -951,13 +1275,36 @@ defineSuite([ expect(style.font).toEqual(new ConditionsExpression(jsonExp, defines)); }); - it('sets labelStyle value to undefined if value not present', function() { - var style = new Cesium3DTileStyle({}); - expect(style.labelStyle).toBeUndefined(); + it('sets style.font values in setter', function() { + var defines = { + 'targetFont': '\'30px Helvetica\'' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); - style = new Cesium3DTileStyle(); - expect(style.labelStyle).toBeUndefined(); - }); + style.font = '\'24px Helvetica\''; + expect(style.style.font).toEqual('\'24px Helvetica\''); + + style.font = '${targetFont}'; + expect(style.style.font).toEqual('${targetFont}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'24px Helvetica\''], + ['true', '${targetFont}'] + ] + }; + + style.font = jsonExp; + expect(style.style.font).toEqual(jsonExp); + }); + + it('sets labelStyle value to undefined if value not present', function() { + var style = new Cesium3DTileStyle({}); + expect(style.labelStyle).toBeUndefined(); + + style = new Cesium3DTileStyle(); + expect(style.labelStyle).toBeUndefined(); + }); it('sets labelStyle value to expression', function() { var style = new Cesium3DTileStyle({ @@ -1004,6 +1351,25 @@ defineSuite([ expect(style.labelStyle).toBeUndefined(); }); + it('sets style.labelStyle expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelStyle = new Expression('2'); + expect(style.style.labelStyle).toEqual('2'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '2'] + ] + }; + style.labelStyle = new ConditionsExpression(jsonExp); + expect(style.style.labelStyle).toEqual(jsonExp); + + style.labelStyle = undefined; + expect(style.style.labelStyle).toBeUndefined(); + }); + it('sets labelStyle values in setter', function() { var defines = { 'targetLabelStyle': '2' @@ -1027,6 +1393,29 @@ defineSuite([ expect(style.labelStyle).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelStyle values in setter', function() { + var defines = { + 'targetLabelStyle': '2' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelStyle = 2; + expect(style.style.labelStyle).toEqual(2); + + style.labelStyle = '${targetLabelStyle}'; + expect(style.style.labelStyle).toEqual('${targetLabelStyle}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '${targetLabelStyle}'] + ] + }; + + style.labelStyle = jsonExp; + expect(style.style.labelStyle).toEqual(jsonExp); + }); + it('sets labelText value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.labelText).toBeUndefined(); @@ -1090,6 +1479,26 @@ defineSuite([ expect(style.labelText).toBeUndefined(); }); + it('sets style.labelText expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelText = new Expression('\'test text\''); + expect(style.style.labelText).toEqual('\'test text\''); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'test text 1\''], + ['true', '\'test text 2\''] + ] + }; + + style.labelText = new ConditionsExpression(jsonExp); + expect(style.style.labelText).toEqual(jsonExp); + + style.labelText = undefined; + expect(style.style.labelText).toBeUndefined(); + }); + it('sets labelText values in setter', function() { var defines = { 'targetText': '\'test text 1\'' @@ -1113,6 +1522,29 @@ defineSuite([ expect(style.labelText).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelText values in setter', function() { + var defines = { + 'targetText': '\'test text 1\'' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelText = '\'test text\''; + expect(style.style.labelText).toEqual('\'test text\''); + + style.labelText = '${targetText}'; + expect(style.style.labelText).toEqual('${targetText}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'test text 2\''], + ['true', '${targetText}'] + ] + }; + + style.labelText = jsonExp; + expect(style.style.labelText).toEqual(jsonExp); + }); + it('sets backgroundColor value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.backgroundColor).toBeUndefined(); @@ -1173,6 +1605,26 @@ defineSuite([ expect(style.backgroundColor).toBeUndefined(); }); + it('sets style.backgroundColor expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.backgroundColor = new Expression('color("red")'); + expect(style.style.backgroundColor).toEqual('color("red")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("blue")'] + ] + }; + + style.backgroundColor = new ConditionsExpression(jsonExp); + expect(style.style.backgroundColor).toEqual(jsonExp); + + style.backgroundColor = undefined; + expect(style.style.backgroundColor).toBeUndefined(); + }); + it('sets backgroundColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -1193,6 +1645,26 @@ defineSuite([ expect(style.backgroundColor).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.backgroundColor values in setter', function() { + var defines = { + 'targetColor': 'red' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.backgroundColor = 'color("${targetColor}")'; + expect(style.style.backgroundColor).toEqual('color("${targetColor}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("${targetColor}")'] + ] + }; + + style.backgroundColor = jsonExp; + expect(style.style.backgroundColor).toEqual(jsonExp); + }); + it('sets backgroundPadding value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.backgroundPadding).toBeUndefined(); @@ -1253,6 +1725,26 @@ defineSuite([ expect(style.backgroundPadding).toBeUndefined(); }); + it('sets style.backgroundPadding expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.backgroundPadding = new Expression('vec2(1.0, 2.0)'); + expect(style.style.backgroundPadding).toEqual('vec2(1.0, 2.0)'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'vec2(1.0, 2.0)'], + ['true', 'vec2(3.0, 4.0)'] + ] + }; + + style.backgroundPadding = new ConditionsExpression(jsonExp); + expect(style.style.backgroundPadding).toEqual(jsonExp); + + style.backgroundPadding = undefined; + expect(style.style.backgroundPadding).toBeUndefined(); + }); + it('sets backgroundPadding values in setter', function() { var defines = { 'targetPadding': '3.0, 4.0' @@ -1273,6 +1765,26 @@ defineSuite([ expect(style.backgroundPadding).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.backgroundPadding values in setter', function() { + var defines = { + 'targetPadding': '3.0, 4.0' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.backgroundPadding = 'vec2("${targetPadding}")'; + expect(style.style.backgroundPadding).toEqual('vec2("${targetPadding}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'vec2(1.0, 2.0)'], + ['true', 'vec2("${targetPadding}")'] + ] + }; + + style.backgroundPadding = jsonExp; + expect(style.style.backgroundPadding).toEqual(jsonExp); + }); + it('sets backgroundEnabled value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.backgroundEnabled).toBeUndefined(); @@ -1340,6 +1852,23 @@ defineSuite([ expect(style.backgroundEnabled).toEqual(exp); }); + it('sets style.backgroundEnabled expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.backgroundEnabled = new Expression('false'); + expect(style.style.backgroundEnabled).toEqual('false'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'false'], + ['true', 'true'] + ] + }; + + style.backgroundEnabled = new ConditionsExpression(jsonExp); + expect(style.style.backgroundEnabled).toEqual(jsonExp); + }); + it('sets backgroundEnabled values in setter', function() { var defines = { 'backgroundFactor': 10 @@ -1366,6 +1895,32 @@ defineSuite([ expect(style.backgroundEnabled).toBeUndefined(); }); + it('sets style.backgroundEnabled values in setter', function() { + var defines = { + 'backgroundFactor': 10 + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.backgroundEnabled = '${height} * ${backgroundFactor} >= 1000'; + expect(style.style.backgroundEnabled).toEqual('${height} * ${backgroundFactor} >= 1000'); + + style.backgroundEnabled = false; + expect(style.style.backgroundEnabled).toEqual(false); + + var jsonExp = { + conditions : [ + ['${height} > ${backgroundFactor}', 'false'], + ['true', 'true'] + ] + }; + + style.backgroundEnabled = jsonExp; + expect(style.style.backgroundEnabled).toEqual(jsonExp); + + style.backgroundEnabled = undefined; + expect(style.style.backgroundEnabled).toBeUndefined(); + }); + it('sets scaleByDistance value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.scaleByDistance).toBeUndefined(); @@ -1426,6 +1981,26 @@ defineSuite([ expect(style.scaleByDistance).toBeUndefined(); }); + it('sets style.scaleByDistance expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.scaleByDistance = new Expression('vec4(5.0, 6.0, 7.0, 8.0)'); + expect(style.style.scaleByDistance).toEqual('vec4(5.0, 6.0, 7.0, 8.0)'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'vec4(1.0, 2.0, 3.0, 4.0)'], + ['true', 'vec4(5.0, 6.0, 7.0, 8.0)'] + ] + }; + + style.scaleByDistance = new ConditionsExpression(jsonExp); + expect(style.style.scaleByDistance).toEqual(jsonExp); + + style.scaleByDistance = undefined; + expect(style.style.scaleByDistance).toBeUndefined(); + }); + it('sets scaleByDistance values in setter', function() { var defines = { 'targetScale': '1.0, 2.0, 3.0, 4.' @@ -1446,6 +2021,26 @@ defineSuite([ expect(style.scaleByDistance).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.scaleByDistance values in setter', function() { + var defines = { + 'targetScale': '1.0, 2.0, 3.0, 4.' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.scaleByDistance = 'vec4("${targetScale}")'; + expect(style.style.scaleByDistance).toEqual('vec4("${targetScale}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'vec4(5.0, 6.0, 7.0, 8.0)'], + ['true', 'vec4("${targetScale}")'] + ] + }; + + style.scaleByDistance = jsonExp; + expect(style.style.scaleByDistance).toEqual(jsonExp); + }); + it('sets distanceDisplayCondition value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.distanceDisplayCondition).toBeUndefined(); @@ -1506,6 +2101,26 @@ defineSuite([ expect(style.distanceDisplayCondition).toBeUndefined(); }); + it('sets style.distanceDisplayCondition expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.distanceDisplayCondition = new Expression('vec4(5.0, 6.0, 7.0, 8.0)'); + expect(style.style.distanceDisplayCondition).toEqual('vec4(5.0, 6.0, 7.0, 8.0)'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'vec4(1.0, 2.0, 3.0, 4.0)'], + ['true', 'vec4(5.0, 6.0, 7.0, 8.0)'] + ] + }; + + style.distanceDisplayCondition = new ConditionsExpression(jsonExp); + expect(style.style.distanceDisplayCondition).toEqual(jsonExp); + + style.distanceDisplayCondition = undefined; + expect(style.style.distanceDisplayCondition).toBeUndefined(); + }); + it('sets distanceDisplayCondition values in setter', function() { var defines = { 'targetTranslucency': '1.0, 2.0, 3.0, 4.' @@ -1526,6 +2141,26 @@ defineSuite([ expect(style.distanceDisplayCondition).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.distanceDisplayCondition values in setter', function() { + var defines = { + 'targetTranslucency': '1.0, 2.0, 3.0, 4.' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.distanceDisplayCondition = 'vec4("${targetTranslucency}")'; + expect(style.style.distanceDisplayCondition).toEqual('vec4("${targetTranslucency}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'vec4(5.0, 6.0, 7.0, 8.0)'], + ['true', 'vec4("${targetTranslucency}")'] + ] + }; + + style.distanceDisplayCondition = jsonExp; + expect(style.style.distanceDisplayCondition).toEqual(jsonExp); + }); + it('sets heightOffset value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.heightOffset).toBeUndefined(); @@ -1585,21 +2220,61 @@ defineSuite([ style.heightOffset = condExp; expect(style.heightOffset).toEqual(condExp); - style.heightOffset = undefined; - expect(style.heightOffset).toBeUndefined(); + style.heightOffset = undefined; + expect(style.heightOffset).toBeUndefined(); + }); + + it('sets style.heightOffset expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.heightOffset = new Expression('2'); + expect(style.style.heightOffset).toEqual('2'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '2.0'] + ] + }; + + style.heightOffset = new ConditionsExpression(jsonExp); + expect(style.style.heightOffset).toEqual(jsonExp); + + style.heightOffset = undefined; + expect(style.style.heightOffset).toBeUndefined(); + }); + + it('sets heightOffset values in setter', function() { + var defines = { + 'targetHeight': '2.0' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.heightOffset = 2; + expect(style.heightOffset).toEqual(new Expression('2')); + + style.heightOffset = '${targetHeight} + 1.0'; + expect(style.heightOffset).toEqual(new Expression('${targetHeight} + 1.0', defines)); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '${targetHeight}'] + ] + }; + + style.heightOffset = jsonExp; + expect(style.heightOffset).toEqual(new ConditionsExpression(jsonExp, defines)); }); - it('sets heightOffset values in setter', function() { + it('sets style.heightOffset values in setter', function() { var defines = { 'targetHeight': '2.0' }; var style = new Cesium3DTileStyle({ 'defines': defines }); - style.heightOffset = 2; - expect(style.heightOffset).toEqual(new Expression('2')); - style.heightOffset = '${targetHeight} + 1.0'; - expect(style.heightOffset).toEqual(new Expression('${targetHeight} + 1.0', defines)); + expect(style.style.heightOffset).toEqual('${targetHeight} + 1.0'); var jsonExp = { conditions : [ @@ -1609,7 +2284,7 @@ defineSuite([ }; style.heightOffset = jsonExp; - expect(style.heightOffset).toEqual(new ConditionsExpression(jsonExp, defines)); + expect(style.style.heightOffset).toEqual(jsonExp); }); it('sets anchorLineEnabled value to undefined if value not present', function() { @@ -1679,6 +2354,24 @@ defineSuite([ expect(style.anchorLineEnabled).toEqual(exp); }); + it('sets style.anchorLineEnabled expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.anchorLineEnabled = new Expression('false'); + expect(style.style.anchorLineEnabled).toEqual('false'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'false'], + ['true', 'true'] + ] + }; + + style.anchorLineEnabled = new ConditionsExpression(jsonExp); + expect(style.style.anchorLineEnabled).toEqual(jsonExp); + + }); + it('sets anchorLineEnabled values in setter', function() { var defines = { 'anchorFactor': 10 @@ -1705,6 +2398,32 @@ defineSuite([ expect(style.anchorLineEnabled).toBeUndefined(); }); + it('sets style.anchorLineEnabled values in setter', function() { + var defines = { + 'anchorFactor': 10 + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.anchorLineEnabled = '${height} * ${anchorFactor} >= 1000'; + expect(style.style.anchorLineEnabled).toEqual('${height} * ${anchorFactor} >= 1000'); + + style.anchorLineEnabled = false; + expect(style.style.anchorLineEnabled).toEqual(false); + + var jsonExp = { + conditions : [ + ['${height} > ${anchorFactor}', 'false'], + ['true', 'true'] + ] + }; + + style.anchorLineEnabled = jsonExp; + expect(style.style.anchorLineEnabled).toEqual(jsonExp); + + style.anchorLineEnabled = undefined; + expect(style.style.anchorLineEnabled).toBeUndefined(); + }); + it('sets anchorLineColor value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.anchorLineColor).toBeUndefined(); @@ -1765,6 +2484,26 @@ defineSuite([ expect(style.anchorLineColor).toBeUndefined(); }); + it('sets style.anchorLineColor expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.anchorLineColor = new Expression('color("red")'); + expect(style.style.anchorLineColor).toEqual('color("red")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("blue")'] + ] + }; + + style.anchorLineColor = new ConditionsExpression(jsonExp); + expect(style.style.anchorLineColor).toEqual(jsonExp); + + style.anchorLineColor = undefined; + expect(style.style.anchorLineColor).toBeUndefined(); + }); + it('sets anchorLineColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -1785,6 +2524,26 @@ defineSuite([ expect(style.anchorLineColor).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.anchorLineColor values in setter', function() { + var defines = { + 'targetColor': 'red' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.anchorLineColor = 'color("${targetColor}")'; + expect(style.style.anchorLineColor).toEqual('color("${targetColor}")'); + + var jsonExp = { + conditions : [ + ['${height} > 2', 'color("cyan")'], + ['true', 'color("${targetColor}")'] + ] + }; + + style.anchorLineColor = jsonExp; + expect(style.style.anchorLineColor).toEqual(jsonExp); + }); + it('sets image value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.image).toBeUndefined(); @@ -1848,6 +2607,26 @@ defineSuite([ expect(style.image).toBeUndefined(); }); + it('sets style.image expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.image = new Expression('\'url/to/image\''); + expect(style.style.image).toEqual('\'url/to/image\''); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'url/to/image1\''], + ['true', '\'url/to/image2\''] + ] + }; + + style.image = new ConditionsExpression(jsonExp); + expect(style.style.image).toEqual(jsonExp); + + style.image = undefined; + expect(style.style.image).toBeUndefined(); + }); + it('sets image values in setter', function() { var defines = { 'targetUrl': '\'url/to/image1\'' @@ -1871,6 +2650,29 @@ defineSuite([ expect(style.image).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.image values in setter', function() { + var defines = { + 'targetUrl': '\'url/to/image1\'' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.image = '\'url/to/image\''; + expect(style.style.image).toEqual('\'url/to/image\''); + + style.image = '${targetUrl}'; + expect(style.style.image).toEqual('${targetUrl}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'url/to/image2\''], + ['true', '${targetUrl}'] + ] + }; + + style.image = jsonExp; + expect(style.style.image).toEqual(jsonExp); + }); + it('sets disableDepthTestDistance value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.disableDepthTestDistance).toBeUndefined(); @@ -1934,6 +2736,26 @@ defineSuite([ expect(style.disableDepthTestDistance).toBeUndefined(); }); + it('sets style.disableDepthTestDistance expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.disableDepthTestDistance = new Expression('2'); + expect(style.style.disableDepthTestDistance).toEqual('2'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '2.0'] + ] + }; + + style.disableDepthTestDistance = new ConditionsExpression(jsonExp); + expect(style.style.disableDepthTestDistance).toEqual(jsonExp); + + style.disableDepthTestDistance = undefined; + expect(style.style.disableDepthTestDistance).toBeUndefined(); + }); + it('sets disableDepthTestDistance values in setter', function() { var defines = { 'targetDistance': '2.0' @@ -2010,6 +2832,26 @@ defineSuite([ expect(style.horizontalOrigin).toBeUndefined(); }); + it('sets style.horizontalOrigin expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.horizontalOrigin = new Expression('1'); + expect(style.style.horizontalOrigin).toEqual('1'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '-1'] + ] + }; + + style.horizontalOrigin = new ConditionsExpression(jsonExp); + expect(style.style.horizontalOrigin).toEqual(jsonExp); + + style.horizontalOrigin = undefined; + expect(style.style.horizontalOrigin).toBeUndefined(); + }); + it('sets horizontalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2033,6 +2875,29 @@ defineSuite([ expect(style.horizontalOrigin).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.horizontalOrigin values in setter', function() { + var defines = { + 'targetOrigin': '-1' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.horizontalOrigin = -1; + expect(style.style.horizontalOrigin).toEqual(-1); + + style.horizontalOrigin = '${targetOrigin}'; + expect(style.style.horizontalOrigin).toEqual('${targetOrigin}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '${targetOrigin}'] + ] + }; + + style.horizontalOrigin = jsonExp; + expect(style.style.horizontalOrigin).toEqual(jsonExp); + }); + it('sets verticalOrigin value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.verticalOrigin).toBeUndefined(); @@ -2086,6 +2951,26 @@ defineSuite([ expect(style.verticalOrigin).toBeUndefined(); }); + it('sets style.styleverticalOrigin expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.verticalOrigin = new Expression('1'); + expect(style.style.verticalOrigin).toEqual('1'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '-1'] + ] + }; + + style.verticalOrigin = new ConditionsExpression(jsonExp); + expect(style.style.verticalOrigin).toEqual(jsonExp); + + style.verticalOrigin = undefined; + expect(style.style.verticalOrigin).toBeUndefined(); + }); + it('sets verticalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2109,6 +2994,29 @@ defineSuite([ expect(style.verticalOrigin).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.verticalOrigin values in setter', function() { + var defines = { + 'targetOrigin': '-1' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.verticalOrigin = -1; + expect(style.style.verticalOrigin).toEqual(-1); + + style.verticalOrigin = '${targetOrigin}'; + expect(style.style.verticalOrigin).toEqual('${targetOrigin}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '${targetOrigin}'] + ] + }; + + style.verticalOrigin = jsonExp; + expect(style.style.verticalOrigin).toEqual(jsonExp); + }); + it('sets labelHorizontalOrigin value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.labelHorizontalOrigin).toBeUndefined(); @@ -2162,6 +3070,26 @@ defineSuite([ expect(style.labelHorizontalOrigin).toBeUndefined(); }); + it('sets style.labelHorizontalOrigin expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelHorizontalOrigin = new Expression('1'); + expect(style.style.labelHorizontalOrigin).toEqual('1'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '-1'] + ] + }; + + style.labelHorizontalOrigin = new ConditionsExpression(jsonExp); + expect(style.style.labelHorizontalOrigin).toEqual(jsonExp); + + style.labelHorizontalOrigin = undefined; + expect(style.style.labelHorizontalOrigin).toBeUndefined(); + }); + it('sets labelHorizontalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2185,6 +3113,29 @@ defineSuite([ expect(style.labelHorizontalOrigin).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelHorizontalOrigin values in setter', function() { + var defines = { + 'targetOrigin': '-1' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelHorizontalOrigin = -1; + expect(style.style.labelHorizontalOrigin).toEqual(-1); + + style.labelHorizontalOrigin = '${targetOrigin}'; + expect(style.style.labelHorizontalOrigin).toEqual('${targetOrigin}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '${targetOrigin}'] + ] + }; + + style.labelHorizontalOrigin = jsonExp; + expect(style.style.labelHorizontalOrigin).toEqual(jsonExp); + }); + it('sets labelVerticalOrigin value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.labelVerticalOrigin).toBeUndefined(); @@ -2238,6 +3189,26 @@ defineSuite([ expect(style.labelVerticalOrigin).toBeUndefined(); }); + it('sets style.labelVerticalOrigin expressions in setter', function() { + var style = new Cesium3DTileStyle(); + + style.labelVerticalOrigin = new Expression('1'); + expect(style.style.labelVerticalOrigin).toEqual('1'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '-1'] + ] + }; + + style.labelVerticalOrigin = new ConditionsExpression(jsonExp); + expect(style.style.labelVerticalOrigin).toEqual(jsonExp); + + style.labelVerticalOrigin = undefined; + expect(style.style.labelVerticalOrigin).toBeUndefined(); + }); + it('sets labelVerticalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2261,6 +3232,29 @@ defineSuite([ expect(style.labelVerticalOrigin).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.labelVerticalOrigin values in setter', function() { + var defines = { + 'targetOrigin': '-1' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.labelVerticalOrigin = -1; + expect(style.style.labelVerticalOrigin).toEqual(-1); + + style.labelVerticalOrigin = '${targetOrigin}'; + expect(style.style.labelVerticalOrigin).toEqual('${targetOrigin}'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1'], + ['true', '${targetOrigin}'] + ] + }; + + style.labelVerticalOrigin = jsonExp; + expect(style.style.labelVerticalOrigin).toEqual(jsonExp); + }); + it('throws on accessing style if not ready', function() { var style = new Cesium3DTileStyle({}); style._ready = false; From b3f8915cd30f417327ce93e5e50e58f947adf257 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Feb 2019 14:27:37 +0100 Subject: [PATCH 5/8] CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 0bdb0ce31a75..a3a5e140f84e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Change Log ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). +* `Cesium3DTileStyle.style` reacts to updates and represents the current state of the style. [#7567](https://github.com/AnalyticalGraphicsInc/cesium/issues/7567) ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) From 6b576b133ed46aa637231334f195e355d2d3945e Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Thu, 21 Mar 2019 19:03:21 +0100 Subject: [PATCH 6/8] .style update refactor --- CHANGES.md | 1 + Source/Scene/Cesium3DTileStyle.js | 114 ++++++++++++++++----------- Specs/Scene/Cesium3DTileStyleSpec.js | 22 +++--- 3 files changed, 81 insertions(+), 56 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a3342fa2beb2..18f452e0fa35 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log ##### Breaking Changes :mega: * `Resource.fetchImage` now returns an `ImageBitmap` instead of `Image` when supported. This allows for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) +* `Cesium3DTileStyle.style` now has an empty `Object` as its default value, instead of `undefined`. [#7567](https://github.com/AnalyticalGraphicsInc/cesium/issues/7567) ##### Deprecated :hourglass_flowing_sand: * `Resource.fetchImage` now takes an options object. Use `resource.fetchImage({ preferBlob: true })` instead of `resource.fetchImage(true)`. The previous function definition will no longer work in 1.57. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index ead6e760f00d..521ca44372f1 100644 --- a/Source/Scene/Cesium3DTileStyle.js +++ b/Source/Scene/Cesium3DTileStyle.js @@ -56,7 +56,7 @@ define([ * @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/Styling|3D Tiles Styling language} */ function Cesium3DTileStyle(style) { - this._style = undefined; + this._style = {}; this._ready = false; this._show = undefined; @@ -112,9 +112,8 @@ define([ } function setup(that, styleJson) { - that._style = clone(styleJson, true); - - styleJson = defaultValue(styleJson, defaultValue.EMPTY_OBJECT); + styleJson = defaultValue(clone(styleJson, true), that._style); + that._style = styleJson; that.show = styleJson.show; that.color = styleJson.color; @@ -159,33 +158,32 @@ define([ that._ready = true; } - function getExpression(tileStyle, value, key) { + function getExpression(tileStyle, value) { var defines = defaultValue(tileStyle._style, defaultValue.EMPTY_OBJECT).defines; - if (!defined(tileStyle._style)) { - tileStyle._style = {}; - } + if (!defined(value)) { - delete tileStyle._style[key]; return undefined; } else if (typeof value === 'boolean' || typeof value === 'number') { - tileStyle._style[key] = value; return new Expression(String(value)); } else if (typeof value === 'string') { - tileStyle._style[key] = value; return new Expression(value, defines); } else if (defined(value.conditions)) { - tileStyle._style[key] = clone(value, true); return new ConditionsExpression(value, defines); - } else if (defined(value.expression)) { - tileStyle._style[key] = value.expression; - return value; - } else if (defined(value.conditionsExpression)) { - tileStyle._style[key] = value.conditionsExpression; - return value; } return value; } + function getJsonFromExpression(expression) { + if (!defined(expression)) { + return undefined; + } else if (defined(expression.expression)) { + return expression.expression; + } else if (defined(expression.conditionsExpression)) { + return clone(expression.conditionsExpression, true); + } + return undefined; + } + defineProperties(Cesium3DTileStyle.prototype, { /** * Gets the object defining the style using the @@ -196,7 +194,7 @@ define([ * @type {Object} * @readonly * - * @default undefined + * @default {} * * @exception {DeveloperError} The style is not loaded. Use Cesium3DTileStyle.readyPromise or wait for Cesium3DTileStyle.ready to be true. */ @@ -307,7 +305,8 @@ define([ return this._show; }, set : function(value) { - this._show = getExpression(this, value, 'show'); + this._show = getExpression(this, value); + this._style.show = getJsonFromExpression(this._show); this._showShaderFunctionReady = false; } }, @@ -369,7 +368,8 @@ define([ return this._color; }, set : function(value) { - this._color = getExpression(this, value, 'color'); + this._color = getExpression(this, value); + this._style.color = getJsonFromExpression(this._color); this._colorShaderFunctionReady = false; } }, @@ -436,7 +436,8 @@ define([ return this._pointSize; }, set : function(value) { - this._pointSize = getExpression(this, value, 'pointSize'); + this._pointSize = getExpression(this, value); + this._style.pointSize = getJsonFromExpression(this._pointSize); this._pointSizeShaderFunctionReady = false; } }, @@ -485,7 +486,8 @@ define([ return this._pointOutlineColor; }, set : function(value) { - this._pointOutlineColor = getExpression(this, value, 'pointOutlineColor'); + this._pointOutlineColor = getExpression(this, value); + this._style.pointOutlineColor = getJsonFromExpression(this._pointOutlineColor); } }, @@ -533,7 +535,8 @@ define([ return this._pointOutlineWidth; }, set : function(value) { - this._pointOutlineWidth = getExpression(this, value, 'pointOutlineWidth'); + this._pointOutlineWidth = getExpression(this, value); + this._style.pointOutlineWidth = getJsonFromExpression(this._pointOutlineWidth); } }, @@ -581,7 +584,8 @@ define([ return this._labelColor; }, set : function(value) { - this._labelColor = getExpression(this, value, 'labelColor'); + this._labelColor = getExpression(this, value); + this._style.labelColor = getJsonFromExpression(this._labelColor); } }, @@ -629,7 +633,8 @@ define([ return this._labelOutlineColor; }, set : function(value) { - this._labelOutlineColor = getExpression(this, value, 'labelOutlineColor'); + this._labelOutlineColor = getExpression(this, value); + this._style.labelOutlineColor = getJsonFromExpression(this._labelOutlineColor); } }, @@ -677,7 +682,8 @@ define([ return this._labelOutlineWidth; }, set : function(value) { - this._labelOutlineWidth = getExpression(this, value, 'labelOutlineWidth'); + this._labelOutlineWidth = getExpression(this, value); + this._style.labelOutlineWidth = getJsonFromExpression(this._labelOutlineWidth); } }, @@ -725,7 +731,8 @@ define([ return this._font; }, set : function(value) { - this._font = getExpression(this, value, 'font'); + this._font = getExpression(this, value); + this._style.font = getJsonFromExpression(this._font); } }, @@ -773,7 +780,8 @@ define([ return this._labelStyle; }, set : function(value) { - this._labelStyle = getExpression(this, value, 'labelStyle'); + this._labelStyle = getExpression(this, value); + this._style.labelStyle = getJsonFromExpression(this._labelStyle); } }, @@ -821,7 +829,8 @@ define([ return this._labelText; }, set : function(value) { - this._labelText = getExpression(this, value, 'labelText'); + this._labelText = getExpression(this, value); + this._style.labelText = getJsonFromExpression(this._labelText); } }, @@ -869,7 +878,8 @@ define([ return this._backgroundColor; }, set : function(value) { - this._backgroundColor = getExpression(this, value, 'backgroundColor'); + this._backgroundColor = getExpression(this, value); + this._style.backgroundColor = getJsonFromExpression(this._backgroundColor); } }, @@ -908,7 +918,8 @@ define([ return this._backgroundPadding; }, set : function(value) { - this._backgroundPadding = getExpression(this, value, 'backgroundPadding'); + this._backgroundPadding = getExpression(this, value); + this._style.backgroundPadding = getJsonFromExpression(this._backgroundPadding); } }, @@ -956,7 +967,8 @@ define([ return this._backgroundEnabled; }, set : function(value) { - this._backgroundEnabled = getExpression(this, value, 'backgroundEnabled'); + this._backgroundEnabled = getExpression(this, value); + this._style.backgroundEnabled = getJsonFromExpression(this._backgroundEnabled); } }, @@ -995,7 +1007,8 @@ define([ return this._scaleByDistance; }, set : function(value) { - this._scaleByDistance = getExpression(this, value, 'scaleByDistance'); + this._scaleByDistance = getExpression(this, value); + this._style.scaleByDistance = getJsonFromExpression(this._scaleByDistance); } }, @@ -1034,7 +1047,8 @@ define([ return this._translucencyByDistance; }, set : function(value) { - this._translucencyByDistance = getExpression(this, value, 'translucencyByDistance'); + this._translucencyByDistance = getExpression(this, value); + this._style.translucencyByDistance = getJsonFromExpression(this._translucencyByDistance); } }, @@ -1073,7 +1087,8 @@ define([ return this._distanceDisplayCondition; }, set : function(value) { - this._distanceDisplayCondition = getExpression(this, value, 'distanceDisplayCondition'); + this._distanceDisplayCondition = getExpression(this, value); + this._style.distanceDisplayCondition = getJsonFromExpression(this._distanceDisplayCondition); } }, @@ -1121,7 +1136,8 @@ define([ return this._heightOffset; }, set : function(value) { - this._heightOffset = getExpression(this, value, 'heightOffset'); + this._heightOffset = getExpression(this, value); + this._style.heightOffset = getJsonFromExpression(this._heightOffset); } }, @@ -1169,7 +1185,8 @@ define([ return this._anchorLineEnabled; }, set : function(value) { - this._anchorLineEnabled = getExpression(this, value, 'anchorLineEnabled'); + this._anchorLineEnabled = getExpression(this, value); + this._style.anchorLineEnabled = getJsonFromExpression(this._anchorLineEnabled); } }, @@ -1217,7 +1234,8 @@ define([ return this._anchorLineColor; }, set : function(value) { - this._anchorLineColor = getExpression(this, value, 'anchorLineColor'); + this._anchorLineColor = getExpression(this, value); + this._style.anchorLineColor = getJsonFromExpression(this._anchorLineColor); } }, @@ -1265,7 +1283,8 @@ define([ return this._image; }, set : function(value) { - this._image = getExpression(this, value, 'image'); + this._image = getExpression(this, value); + this._style.image = getJsonFromExpression(this._image); } }, @@ -1304,7 +1323,8 @@ define([ return this._disableDepthTestDistance; }, set : function(value) { - this._disableDepthTestDistance = getExpression(this, value, 'disableDepthTestDistance'); + this._disableDepthTestDistance = getExpression(this, value); + this._style.disableDepthTestDistance = getJsonFromExpression(this._disableDepthTestDistance); } }, @@ -1352,7 +1372,8 @@ define([ return this._horizontalOrigin; }, set : function(value) { - this._horizontalOrigin = getExpression(this, value, 'horizontalOrigin'); + this._horizontalOrigin = getExpression(this, value); + this._style.horizontalOrigin = getJsonFromExpression(this._horizontalOrigin); } }, @@ -1400,7 +1421,8 @@ define([ return this._verticalOrigin; }, set : function(value) { - this._verticalOrigin = getExpression(this, value, 'verticalOrigin'); + this._verticalOrigin = getExpression(this, value); + this._style.verticalOrigin = getJsonFromExpression(this._verticalOrigin); } }, @@ -1448,7 +1470,8 @@ define([ return this._labelHorizontalOrigin; }, set : function(value) { - this._labelHorizontalOrigin = getExpression(this, value, 'labelHorizontalOrigin'); + this._labelHorizontalOrigin = getExpression(this, value); + this._style.labelHorizontalOrigin = getJsonFromExpression(this._labelHorizontalOrigin); } }, @@ -1496,7 +1519,8 @@ define([ return this._labelVerticalOrigin; }, set : function(value) { - this._labelVerticalOrigin = getExpression(this, value, 'labelVerticalOrigin'); + this._labelVerticalOrigin = getExpression(this, value); + this._style.labelVerticalOrigin = getJsonFromExpression(this._labelVerticalOrigin); } }, diff --git a/Specs/Scene/Cesium3DTileStyleSpec.js b/Specs/Scene/Cesium3DTileStyleSpec.js index 14815732e699..6cee7a0b1a32 100644 --- a/Specs/Scene/Cesium3DTileStyleSpec.js +++ b/Specs/Scene/Cesium3DTileStyleSpec.js @@ -293,7 +293,7 @@ defineSuite([ expect(style.style.show).toEqual('${height} * ${showFactor} >= 1000'); style.show = false; - expect(style.style.show).toEqual(false); + expect(style.style.show).toEqual('false'); var jsonExp = { conditions : [ @@ -539,7 +539,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.pointSize = 2; - expect(style.style.pointSize).toEqual(2); + expect(style.style.pointSize).toEqual('2'); style.pointSize = '${targetPointSize} + 1.0'; expect(style.style.pointSize).toEqual('${targetPointSize} + 1.0'); @@ -787,7 +787,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.pointOutlineWidth = 2; - expect(style.style.pointOutlineWidth).toEqual(2); + expect(style.style.pointOutlineWidth).toEqual('2'); style.pointOutlineWidth = '${targetPointSize} + 1.0'; expect(style.style.pointOutlineWidth).toEqual('${targetPointSize} + 1.0'); @@ -1153,7 +1153,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.labelOutlineWidth = 2; - expect(style.style.labelOutlineWidth).toEqual(2); + expect(style.style.labelOutlineWidth).toEqual('2'); style.labelOutlineWidth = '${targetLabelSize} + 1.0'; expect(style.style.labelOutlineWidth).toEqual('${targetLabelSize} + 1.0'); @@ -1400,7 +1400,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.labelStyle = 2; - expect(style.style.labelStyle).toEqual(2); + expect(style.style.labelStyle).toEqual('2'); style.labelStyle = '${targetLabelStyle}'; expect(style.style.labelStyle).toEqual('${targetLabelStyle}'); @@ -1905,7 +1905,7 @@ defineSuite([ expect(style.style.backgroundEnabled).toEqual('${height} * ${backgroundFactor} >= 1000'); style.backgroundEnabled = false; - expect(style.style.backgroundEnabled).toEqual(false); + expect(style.style.backgroundEnabled).toEqual('false'); var jsonExp = { conditions : [ @@ -2408,7 +2408,7 @@ defineSuite([ expect(style.style.anchorLineEnabled).toEqual('${height} * ${anchorFactor} >= 1000'); style.anchorLineEnabled = false; - expect(style.style.anchorLineEnabled).toEqual(false); + expect(style.style.anchorLineEnabled).toEqual('false'); var jsonExp = { conditions : [ @@ -2882,7 +2882,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.horizontalOrigin = -1; - expect(style.style.horizontalOrigin).toEqual(-1); + expect(style.style.horizontalOrigin).toEqual('-1'); style.horizontalOrigin = '${targetOrigin}'; expect(style.style.horizontalOrigin).toEqual('${targetOrigin}'); @@ -3001,7 +3001,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.verticalOrigin = -1; - expect(style.style.verticalOrigin).toEqual(-1); + expect(style.style.verticalOrigin).toEqual('-1'); style.verticalOrigin = '${targetOrigin}'; expect(style.style.verticalOrigin).toEqual('${targetOrigin}'); @@ -3120,7 +3120,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.labelHorizontalOrigin = -1; - expect(style.style.labelHorizontalOrigin).toEqual(-1); + expect(style.style.labelHorizontalOrigin).toEqual('-1'); style.labelHorizontalOrigin = '${targetOrigin}'; expect(style.style.labelHorizontalOrigin).toEqual('${targetOrigin}'); @@ -3239,7 +3239,7 @@ defineSuite([ var style = new Cesium3DTileStyle({ 'defines': defines }); style.labelVerticalOrigin = -1; - expect(style.style.labelVerticalOrigin).toEqual(-1); + expect(style.style.labelVerticalOrigin).toEqual('-1'); style.labelVerticalOrigin = '${targetOrigin}'; expect(style.style.labelVerticalOrigin).toEqual('${targetOrigin}'); From 65a39f3368a643b0f7692b28f5b85bc4a4fb5b9f Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 22 Mar 2019 08:55:03 +0100 Subject: [PATCH 7/8] getJsonFromExpression return custom expressions --- Source/Scene/Cesium3DTileStyle.js | 2 +- Specs/Scene/Cesium3DTileStyleSpec.js | 142 +++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index 521ca44372f1..0b3a0fea74be 100644 --- a/Source/Scene/Cesium3DTileStyle.js +++ b/Source/Scene/Cesium3DTileStyle.js @@ -181,7 +181,7 @@ define([ } else if (defined(expression.conditionsExpression)) { return clone(expression.conditionsExpression, true); } - return undefined; + return expression; } defineProperties(Cesium3DTileStyle.prototype, { diff --git a/Specs/Scene/Cesium3DTileStyleSpec.js b/Specs/Scene/Cesium3DTileStyleSpec.js index 6cee7a0b1a32..460f295410cf 100644 --- a/Specs/Scene/Cesium3DTileStyleSpec.js +++ b/Specs/Scene/Cesium3DTileStyleSpec.js @@ -505,6 +505,12 @@ defineSuite([ style.pointSize = new ConditionsExpression(jsonExp); expect(style.style.pointSize).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.pointSize = customExpression; + expect(style.style.pointSize).toEqual(customExpression); + style.pointSize = undefined; expect(style.style.pointSize).toBeUndefined(); }); @@ -631,6 +637,13 @@ defineSuite([ style.pointOutlineColor = new ConditionsExpression(jsonExp); expect(style.style.pointOutlineColor).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return Color.RED; }, + evaluateColor: function() { return Color.RED; } + }; + style.pointOutlineColor = customExpression; + expect(style.style.pointOutlineColor).toEqual(customExpression); + style.pointOutlineColor = undefined; expect(style.style.pointOutlineColor).toBeUndefined(); }); @@ -753,6 +766,12 @@ defineSuite([ style.pointOutlineWidth = new ConditionsExpression(jsonExp); expect(style.style.pointOutlineWidth).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.pointOutlineWidth = customExpression; + expect(style.style.pointOutlineWidth).toEqual(customExpression); + style.pointOutlineWidth = undefined; expect(style.style.pointOutlineWidth).toBeUndefined(); }); @@ -878,6 +897,13 @@ defineSuite([ style.labelColor = new ConditionsExpression(jsonExp); expect(style.style.labelColor).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return Color.RED; }, + evaluateColor: function() { return Color.RED; } + }; + style.labelColor = customExpression; + expect(style.style.labelColor).toEqual(customExpression); + style.labelColor = undefined; expect(style.style.labelColor).toBeUndefined(); }); @@ -998,6 +1024,13 @@ defineSuite([ style.labelOutlineColor = new ConditionsExpression(jsonExp); expect(style.style.labelOutlineColor).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return Color.RED; }, + evaluateColor: function() { return Color.RED; } + }; + style.labelOutlineColor = customExpression; + expect(style.style.labelOutlineColor).toEqual(customExpression); + style.labelOutlineColor = undefined; expect(style.style.labelOutlineColor).toBeUndefined(); }); @@ -1119,6 +1152,12 @@ defineSuite([ style.labelOutlineWidth = new ConditionsExpression(jsonExp); expect(style.style.labelOutlineWidth).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.labelOutlineWidth = customExpression; + expect(style.style.labelOutlineWidth).toEqual(customExpression); + style.labelOutlineWidth = undefined; expect(style.style.labelOutlineWidth).toBeUndefined(); }); @@ -1248,6 +1287,12 @@ defineSuite([ style.font = new ConditionsExpression(jsonExp); expect(style.style.font).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return '\'24px Helvetica\''; } + }; + style.font = customExpression; + expect(style.style.font).toEqual(customExpression); + style.font = undefined; expect(style.style.font).toBeUndefined(); }); @@ -1366,6 +1411,12 @@ defineSuite([ style.labelStyle = new ConditionsExpression(jsonExp); expect(style.style.labelStyle).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 0; } + }; + style.labelStyle = customExpression; + expect(style.style.labelStyle).toEqual(customExpression); + style.labelStyle = undefined; expect(style.style.labelStyle).toBeUndefined(); }); @@ -1495,6 +1546,12 @@ defineSuite([ style.labelText = new ConditionsExpression(jsonExp); expect(style.style.labelText).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return '\'test text 1\''; } + }; + style.labelText = customExpression; + expect(style.style.labelText).toEqual(customExpression); + style.labelText = undefined; expect(style.style.labelText).toBeUndefined(); }); @@ -1621,6 +1678,13 @@ defineSuite([ style.backgroundColor = new ConditionsExpression(jsonExp); expect(style.style.backgroundColor).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return Color.RED; }, + evaluateColor: function() { return Color.RED; } + }; + style.backgroundColor = customExpression; + expect(style.style.backgroundColor).toEqual(customExpression); + style.backgroundColor = undefined; expect(style.style.backgroundColor).toBeUndefined(); }); @@ -1738,6 +1802,12 @@ defineSuite([ ] }; + var customExpression = { + evaluate: function() { return new Cartesian2(1.0, 2.0); } + }; + style.labelText = customExpression; + expect(style.style.labelText).toEqual(customExpression); + style.backgroundPadding = new ConditionsExpression(jsonExp); expect(style.style.backgroundPadding).toEqual(jsonExp); @@ -1867,6 +1937,12 @@ defineSuite([ style.backgroundEnabled = new ConditionsExpression(jsonExp); expect(style.style.backgroundEnabled).toEqual(jsonExp); + + var customExpression = { + evaluate: function() { return true; } + }; + style.backgroundEnabled = customExpression; + expect(style.style.backgroundEnabled).toEqual(customExpression); }); it('sets backgroundEnabled values in setter', function() { @@ -1997,6 +2073,12 @@ defineSuite([ style.scaleByDistance = new ConditionsExpression(jsonExp); expect(style.style.scaleByDistance).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return new Cartesian4(1.0, 2.0, 3.0, 4.0); } + }; + style.scaleByDistance = customExpression; + expect(style.style.scaleByDistance).toEqual(customExpression); + style.scaleByDistance = undefined; expect(style.style.scaleByDistance).toBeUndefined(); }); @@ -2117,6 +2199,12 @@ defineSuite([ style.distanceDisplayCondition = new ConditionsExpression(jsonExp); expect(style.style.distanceDisplayCondition).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return new Cartesian4(1.0, 2.0, 3.0, 4.0); } + }; + style.distanceDisplayCondition = customExpression; + expect(style.style.distanceDisplayCondition).toEqual(customExpression); + style.distanceDisplayCondition = undefined; expect(style.style.distanceDisplayCondition).toBeUndefined(); }); @@ -2240,6 +2328,12 @@ defineSuite([ style.heightOffset = new ConditionsExpression(jsonExp); expect(style.style.heightOffset).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 2; } + }; + style.heightOffset = customExpression; + expect(style.style.heightOffset).toEqual(customExpression); + style.heightOffset = undefined; expect(style.style.heightOffset).toBeUndefined(); }); @@ -2370,6 +2464,11 @@ defineSuite([ style.anchorLineEnabled = new ConditionsExpression(jsonExp); expect(style.style.anchorLineEnabled).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return true; } + }; + style.anchorLineEnabled = customExpression; + expect(style.style.anchorLineEnabled).toEqual(customExpression); }); it('sets anchorLineEnabled values in setter', function() { @@ -2500,6 +2599,13 @@ defineSuite([ style.anchorLineColor = new ConditionsExpression(jsonExp); expect(style.style.anchorLineColor).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return Color.RED; }, + evaluateColor: function() { return Color.RED; } + }; + style.anchorLineColor = customExpression; + expect(style.style.anchorLineColor).toEqual(customExpression); + style.anchorLineColor = undefined; expect(style.style.anchorLineColor).toBeUndefined(); }); @@ -2623,6 +2729,12 @@ defineSuite([ style.image = new ConditionsExpression(jsonExp); expect(style.style.image).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return '\'url/to/image1\''; } + }; + style.image = customExpression; + expect(style.style.image).toEqual(customExpression); + style.image = undefined; expect(style.style.image).toBeUndefined(); }); @@ -2752,6 +2864,12 @@ defineSuite([ style.disableDepthTestDistance = new ConditionsExpression(jsonExp); expect(style.style.disableDepthTestDistance).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1.0; } + }; + style.disableDepthTestDistance = customExpression; + expect(style.style.disableDepthTestDistance).toEqual(customExpression); + style.disableDepthTestDistance = undefined; expect(style.style.disableDepthTestDistance).toBeUndefined(); }); @@ -2848,6 +2966,12 @@ defineSuite([ style.horizontalOrigin = new ConditionsExpression(jsonExp); expect(style.style.horizontalOrigin).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.horizontalOrigin = customExpression; + expect(style.style.horizontalOrigin).toEqual(customExpression); + style.horizontalOrigin = undefined; expect(style.style.horizontalOrigin).toBeUndefined(); }); @@ -2967,6 +3091,12 @@ defineSuite([ style.verticalOrigin = new ConditionsExpression(jsonExp); expect(style.style.verticalOrigin).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.verticalOrigin = customExpression; + expect(style.style.verticalOrigin).toEqual(customExpression); + style.verticalOrigin = undefined; expect(style.style.verticalOrigin).toBeUndefined(); }); @@ -3086,6 +3216,12 @@ defineSuite([ style.labelHorizontalOrigin = new ConditionsExpression(jsonExp); expect(style.style.labelHorizontalOrigin).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.labelHorizontalOrigin = customExpression; + expect(style.style.labelHorizontalOrigin).toEqual(customExpression); + style.labelHorizontalOrigin = undefined; expect(style.style.labelHorizontalOrigin).toBeUndefined(); }); @@ -3205,6 +3341,12 @@ defineSuite([ style.labelVerticalOrigin = new ConditionsExpression(jsonExp); expect(style.style.labelVerticalOrigin).toEqual(jsonExp); + var customExpression = { + evaluate: function() { return 1; } + }; + style.labelVerticalOrigin = customExpression; + expect(style.style.labelVerticalOrigin).toEqual(customExpression); + style.labelVerticalOrigin = undefined; expect(style.style.labelVerticalOrigin).toBeUndefined(); }); From 5f05495d883f91cba0135344348d9857ddbedef2 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 22 Mar 2019 08:58:36 +0100 Subject: [PATCH 8/8] added missing require to spec --- Specs/Scene/Cesium3DTileStyleSpec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Specs/Scene/Cesium3DTileStyleSpec.js b/Specs/Scene/Cesium3DTileStyleSpec.js index 460f295410cf..4f88119fb8ae 100644 --- a/Specs/Scene/Cesium3DTileStyleSpec.js +++ b/Specs/Scene/Cesium3DTileStyleSpec.js @@ -1,11 +1,15 @@ defineSuite([ 'Scene/Cesium3DTileStyle', + 'Core/Cartesian2', + 'Core/Cartesian4', 'Core/Color', 'Core/Resource', 'Scene/ConditionsExpression', 'Scene/Expression' ], function( Cesium3DTileStyle, + Cartesian2, + Cartesian4, Color, Resource, ConditionsExpression,