From 5cb1088d0dbc8b01d2eb46b289e1ab77150c01b1 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 27 Sep 2016 14:57:59 -0400 Subject: [PATCH] Change conditions from an object to an array --- Apps/Sandcastle/gallery/3D Tiles.html | 24 ++++++++++----------- Source/Scene/ConditionsExpression.js | 30 +++++++++++++-------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Apps/Sandcastle/gallery/3D Tiles.html b/Apps/Sandcastle/gallery/3D Tiles.html index e8bda0c717fc..2c0558216d34 100644 --- a/Apps/Sandcastle/gallery/3D Tiles.html +++ b/Apps/Sandcastle/gallery/3D Tiles.html @@ -87,15 +87,15 @@ // "color" : "rgb(100, 255, 190)", // "color" : "hsla(0.9, 0.6, 0.7, 0.75)", "color" : { - "conditions" : { - "${Height} >= 83" : "color('purple', 0.5)", - "${Height} >= 80" : "color('red')", - "${Height} >= 70" : "color('orange')", - "${Height} >= 12" : "color('yellow')", - "${Height} >= 7" : "color('lime')", - "${Height} >= 1" : "color('cyan')", - "true" : "color('blue')" - } + "conditions" : [ + ["${Height} >= 83", "color('purple', 0.5)"], + ["${Height} >= 80", "color('red')"], + ["${Height} >= 70", "color('orange')"], + ["${Height} >= 12", "color('yellow')"], + ["${Height} >= 7", "color('lime')"], + ["${Height} >= 1", "color('cyan')"], + ["true", "color('blue')"] + ] }, // "show": false, // "show" : "${Height} >= 0", @@ -410,13 +410,13 @@ } function styleFunction(name) { - var conditions = {}; + var conditions = []; var intervalSize = Math.floor(100/numberofColors); for (var i = numberofColors; i >= 0; --i) { var cond = '${' + name + '} > ' + (i * intervalSize); - conditions[cond] = getRandomColor(); + conditions.push([cond, getRandomColor()]); } - conditions['true'] = getRandomColor(); + conditions.push(['true', getRandomColor()]); tileset.style = new Cesium.Cesium3DTileStyle({ color : { diff --git a/Source/Scene/ConditionsExpression.js b/Source/Scene/ConditionsExpression.js index 70be56e9a854..986467e1e23d 100644 --- a/Source/Scene/ConditionsExpression.js +++ b/Source/Scene/ConditionsExpression.js @@ -79,22 +79,22 @@ define([ var runtimeConditions = []; var conditions = expression._conditions; var exp = expression._expression; - for (var cond in conditions) { - if (conditions.hasOwnProperty(cond)) { - cond = String(cond); - var condExpression = String(conditions[cond]); - if (defined(exp)) { - cond = cond.replace(expressionPlaceholder, exp); - condExpression = condExpression.replace(expressionPlaceholder, exp); - } else { - cond = cond.replace(expressionPlaceholder, 'undefined'); - condExpression = condExpression.replace(expressionPlaceholder, 'undefined'); - } - runtimeConditions.push(new Statement( - new Expression(cond), - new Expression(condExpression) - )); + var length = conditions.length; + for (var i = 0; i < length; ++i) { + var statement = conditions[i]; + var cond = String(statement[0]); + var condExpression = String(statement[1]); + if (defined(exp)) { + cond = cond.replace(expressionPlaceholder, exp); + condExpression = condExpression.replace(expressionPlaceholder, exp); + } else { + cond = cond.replace(expressionPlaceholder, 'undefined'); + condExpression = condExpression.replace(expressionPlaceholder, 'undefined'); } + runtimeConditions.push(new Statement( + new Expression(cond), + new Expression(condExpression) + )); } expression._runtimeConditions = runtimeConditions;