diff --git a/CHANGES.md b/CHANGES.md index a2dfb123e38c..28b375792f66 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) @@ -13,6 +14,7 @@ Change Log * `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode. It is only valid when `ImageBitmapOptions` is supported by the browser. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) * Added `backFaceCulling` and `normalShading` options to `PointCloudShading`. Both options are only applicable for point clouds containing normals. [#7399](https://github.com/AnalyticalGraphicsInc/cesium/pull/7399) * Added support for touch and hold gesture. The touch and hold delay can be customized by updating `ScreenSpaceEventHandler.touchHoldDelayMilliseconds`. [#7286](https://github.com/AnalyticalGraphicsInc/cesium/pull/7286) +* `Cesium3DTileStyle.style` reacts to updates and represents the current state of the style. [#7567](https://github.com/AnalyticalGraphicsInc/cesium/issues/7567) ##### Fixes :wrench: * Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https://github.com/AnalyticalGraphicsInc/cesium/pull/7624) diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index f6b2ed67949c..0b3a0fea74be 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; @@ -161,6 +160,7 @@ define([ function getExpression(tileStyle, value) { var defines = defaultValue(tileStyle._style, defaultValue.EMPTY_OBJECT).defines; + if (!defined(value)) { return undefined; } else if (typeof value === 'boolean' || typeof value === 'number') { @@ -173,6 +173,17 @@ define([ 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 expression; + } + defineProperties(Cesium3DTileStyle.prototype, { /** * Gets the object defining the style using the @@ -183,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. */ @@ -295,6 +306,7 @@ define([ }, set : function(value) { this._show = getExpression(this, value); + this._style.show = getJsonFromExpression(this._show); this._showShaderFunctionReady = false; } }, @@ -357,6 +369,7 @@ define([ }, set : function(value) { this._color = getExpression(this, value); + this._style.color = getJsonFromExpression(this._color); this._colorShaderFunctionReady = false; } }, @@ -424,6 +437,7 @@ define([ }, set : function(value) { this._pointSize = getExpression(this, value); + this._style.pointSize = getJsonFromExpression(this._pointSize); this._pointSizeShaderFunctionReady = false; } }, @@ -473,6 +487,7 @@ define([ }, set : function(value) { this._pointOutlineColor = getExpression(this, value); + this._style.pointOutlineColor = getJsonFromExpression(this._pointOutlineColor); } }, @@ -521,6 +536,7 @@ define([ }, set : function(value) { this._pointOutlineWidth = getExpression(this, value); + this._style.pointOutlineWidth = getJsonFromExpression(this._pointOutlineWidth); } }, @@ -569,6 +585,7 @@ define([ }, set : function(value) { this._labelColor = getExpression(this, value); + this._style.labelColor = getJsonFromExpression(this._labelColor); } }, @@ -617,6 +634,7 @@ define([ }, set : function(value) { this._labelOutlineColor = getExpression(this, value); + this._style.labelOutlineColor = getJsonFromExpression(this._labelOutlineColor); } }, @@ -665,6 +683,7 @@ define([ }, set : function(value) { this._labelOutlineWidth = getExpression(this, value); + this._style.labelOutlineWidth = getJsonFromExpression(this._labelOutlineWidth); } }, @@ -713,6 +732,7 @@ define([ }, set : function(value) { this._font = getExpression(this, value); + this._style.font = getJsonFromExpression(this._font); } }, @@ -761,6 +781,7 @@ define([ }, set : function(value) { this._labelStyle = getExpression(this, value); + this._style.labelStyle = getJsonFromExpression(this._labelStyle); } }, @@ -809,6 +830,7 @@ define([ }, set : function(value) { this._labelText = getExpression(this, value); + this._style.labelText = getJsonFromExpression(this._labelText); } }, @@ -857,6 +879,7 @@ define([ }, set : function(value) { this._backgroundColor = getExpression(this, value); + this._style.backgroundColor = getJsonFromExpression(this._backgroundColor); } }, @@ -896,6 +919,7 @@ define([ }, set : function(value) { this._backgroundPadding = getExpression(this, value); + this._style.backgroundPadding = getJsonFromExpression(this._backgroundPadding); } }, @@ -944,6 +968,7 @@ define([ }, set : function(value) { this._backgroundEnabled = getExpression(this, value); + this._style.backgroundEnabled = getJsonFromExpression(this._backgroundEnabled); } }, @@ -983,6 +1008,7 @@ define([ }, set : function(value) { this._scaleByDistance = getExpression(this, value); + this._style.scaleByDistance = getJsonFromExpression(this._scaleByDistance); } }, @@ -1022,6 +1048,7 @@ define([ }, set : function(value) { this._translucencyByDistance = getExpression(this, value); + this._style.translucencyByDistance = getJsonFromExpression(this._translucencyByDistance); } }, @@ -1061,6 +1088,7 @@ define([ }, set : function(value) { this._distanceDisplayCondition = getExpression(this, value); + this._style.distanceDisplayCondition = getJsonFromExpression(this._distanceDisplayCondition); } }, @@ -1109,6 +1137,7 @@ define([ }, set : function(value) { this._heightOffset = getExpression(this, value); + this._style.heightOffset = getJsonFromExpression(this._heightOffset); } }, @@ -1157,6 +1186,7 @@ define([ }, set : function(value) { this._anchorLineEnabled = getExpression(this, value); + this._style.anchorLineEnabled = getJsonFromExpression(this._anchorLineEnabled); } }, @@ -1205,6 +1235,7 @@ define([ }, set : function(value) { this._anchorLineColor = getExpression(this, value); + this._style.anchorLineColor = getJsonFromExpression(this._anchorLineColor); } }, @@ -1253,6 +1284,7 @@ define([ }, set : function(value) { this._image = getExpression(this, value); + this._style.image = getJsonFromExpression(this._image); } }, @@ -1292,6 +1324,7 @@ define([ }, set : function(value) { this._disableDepthTestDistance = getExpression(this, value); + this._style.disableDepthTestDistance = getJsonFromExpression(this._disableDepthTestDistance); } }, @@ -1340,6 +1373,7 @@ define([ }, set : function(value) { this._horizontalOrigin = getExpression(this, value); + this._style.horizontalOrigin = getJsonFromExpression(this._horizontalOrigin); } }, @@ -1388,6 +1422,7 @@ define([ }, set : function(value) { this._verticalOrigin = getExpression(this, value); + this._style.verticalOrigin = getJsonFromExpression(this._verticalOrigin); } }, @@ -1436,6 +1471,7 @@ define([ }, set : function(value) { this._labelHorizontalOrigin = getExpression(this, value); + this._style.labelHorizontalOrigin = getJsonFromExpression(this._labelHorizontalOrigin); } }, @@ -1484,6 +1520,7 @@ define([ }, set : function(value) { this._labelVerticalOrigin = getExpression(this, value); + this._style.labelVerticalOrigin = getJsonFromExpression(this._labelVerticalOrigin); } }, diff --git a/Specs/Scene/Cesium3DTileStyleSpec.js b/Specs/Scene/Cesium3DTileStyleSpec.js index 3f477c4255b4..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, @@ -287,6 +291,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 +373,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 +414,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 +494,31 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.pointSize = customExpression; + expect(style.style.pointSize).toEqual(customExpression); + + style.pointSize = undefined; + expect(style.style.pointSize).toBeUndefined(); + }); + it('sets pointSize values in setter', function() { var defines = { 'targetPointSize': '2.0' @@ -453,6 +542,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 +625,33 @@ 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); + + 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(); + }); + it('sets pointOutlineColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -533,6 +672,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 +755,31 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.pointOutlineWidth = customExpression; + expect(style.style.pointOutlineWidth).toEqual(customExpression); + + style.pointOutlineWidth = undefined; + expect(style.style.pointOutlineWidth).toBeUndefined(); + }); + it('sets pointOutlineWidth values in setter', function() { var defines = { 'targetPointSize': '2.0' @@ -619,6 +803,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 +886,32 @@ 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); + + 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(); + }); + it('sets labelColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -699,6 +932,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 +1012,33 @@ 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); + + 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(); + }); + it('sets labelOutlineColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -779,6 +1059,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 +1142,30 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.labelOutlineWidth = customExpression; + expect(style.style.labelOutlineWidth).toEqual(customExpression); + + style.labelOutlineWidth = undefined; + expect(style.style.labelOutlineWidth).toBeUndefined(); + }); + it('sets labelOutlineWidth values in setter', function() { var defines = { 'targetLabelSize': '2.0' @@ -865,6 +1189,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,21 +1275,47 @@ defineSuite([ expect(style.font).toBeUndefined(); }); - it('sets font values in setter', function() { - var defines = { - 'targetFont': '\'30px Helvetica\'' - }; - var style = new Cesium3DTileStyle({ 'defines': defines }); - - style.font = '\'24px Helvetica\''; - expect(style.font).toEqual(new Expression('\'24px Helvetica\'')); + it('sets style.font expressions in setter', function() { + var style = new Cesium3DTileStyle(); - style.font = '${targetFont}'; - expect(style.font).toEqual(new Expression('${targetFont}', defines)); + style.font = new Expression('\'24px Helvetica\''); + expect(style.style.font).toEqual('\'24px Helvetica\''); var jsonExp = { conditions : [ - ['${height} > 2', '\'24px Helvetica\''], + ['${height} > 2', '\'30px Helvetica\''], + ['true', '\'24px Helvetica\''] + ] + }; + + 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(); + }); + + it('sets font values in setter', function() { + var defines = { + 'targetFont': '\'30px Helvetica\'' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.font = '\'24px Helvetica\''; + expect(style.font).toEqual(new Expression('\'24px Helvetica\'')); + + style.font = '${targetFont}'; + expect(style.font).toEqual(new Expression('${targetFont}', defines)); + + var jsonExp = { + conditions : [ + ['${height} > 2', '\'24px Helvetica\''], ['true', '${targetFont}'] ] }; @@ -951,6 +1324,29 @@ defineSuite([ expect(style.font).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.font values in setter', function() { + var defines = { + 'targetFont': '\'30px Helvetica\'' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + 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(); @@ -1004,6 +1400,31 @@ 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); + + var customExpression = { + evaluate: function() { return 0; } + }; + style.labelStyle = customExpression; + expect(style.style.labelStyle).toEqual(customExpression); + + style.labelStyle = undefined; + expect(style.style.labelStyle).toBeUndefined(); + }); + it('sets labelStyle values in setter', function() { var defines = { 'targetLabelStyle': '2' @@ -1027,6 +1448,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 +1534,32 @@ 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); + + 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(); + }); + it('sets labelText values in setter', function() { var defines = { 'targetText': '\'test text 1\'' @@ -1113,6 +1583,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 +1666,33 @@ 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); + + 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(); + }); + it('sets backgroundColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -1193,6 +1713,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 +1793,32 @@ 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)'] + ] + }; + + 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); + + style.backgroundPadding = undefined; + expect(style.style.backgroundPadding).toBeUndefined(); + }); + it('sets backgroundPadding values in setter', function() { var defines = { 'targetPadding': '3.0, 4.0' @@ -1273,6 +1839,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 +1926,29 @@ 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); + + var customExpression = { + evaluate: function() { return true; } + }; + style.backgroundEnabled = customExpression; + expect(style.style.backgroundEnabled).toEqual(customExpression); + }); + it('sets backgroundEnabled values in setter', function() { var defines = { 'backgroundFactor': 10 @@ -1366,6 +1975,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 +2061,32 @@ 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); + + 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(); + }); + it('sets scaleByDistance values in setter', function() { var defines = { 'targetScale': '1.0, 2.0, 3.0, 4.' @@ -1446,6 +2107,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 +2187,32 @@ 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); + + 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(); + }); + it('sets distanceDisplayCondition values in setter', function() { var defines = { 'targetTranslucency': '1.0, 2.0, 3.0, 4.' @@ -1526,6 +2233,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(); @@ -1589,6 +2316,32 @@ defineSuite([ 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); + + var customExpression = { + evaluate: function() { return 2; } + }; + style.heightOffset = customExpression; + expect(style.style.heightOffset).toEqual(customExpression); + + style.heightOffset = undefined; + expect(style.style.heightOffset).toBeUndefined(); + }); + it('sets heightOffset values in setter', function() { var defines = { 'targetHeight': '2.0' @@ -1612,6 +2365,26 @@ defineSuite([ expect(style.heightOffset).toEqual(new ConditionsExpression(jsonExp, defines)); }); + it('sets style.heightOffset values in setter', function() { + var defines = { + 'targetHeight': '2.0' + }; + var style = new Cesium3DTileStyle({ 'defines': defines }); + + style.heightOffset = '${targetHeight} + 1.0'; + expect(style.style.heightOffset).toEqual('${targetHeight} + 1.0'); + + var jsonExp = { + conditions : [ + ['${height} > 2', '1.0'], + ['true', '${targetHeight}'] + ] + }; + + style.heightOffset = jsonExp; + expect(style.style.heightOffset).toEqual(jsonExp); + }); + it('sets anchorLineEnabled value to undefined if value not present', function() { var style = new Cesium3DTileStyle({}); expect(style.anchorLineEnabled).toBeUndefined(); @@ -1664,19 +2437,42 @@ defineSuite([ it('sets anchorLineEnabled expressions in setter', function() { var style = new Cesium3DTileStyle(); - var condExp = new ConditionsExpression({ + var condExp = new ConditionsExpression({ + conditions : [ + ['${height} > 2', 'false'], + ['true', 'true'] + ] + }); + + style.anchorLineEnabled = condExp; + expect(style.anchorLineEnabled).toEqual(condExp); + + var exp = new Expression('false'); + style.anchorLineEnabled = exp; + 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 = condExp; - expect(style.anchorLineEnabled).toEqual(condExp); + style.anchorLineEnabled = new ConditionsExpression(jsonExp); + expect(style.style.anchorLineEnabled).toEqual(jsonExp); - var exp = new Expression('false'); - style.anchorLineEnabled = exp; - expect(style.anchorLineEnabled).toEqual(exp); + var customExpression = { + evaluate: function() { return true; } + }; + style.anchorLineEnabled = customExpression; + expect(style.style.anchorLineEnabled).toEqual(customExpression); }); it('sets anchorLineEnabled values in setter', function() { @@ -1705,6 +2501,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 +2587,33 @@ 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); + + 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(); + }); + it('sets anchorLineColor values in setter', function() { var defines = { 'targetColor': 'red' @@ -1785,6 +2634,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 +2717,32 @@ 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); + + 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(); + }); + it('sets image values in setter', function() { var defines = { 'targetUrl': '\'url/to/image1\'' @@ -1871,6 +2766,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 +2852,32 @@ 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); + + var customExpression = { + evaluate: function() { return 1.0; } + }; + style.disableDepthTestDistance = customExpression; + expect(style.style.disableDepthTestDistance).toEqual(customExpression); + + style.disableDepthTestDistance = undefined; + expect(style.style.disableDepthTestDistance).toBeUndefined(); + }); + it('sets disableDepthTestDistance values in setter', function() { var defines = { 'targetDistance': '2.0' @@ -2010,6 +2954,32 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.horizontalOrigin = customExpression; + expect(style.style.horizontalOrigin).toEqual(customExpression); + + style.horizontalOrigin = undefined; + expect(style.style.horizontalOrigin).toBeUndefined(); + }); + it('sets horizontalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2033,6 +3003,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 +3079,32 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.verticalOrigin = customExpression; + expect(style.style.verticalOrigin).toEqual(customExpression); + + style.verticalOrigin = undefined; + expect(style.style.verticalOrigin).toBeUndefined(); + }); + it('sets verticalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2109,6 +3128,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 +3204,32 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.labelHorizontalOrigin = customExpression; + expect(style.style.labelHorizontalOrigin).toEqual(customExpression); + + style.labelHorizontalOrigin = undefined; + expect(style.style.labelHorizontalOrigin).toBeUndefined(); + }); + it('sets labelHorizontalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2185,6 +3253,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 +3329,32 @@ 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); + + var customExpression = { + evaluate: function() { return 1; } + }; + style.labelVerticalOrigin = customExpression; + expect(style.style.labelVerticalOrigin).toEqual(customExpression); + + style.labelVerticalOrigin = undefined; + expect(style.style.labelVerticalOrigin).toBeUndefined(); + }); + it('sets labelVerticalOrigin values in setter', function() { var defines = { 'targetOrigin': '-1' @@ -2261,6 +3378,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;