智慧水务管理系统 - 精河县供水工程综合管理平台

Cesium3DTileStyle.js 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. import addAllToArray from "../Core/addAllToArray.js";
  2. import clone from "../Core/clone.js";
  3. import Frozen from "../Core/Frozen.js";
  4. import defined from "../Core/defined.js";
  5. import DeveloperError from "../Core/DeveloperError.js";
  6. import Resource from "../Core/Resource.js";
  7. import ConditionsExpression from "./ConditionsExpression.js";
  8. import Expression from "./Expression.js";
  9. /**
  10. * A style that is applied to a {@link Cesium3DTileset}.
  11. * <p>
  12. * Evaluates an expression defined using the
  13. * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}.
  14. * </p>
  15. *
  16. * @alias Cesium3DTileStyle
  17. * @constructor
  18. *
  19. * @param {object} [style] An object defining a style.
  20. *
  21. * @example
  22. * tileset.style = new Cesium.Cesium3DTileStyle({
  23. * color : {
  24. * conditions : [
  25. * ['${Height} >= 100', 'color("purple", 0.5)'],
  26. * ['${Height} >= 50', 'color("red")'],
  27. * ['true', 'color("blue")']
  28. * ]
  29. * },
  30. * show : '${Height} > 0',
  31. * meta : {
  32. * description : '"Building id ${id} has height ${Height}."'
  33. * }
  34. * });
  35. *
  36. * @example
  37. * tileset.style = new Cesium.Cesium3DTileStyle({
  38. * color : 'vec4(${Temperature})',
  39. * pointSize : '${Temperature} * 2.0'
  40. * });
  41. *
  42. * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}
  43. */
  44. function Cesium3DTileStyle(style) {
  45. this._style = {};
  46. this._ready = false;
  47. this._show = undefined;
  48. this._color = undefined;
  49. this._pointSize = undefined;
  50. this._pointOutlineColor = undefined;
  51. this._pointOutlineWidth = undefined;
  52. this._labelColor = undefined;
  53. this._labelOutlineColor = undefined;
  54. this._labelOutlineWidth = undefined;
  55. this._font = undefined;
  56. this._labelStyle = undefined;
  57. this._labelText = undefined;
  58. this._backgroundColor = undefined;
  59. this._backgroundPadding = undefined;
  60. this._backgroundEnabled = undefined;
  61. this._scaleByDistance = undefined;
  62. this._translucencyByDistance = undefined;
  63. this._distanceDisplayCondition = undefined;
  64. this._heightOffset = undefined;
  65. this._anchorLineEnabled = undefined;
  66. this._anchorLineColor = undefined;
  67. this._image = undefined;
  68. this._disableDepthTestDistance = undefined;
  69. this._horizontalOrigin = undefined;
  70. this._verticalOrigin = undefined;
  71. this._labelHorizontalOrigin = undefined;
  72. this._labelVerticalOrigin = undefined;
  73. this._meta = undefined;
  74. // Vector Tiles in 3D Tiles 2.0.
  75. this._lineWidth = undefined;
  76. this._colorShaderFunction = undefined;
  77. this._showShaderFunction = undefined;
  78. this._pointSizeShaderFunction = undefined;
  79. this._colorShaderFunctionReady = false;
  80. this._showShaderFunctionReady = false;
  81. this._pointSizeShaderFunctionReady = false;
  82. this._colorShaderTranslucent = false;
  83. setup(this, style);
  84. }
  85. function setup(that, styleJson) {
  86. styleJson = clone(styleJson, true) ?? that._style;
  87. that._style = styleJson;
  88. that.show = styleJson.show;
  89. that.color = styleJson.color;
  90. that.pointSize = styleJson.pointSize;
  91. that.pointOutlineColor = styleJson.pointOutlineColor;
  92. that.pointOutlineWidth = styleJson.pointOutlineWidth;
  93. that.labelColor = styleJson.labelColor;
  94. that.labelOutlineColor = styleJson.labelOutlineColor;
  95. that.labelOutlineWidth = styleJson.labelOutlineWidth;
  96. that.labelStyle = styleJson.labelStyle;
  97. that.font = styleJson.font;
  98. that.labelText = styleJson.labelText;
  99. that.backgroundColor = styleJson.backgroundColor;
  100. that.backgroundPadding = styleJson.backgroundPadding;
  101. that.backgroundEnabled = styleJson.backgroundEnabled;
  102. that.scaleByDistance = styleJson.scaleByDistance;
  103. that.translucencyByDistance = styleJson.translucencyByDistance;
  104. that.distanceDisplayCondition = styleJson.distanceDisplayCondition;
  105. that.heightOffset = styleJson.heightOffset;
  106. that.anchorLineEnabled = styleJson.anchorLineEnabled;
  107. that.anchorLineColor = styleJson.anchorLineColor;
  108. that.image = styleJson.image;
  109. that.disableDepthTestDistance = styleJson.disableDepthTestDistance;
  110. that.horizontalOrigin = styleJson.horizontalOrigin;
  111. that.verticalOrigin = styleJson.verticalOrigin;
  112. that.labelHorizontalOrigin = styleJson.labelHorizontalOrigin;
  113. that.labelVerticalOrigin = styleJson.labelVerticalOrigin;
  114. // Vector Tiles in 3D Tiles 2.0.
  115. that.lineWidth = styleJson.lineWidth;
  116. const meta = {};
  117. if (defined(styleJson.meta)) {
  118. const defines = styleJson.defines;
  119. const metaJson = styleJson.meta ?? Frozen.EMPTY_OBJECT;
  120. for (const property in metaJson) {
  121. if (metaJson.hasOwnProperty(property)) {
  122. meta[property] = new Expression(metaJson[property], defines);
  123. }
  124. }
  125. }
  126. that._meta = meta;
  127. that._ready = true;
  128. }
  129. function getExpression(tileStyle, value) {
  130. const defines = (tileStyle._style ?? Frozen.EMPTY_OBJECT).defines;
  131. if (!defined(value)) {
  132. return undefined;
  133. } else if (typeof value === "boolean" || typeof value === "number") {
  134. return new Expression(String(value));
  135. } else if (typeof value === "string") {
  136. return new Expression(value, defines);
  137. } else if (defined(value.conditions)) {
  138. return new ConditionsExpression(value, defines);
  139. }
  140. return value;
  141. }
  142. function getJsonFromExpression(expression) {
  143. if (!defined(expression)) {
  144. return undefined;
  145. } else if (defined(expression.expression)) {
  146. return expression.expression;
  147. } else if (defined(expression.conditionsExpression)) {
  148. return clone(expression.conditionsExpression, true);
  149. }
  150. return expression;
  151. }
  152. Object.defineProperties(Cesium3DTileStyle.prototype, {
  153. /**
  154. * Gets the object defining the style using the
  155. * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}.
  156. *
  157. * @memberof Cesium3DTileStyle.prototype
  158. *
  159. * @type {object}
  160. * @readonly
  161. *
  162. * @default {}
  163. */
  164. style: {
  165. get: function () {
  166. return this._style;
  167. },
  168. },
  169. /**
  170. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>show</code> property. Alternatively a boolean, string, or object defining a show style can be used.
  171. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  172. * <p>
  173. * The expression must return or convert to a <code>Boolean</code>.
  174. * </p>
  175. * <p>
  176. * This expression is applicable to all tile formats.
  177. * </p>
  178. *
  179. * @memberof Cesium3DTileStyle.prototype
  180. *
  181. * @type {StyleExpression}
  182. *
  183. * @example
  184. * const style = new Cesium3DTileStyle({
  185. * show : '(regExp("^Chest").test(${County})) && (${YearBuilt} >= 1970)'
  186. * });
  187. * style.show.evaluate(feature); // returns true or false depending on the feature's properties
  188. *
  189. * @example
  190. * const style = new Cesium.Cesium3DTileStyle();
  191. * // Override show expression with a custom function
  192. * style.show = {
  193. * evaluate : function(feature) {
  194. * return true;
  195. * }
  196. * };
  197. *
  198. * @example
  199. * const style = new Cesium.Cesium3DTileStyle();
  200. * // Override show expression with a boolean
  201. * style.show = true;
  202. * };
  203. *
  204. * @example
  205. * const style = new Cesium.Cesium3DTileStyle();
  206. * // Override show expression with a string
  207. * style.show = '${Height} > 0';
  208. * };
  209. *
  210. * @example
  211. * const style = new Cesium.Cesium3DTileStyle();
  212. * // Override show expression with a condition
  213. * style.show = {
  214. * conditions: [
  215. * ['${height} > 2', 'false'],
  216. * ['true', 'true']
  217. * ];
  218. * };
  219. */
  220. show: {
  221. get: function () {
  222. return this._show;
  223. },
  224. set: function (value) {
  225. this._show = getExpression(this, value);
  226. this._style.show = getJsonFromExpression(this._show);
  227. this._showShaderFunctionReady = false;
  228. },
  229. },
  230. /**
  231. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>color</code> property. Alternatively a string or object defining a color style can be used.
  232. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  233. * <p>
  234. * The expression must return a <code>Color</code>.
  235. * </p>
  236. * <p>
  237. * This expression is applicable to all tile formats.
  238. * </p>
  239. *
  240. * @memberof Cesium3DTileStyle.prototype
  241. *
  242. * @type {StyleExpression}
  243. *
  244. * @example
  245. * const style = new Cesium3DTileStyle({
  246. * color : '(${Temperature} > 90) ? color("red") : color("white")'
  247. * });
  248. * style.color.evaluateColor(feature, result); // returns a Cesium.Color object
  249. *
  250. * @example
  251. * const style = new Cesium.Cesium3DTileStyle();
  252. * // Override color expression with a custom function
  253. * style.color = {
  254. * evaluateColor : function(feature, result) {
  255. * return Cesium.Color.clone(Cesium.Color.WHITE, result);
  256. * }
  257. * };
  258. *
  259. * @example
  260. * const style = new Cesium.Cesium3DTileStyle();
  261. * // Override color expression with a string
  262. * style.color = 'color("blue")';
  263. *
  264. * @example
  265. * const style = new Cesium.Cesium3DTileStyle();
  266. * // Override color expression with a condition
  267. * style.color = {
  268. * conditions : [
  269. * ['${height} > 2', 'color("cyan")'],
  270. * ['true', 'color("blue")']
  271. * ]
  272. * };
  273. */
  274. color: {
  275. get: function () {
  276. return this._color;
  277. },
  278. set: function (value) {
  279. this._color = getExpression(this, value);
  280. this._style.color = getJsonFromExpression(this._color);
  281. this._colorShaderFunctionReady = false;
  282. },
  283. },
  284. /**
  285. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>pointSize</code> property. Alternatively a string or object defining a point size style can be used.
  286. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  287. * <p>
  288. * The expression must return a <code>Number</code>.
  289. * </p>
  290. * <p>
  291. * This expression is only applicable to point features in a Vector tile or a Point Cloud tile.
  292. * </p>
  293. *
  294. * @memberof Cesium3DTileStyle.prototype
  295. *
  296. * @type {StyleExpression}
  297. *
  298. * @example
  299. * const style = new Cesium3DTileStyle({
  300. * pointSize : '(${Temperature} > 90) ? 2.0 : 1.0'
  301. * });
  302. * style.pointSize.evaluate(feature); // returns a Number
  303. *
  304. * @example
  305. * const style = new Cesium.Cesium3DTileStyle();
  306. * // Override pointSize expression with a custom function
  307. * style.pointSize = {
  308. * evaluate : function(feature) {
  309. * return 1.0;
  310. * }
  311. * };
  312. *
  313. * @example
  314. * const style = new Cesium.Cesium3DTileStyle();
  315. * // Override pointSize expression with a number
  316. * style.pointSize = 1.0;
  317. *
  318. * @example
  319. * const style = new Cesium.Cesium3DTileStyle();
  320. * // Override pointSize expression with a string
  321. * style.pointSize = '${height} / 10';
  322. *
  323. * @example
  324. * const style = new Cesium.Cesium3DTileStyle();
  325. * // Override pointSize expression with a condition
  326. * style.pointSize = {
  327. * conditions : [
  328. * ['${height} > 2', '1.0'],
  329. * ['true', '2.0']
  330. * ]
  331. * };
  332. */
  333. pointSize: {
  334. get: function () {
  335. return this._pointSize;
  336. },
  337. set: function (value) {
  338. this._pointSize = getExpression(this, value);
  339. this._style.pointSize = getJsonFromExpression(this._pointSize);
  340. this._pointSizeShaderFunctionReady = false;
  341. },
  342. },
  343. /**
  344. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>pointOutlineColor</code> property. Alternatively a string or object defining a color style can be used.
  345. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  346. * <p>
  347. * The expression must return a <code>Color</code>.
  348. * </p>
  349. * <p>
  350. * This expression is only applicable to point features in a Vector tile.
  351. * </p>
  352. *
  353. * @memberof Cesium3DTileStyle.prototype
  354. *
  355. * @type {StyleExpression}
  356. *
  357. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  358. *
  359. * @example
  360. * const style = new Cesium.Cesium3DTileStyle();
  361. * // Override pointOutlineColor expression with a string
  362. * style.pointOutlineColor = 'color("blue")';
  363. *
  364. * @example
  365. * const style = new Cesium.Cesium3DTileStyle();
  366. * // Override pointOutlineColor expression with a condition
  367. * style.pointOutlineColor = {
  368. * conditions : [
  369. * ['${height} > 2', 'color("cyan")'],
  370. * ['true', 'color("blue")']
  371. * ]
  372. * };
  373. */
  374. pointOutlineColor: {
  375. get: function () {
  376. return this._pointOutlineColor;
  377. },
  378. set: function (value) {
  379. this._pointOutlineColor = getExpression(this, value);
  380. this._style.pointOutlineColor = getJsonFromExpression(
  381. this._pointOutlineColor,
  382. );
  383. },
  384. },
  385. /**
  386. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>pointOutlineWidth</code> property. Alternatively a string or object defining a number style can be used.
  387. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  388. * <p>
  389. * The expression must return a <code>Number</code>.
  390. * </p>
  391. * <p>
  392. * This expression is only applicable to point features in a Vector tile.
  393. * </p>
  394. *
  395. * @memberof Cesium3DTileStyle.prototype
  396. *
  397. * @type {StyleExpression}
  398. *
  399. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  400. *
  401. * @example
  402. * const style = new Cesium.Cesium3DTileStyle();
  403. * // Override pointOutlineWidth expression with a string
  404. * style.pointOutlineWidth = '5';
  405. *
  406. * @example
  407. * const style = new Cesium.Cesium3DTileStyle();
  408. * // Override pointOutlineWidth expression with a condition
  409. * style.pointOutlineWidth = {
  410. * conditions : [
  411. * ['${height} > 2', '5'],
  412. * ['true', '0']
  413. * ]
  414. * };
  415. */
  416. pointOutlineWidth: {
  417. get: function () {
  418. return this._pointOutlineWidth;
  419. },
  420. set: function (value) {
  421. this._pointOutlineWidth = getExpression(this, value);
  422. this._style.pointOutlineWidth = getJsonFromExpression(
  423. this._pointOutlineWidth,
  424. );
  425. },
  426. },
  427. /**
  428. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>labelColor</code> property. Alternatively a string or object defining a color style can be used.
  429. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  430. * <p>
  431. * The expression must return a <code>Color</code>.
  432. * </p>
  433. * <p>
  434. * This expression is only applicable to point features in a Vector tile.
  435. * </p>
  436. *
  437. * @memberof Cesium3DTileStyle.prototype
  438. *
  439. * @type {StyleExpression}
  440. *
  441. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  442. *
  443. * @example
  444. * const style = new Cesium.Cesium3DTileStyle();
  445. * // Override labelColor expression with a string
  446. * style.labelColor = 'color("blue")';
  447. *
  448. * @example
  449. * const style = new Cesium.Cesium3DTileStyle();
  450. * // Override labelColor expression with a condition
  451. * style.labelColor = {
  452. * conditions : [
  453. * ['${height} > 2', 'color("cyan")'],
  454. * ['true', 'color("blue")']
  455. * ]
  456. * };
  457. */
  458. labelColor: {
  459. get: function () {
  460. return this._labelColor;
  461. },
  462. set: function (value) {
  463. this._labelColor = getExpression(this, value);
  464. this._style.labelColor = getJsonFromExpression(this._labelColor);
  465. },
  466. },
  467. /**
  468. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>labelOutlineColor</code> property. Alternatively a string or object defining a color style can be used.
  469. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  470. * <p>
  471. * The expression must return a <code>Color</code>.
  472. * </p>
  473. * <p>
  474. * This expression is only applicable to point features in a Vector tile.
  475. * </p>
  476. *
  477. * @memberof Cesium3DTileStyle.prototype
  478. *
  479. * @type {StyleExpression}
  480. *
  481. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  482. *
  483. * @example
  484. * const style = new Cesium.Cesium3DTileStyle();
  485. * // Override labelOutlineColor expression with a string
  486. * style.labelOutlineColor = 'color("blue")';
  487. *
  488. * @example
  489. * const style = new Cesium.Cesium3DTileStyle();
  490. * // Override labelOutlineColor expression with a condition
  491. * style.labelOutlineColor = {
  492. * conditions : [
  493. * ['${height} > 2', 'color("cyan")'],
  494. * ['true', 'color("blue")']
  495. * ]
  496. * };
  497. */
  498. labelOutlineColor: {
  499. get: function () {
  500. return this._labelOutlineColor;
  501. },
  502. set: function (value) {
  503. this._labelOutlineColor = getExpression(this, value);
  504. this._style.labelOutlineColor = getJsonFromExpression(
  505. this._labelOutlineColor,
  506. );
  507. },
  508. },
  509. /**
  510. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>labelOutlineWidth</code> property. Alternatively a string or object defining a number style can be used.
  511. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  512. * <p>
  513. * The expression must return a <code>Number</code>.
  514. * </p>
  515. * <p>
  516. * This expression is only applicable to point features in a Vector tile.
  517. * </p>
  518. *
  519. * @memberof Cesium3DTileStyle.prototype
  520. *
  521. * @type {StyleExpression}
  522. *
  523. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  524. *
  525. * @example
  526. * const style = new Cesium.Cesium3DTileStyle();
  527. * // Override labelOutlineWidth expression with a string
  528. * style.labelOutlineWidth = '5';
  529. *
  530. * @example
  531. * const style = new Cesium.Cesium3DTileStyle();
  532. * // Override labelOutlineWidth expression with a condition
  533. * style.labelOutlineWidth = {
  534. * conditions : [
  535. * ['${height} > 2', '5'],
  536. * ['true', '0']
  537. * ]
  538. * };
  539. */
  540. labelOutlineWidth: {
  541. get: function () {
  542. return this._labelOutlineWidth;
  543. },
  544. set: function (value) {
  545. this._labelOutlineWidth = getExpression(this, value);
  546. this._style.labelOutlineWidth = getJsonFromExpression(
  547. this._labelOutlineWidth,
  548. );
  549. },
  550. },
  551. /**
  552. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>font</code> property. Alternatively a string or object defining a string style can be used.
  553. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  554. * <p>
  555. * The expression must return a <code>String</code>.
  556. * </p>
  557. * <p>
  558. * This expression is only applicable to point features in a Vector tile.
  559. * </p>
  560. *
  561. * @memberof Cesium3DTileStyle.prototype
  562. *
  563. * @type {StyleExpression}
  564. *
  565. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  566. *
  567. * @example
  568. * const style = new Cesium3DTileStyle({
  569. * font : '(${Temperature} > 90) ? "30px Helvetica" : "24px Helvetica"'
  570. * });
  571. * style.font.evaluate(feature); // returns a String
  572. *
  573. * @example
  574. * const style = new Cesium.Cesium3DTileStyle();
  575. * // Override font expression with a custom function
  576. * style.font = {
  577. * evaluate : function(feature) {
  578. * return '24px Helvetica';
  579. * }
  580. * };
  581. */
  582. font: {
  583. get: function () {
  584. return this._font;
  585. },
  586. set: function (value) {
  587. this._font = getExpression(this, value);
  588. this._style.font = getJsonFromExpression(this._font);
  589. },
  590. },
  591. /**
  592. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>label style</code> property. Alternatively a string or object defining a number style can be used.
  593. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  594. * <p>
  595. * The expression must return a <code>LabelStyle</code>.
  596. * </p>
  597. * <p>
  598. * This expression is only applicable to point features in a Vector tile.
  599. * </p>
  600. *
  601. * @memberof Cesium3DTileStyle.prototype
  602. *
  603. * @type {StyleExpression}
  604. *
  605. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  606. *
  607. * @example
  608. * const style = new Cesium3DTileStyle({
  609. * labelStyle : `(\${Temperature} > 90) ? ${LabelStyle.FILL_AND_OUTLINE} : ${LabelStyle.FILL}`
  610. * });
  611. * style.labelStyle.evaluate(feature); // returns a LabelStyle
  612. *
  613. * @example
  614. * const style = new Cesium.Cesium3DTileStyle();
  615. * // Override labelStyle expression with a custom function
  616. * style.labelStyle = {
  617. * evaluate : function(feature) {
  618. * return LabelStyle.FILL;
  619. * }
  620. * };
  621. */
  622. labelStyle: {
  623. get: function () {
  624. return this._labelStyle;
  625. },
  626. set: function (value) {
  627. this._labelStyle = getExpression(this, value);
  628. this._style.labelStyle = getJsonFromExpression(this._labelStyle);
  629. },
  630. },
  631. /**
  632. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>labelText</code> property. Alternatively a string or object defining a string style can be used.
  633. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  634. * <p>
  635. * The expression must return a <code>String</code>.
  636. * </p>
  637. * <p>
  638. * This expression is only applicable to point features in a Vector tile.
  639. * </p>
  640. *
  641. * @memberof Cesium3DTileStyle.prototype
  642. *
  643. * @type {StyleExpression}
  644. *
  645. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  646. *
  647. * @example
  648. * const style = new Cesium3DTileStyle({
  649. * labelText : '(${Temperature} > 90) ? ">90" : "<=90"'
  650. * });
  651. * style.labelText.evaluate(feature); // returns a String
  652. *
  653. * @example
  654. * const style = new Cesium.Cesium3DTileStyle();
  655. * // Override labelText expression with a custom function
  656. * style.labelText = {
  657. * evaluate : function(feature) {
  658. * return 'Example label text';
  659. * }
  660. * };
  661. */
  662. labelText: {
  663. get: function () {
  664. return this._labelText;
  665. },
  666. set: function (value) {
  667. this._labelText = getExpression(this, value);
  668. this._style.labelText = getJsonFromExpression(this._labelText);
  669. },
  670. },
  671. /**
  672. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>backgroundColor</code> property. Alternatively a string or object defining a color style can be used.
  673. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  674. * <p>
  675. * The expression must return a <code>Color</code>.
  676. * </p>
  677. * <p>
  678. * This expression is only applicable to point features in a Vector tile.
  679. * </p>
  680. *
  681. * @memberof Cesium3DTileStyle.prototype
  682. *
  683. * @type {StyleExpression}
  684. *
  685. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  686. *
  687. * @example
  688. * const style = new Cesium.Cesium3DTileStyle();
  689. * // Override backgroundColor expression with a string
  690. * style.backgroundColor = 'color("blue")';
  691. *
  692. * @example
  693. * const style = new Cesium.Cesium3DTileStyle();
  694. * // Override backgroundColor expression with a condition
  695. * style.backgroundColor = {
  696. * conditions : [
  697. * ['${height} > 2', 'color("cyan")'],
  698. * ['true', 'color("blue")']
  699. * ]
  700. * };
  701. */
  702. backgroundColor: {
  703. get: function () {
  704. return this._backgroundColor;
  705. },
  706. set: function (value) {
  707. this._backgroundColor = getExpression(this, value);
  708. this._style.backgroundColor = getJsonFromExpression(
  709. this._backgroundColor,
  710. );
  711. },
  712. },
  713. /**
  714. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>backgroundPadding</code> property. Alternatively a string or object defining a vec2 style can be used.
  715. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  716. * <p>
  717. * The expression must return a <code>Cartesian2</code>.
  718. * </p>
  719. * <p>
  720. * This expression is only applicable to point features in a Vector tile.
  721. * </p>
  722. *
  723. * @memberof Cesium3DTileStyle.prototype
  724. *
  725. * @type {StyleExpression}
  726. *
  727. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  728. *
  729. * @example
  730. * const style = new Cesium.Cesium3DTileStyle();
  731. * // Override backgroundPadding expression with a string
  732. * style.backgroundPadding = 'vec2(5.0, 7.0)';
  733. * style.backgroundPadding.evaluate(feature); // returns a Cartesian2
  734. */
  735. backgroundPadding: {
  736. get: function () {
  737. return this._backgroundPadding;
  738. },
  739. set: function (value) {
  740. this._backgroundPadding = getExpression(this, value);
  741. this._style.backgroundPadding = getJsonFromExpression(
  742. this._backgroundPadding,
  743. );
  744. },
  745. },
  746. /**
  747. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>backgroundEnabled</code> property. Alternatively a string or object defining a boolean style can be used.
  748. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  749. * <p>
  750. * The expression must return a <code>Boolean</code>.
  751. * </p>
  752. * <p>
  753. * This expression is only applicable to point features in a Vector tile.
  754. * </p>
  755. *
  756. * @memberof Cesium3DTileStyle.prototype
  757. *
  758. * @type {StyleExpression}
  759. *
  760. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  761. *
  762. * @example
  763. * const style = new Cesium.Cesium3DTileStyle();
  764. * // Override backgroundEnabled expression with a string
  765. * style.backgroundEnabled = 'true';
  766. *
  767. * @example
  768. * const style = new Cesium.Cesium3DTileStyle();
  769. * // Override backgroundEnabled expression with a condition
  770. * style.backgroundEnabled = {
  771. * conditions : [
  772. * ['${height} > 2', 'true'],
  773. * ['true', 'false']
  774. * ]
  775. * };
  776. */
  777. backgroundEnabled: {
  778. get: function () {
  779. return this._backgroundEnabled;
  780. },
  781. set: function (value) {
  782. this._backgroundEnabled = getExpression(this, value);
  783. this._style.backgroundEnabled = getJsonFromExpression(
  784. this._backgroundEnabled,
  785. );
  786. },
  787. },
  788. /**
  789. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>scaleByDistance</code> property. Alternatively a string or object defining a vec4 style can be used.
  790. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  791. * <p>
  792. * The expression must return a <code>Cartesian4</code>.
  793. * </p>
  794. * <p>
  795. * This expression is only applicable to point features in a Vector tile.
  796. * </p>
  797. *
  798. * @memberof Cesium3DTileStyle.prototype
  799. *
  800. * @type {StyleExpression}
  801. *
  802. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  803. *
  804. * @example
  805. * const style = new Cesium.Cesium3DTileStyle();
  806. * // Override scaleByDistance expression with a string
  807. * style.scaleByDistance = 'vec4(1.5e2, 2.0, 1.5e7, 0.5)';
  808. * style.scaleByDistance.evaluate(feature); // returns a Cartesian4
  809. */
  810. scaleByDistance: {
  811. get: function () {
  812. return this._scaleByDistance;
  813. },
  814. set: function (value) {
  815. this._scaleByDistance = getExpression(this, value);
  816. this._style.scaleByDistance = getJsonFromExpression(
  817. this._scaleByDistance,
  818. );
  819. },
  820. },
  821. /**
  822. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>translucencyByDistance</code> property. Alternatively a string or object defining a vec4 style can be used.
  823. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  824. * <p>
  825. * The expression must return a <code>Cartesian4</code>.
  826. * </p>
  827. * <p>
  828. * This expression is only applicable to point features in a Vector tile.
  829. * </p>
  830. *
  831. * @memberof Cesium3DTileStyle.prototype
  832. *
  833. * @type {StyleExpression}
  834. *
  835. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  836. *
  837. * @example
  838. * const style = new Cesium.Cesium3DTileStyle();
  839. * // Override translucencyByDistance expression with a string
  840. * style.translucencyByDistance = 'vec4(1.5e2, 1.0, 1.5e7, 0.2)';
  841. * style.translucencyByDistance.evaluate(feature); // returns a Cartesian4
  842. */
  843. translucencyByDistance: {
  844. get: function () {
  845. return this._translucencyByDistance;
  846. },
  847. set: function (value) {
  848. this._translucencyByDistance = getExpression(this, value);
  849. this._style.translucencyByDistance = getJsonFromExpression(
  850. this._translucencyByDistance,
  851. );
  852. },
  853. },
  854. /**
  855. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>distanceDisplayCondition</code> property. Alternatively a string or object defining a vec2 style can be used.
  856. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  857. * <p>
  858. * The expression must return a <code>Cartesian2</code>.
  859. * </p>
  860. * <p>
  861. * This expression is only applicable to point features in a Vector tile.
  862. * </p>
  863. *
  864. * @memberof Cesium3DTileStyle.prototype
  865. *
  866. * @type {StyleExpression}
  867. *
  868. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  869. *
  870. * @example
  871. * const style = new Cesium.Cesium3DTileStyle();
  872. * // Override distanceDisplayCondition expression with a string
  873. * style.distanceDisplayCondition = 'vec2(0.0, 5.5e6)';
  874. * style.distanceDisplayCondition.evaluate(feature); // returns a Cartesian2
  875. */
  876. distanceDisplayCondition: {
  877. get: function () {
  878. return this._distanceDisplayCondition;
  879. },
  880. set: function (value) {
  881. this._distanceDisplayCondition = getExpression(this, value);
  882. this._style.distanceDisplayCondition = getJsonFromExpression(
  883. this._distanceDisplayCondition,
  884. );
  885. },
  886. },
  887. /**
  888. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>heightOffset</code> property. Alternatively a string or object defining a number style can be used.
  889. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  890. * <p>
  891. * The expression must return a <code>Number</code>.
  892. * </p>
  893. * <p>
  894. * This expression is only applicable to point features in a Vector tile.
  895. * </p>
  896. *
  897. * @memberof Cesium3DTileStyle.prototype
  898. *
  899. * @type {StyleExpression}
  900. *
  901. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  902. *
  903. * @example
  904. * const style = new Cesium.Cesium3DTileStyle();
  905. * // Override heightOffset expression with a string
  906. * style.heightOffset = '2.0';
  907. *
  908. * @example
  909. * const style = new Cesium.Cesium3DTileStyle();
  910. * // Override heightOffset expression with a condition
  911. * style.heightOffset = {
  912. * conditions : [
  913. * ['${height} > 2', '4.0'],
  914. * ['true', '2.0']
  915. * ]
  916. * };
  917. */
  918. heightOffset: {
  919. get: function () {
  920. return this._heightOffset;
  921. },
  922. set: function (value) {
  923. this._heightOffset = getExpression(this, value);
  924. this._style.heightOffset = getJsonFromExpression(this._heightOffset);
  925. },
  926. },
  927. /**
  928. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>anchorLineEnabled</code> property. Alternatively a string or object defining a boolean style can be used.
  929. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  930. * <p>
  931. * The expression must return a <code>Boolean</code>.
  932. * </p>
  933. * <p>
  934. * This expression is only applicable to point features in a Vector tile.
  935. * </p>
  936. *
  937. * @memberof Cesium3DTileStyle.prototype
  938. *
  939. * @type {StyleExpression}
  940. *
  941. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  942. *
  943. * @example
  944. * const style = new Cesium.Cesium3DTileStyle();
  945. * // Override anchorLineEnabled expression with a string
  946. * style.anchorLineEnabled = 'true';
  947. *
  948. * @example
  949. * const style = new Cesium.Cesium3DTileStyle();
  950. * // Override anchorLineEnabled expression with a condition
  951. * style.anchorLineEnabled = {
  952. * conditions : [
  953. * ['${height} > 2', 'true'],
  954. * ['true', 'false']
  955. * ]
  956. * };
  957. */
  958. anchorLineEnabled: {
  959. get: function () {
  960. return this._anchorLineEnabled;
  961. },
  962. set: function (value) {
  963. this._anchorLineEnabled = getExpression(this, value);
  964. this._style.anchorLineEnabled = getJsonFromExpression(
  965. this._anchorLineEnabled,
  966. );
  967. },
  968. },
  969. /**
  970. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>anchorLineColor</code> property. Alternatively a string or object defining a color style can be used.
  971. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  972. * <p>
  973. * The expression must return a <code>Color</code>.
  974. * </p>
  975. * <p>
  976. * This expression is only applicable to point features in a Vector tile.
  977. * </p>
  978. *
  979. * @memberof Cesium3DTileStyle.prototype
  980. *
  981. * @type {StyleExpression}
  982. *
  983. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  984. *
  985. * @example
  986. * const style = new Cesium.Cesium3DTileStyle();
  987. * // Override anchorLineColor expression with a string
  988. * style.anchorLineColor = 'color("blue")';
  989. *
  990. * @example
  991. * const style = new Cesium.Cesium3DTileStyle();
  992. * // Override anchorLineColor expression with a condition
  993. * style.anchorLineColor = {
  994. * conditions : [
  995. * ['${height} > 2', 'color("cyan")'],
  996. * ['true', 'color("blue")']
  997. * ]
  998. * };
  999. */
  1000. anchorLineColor: {
  1001. get: function () {
  1002. return this._anchorLineColor;
  1003. },
  1004. set: function (value) {
  1005. this._anchorLineColor = getExpression(this, value);
  1006. this._style.anchorLineColor = getJsonFromExpression(
  1007. this._anchorLineColor,
  1008. );
  1009. },
  1010. },
  1011. /**
  1012. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>image</code> property. Alternatively a string or object defining a string style can be used.
  1013. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  1014. * <p>
  1015. * The expression must return a <code>String</code>.
  1016. * </p>
  1017. * <p>
  1018. * This expression is only applicable to point features in a Vector tile.
  1019. * </p>
  1020. *
  1021. * @memberof Cesium3DTileStyle.prototype
  1022. *
  1023. * @type {StyleExpression}
  1024. *
  1025. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  1026. *
  1027. * @example
  1028. * const style = new Cesium3DTileStyle({
  1029. * image : '(${Temperature} > 90) ? "/url/to/image1" : "/url/to/image2"'
  1030. * });
  1031. * style.image.evaluate(feature); // returns a String
  1032. *
  1033. * @example
  1034. * const style = new Cesium.Cesium3DTileStyle();
  1035. * // Override image expression with a custom function
  1036. * style.image = {
  1037. * evaluate : function(feature) {
  1038. * return '/url/to/image';
  1039. * }
  1040. * };
  1041. */
  1042. image: {
  1043. get: function () {
  1044. return this._image;
  1045. },
  1046. set: function (value) {
  1047. this._image = getExpression(this, value);
  1048. this._style.image = getJsonFromExpression(this._image);
  1049. },
  1050. },
  1051. /**
  1052. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>disableDepthTestDistance</code> property. Alternatively a string or object defining a number style can be used.
  1053. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  1054. * <p>
  1055. * The expression must return a <code>Number</code>.
  1056. * </p>
  1057. * <p>
  1058. * This expression is only applicable to point features in a Vector tile.
  1059. * </p>
  1060. *
  1061. * @memberof Cesium3DTileStyle.prototype
  1062. *
  1063. * @type {StyleExpression}
  1064. *
  1065. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  1066. *
  1067. * @example
  1068. * const style = new Cesium.Cesium3DTileStyle();
  1069. * // Override disableDepthTestDistance expression with a string
  1070. * style.disableDepthTestDistance = '1000.0';
  1071. * style.disableDepthTestDistance.evaluate(feature); // returns a Number
  1072. */
  1073. disableDepthTestDistance: {
  1074. get: function () {
  1075. return this._disableDepthTestDistance;
  1076. },
  1077. set: function (value) {
  1078. this._disableDepthTestDistance = getExpression(this, value);
  1079. this._style.disableDepthTestDistance = getJsonFromExpression(
  1080. this._disableDepthTestDistance,
  1081. );
  1082. },
  1083. },
  1084. /**
  1085. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>horizontalOrigin</code> property. Alternatively a string or object defining a number style can be used.
  1086. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  1087. * <p>
  1088. * The expression must return a <code>HorizontalOrigin</code>.
  1089. * </p>
  1090. * <p>
  1091. * This expression is only applicable to point features in a Vector tile.
  1092. * </p>
  1093. *
  1094. * @memberof Cesium3DTileStyle.prototype
  1095. *
  1096. * @type {StyleExpression}
  1097. *
  1098. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  1099. *
  1100. * @example
  1101. * const style = new Cesium3DTileStyle({
  1102. * horizontalOrigin : HorizontalOrigin.LEFT
  1103. * });
  1104. * style.horizontalOrigin.evaluate(feature); // returns a HorizontalOrigin
  1105. *
  1106. * @example
  1107. * const style = new Cesium.Cesium3DTileStyle();
  1108. * // Override horizontalOrigin expression with a custom function
  1109. * style.horizontalOrigin = {
  1110. * evaluate : function(feature) {
  1111. * return HorizontalOrigin.CENTER;
  1112. * }
  1113. * };
  1114. */
  1115. horizontalOrigin: {
  1116. get: function () {
  1117. return this._horizontalOrigin;
  1118. },
  1119. set: function (value) {
  1120. this._horizontalOrigin = getExpression(this, value);
  1121. this._style.horizontalOrigin = getJsonFromExpression(
  1122. this._horizontalOrigin,
  1123. );
  1124. },
  1125. },
  1126. /**
  1127. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>verticalOrigin</code> property. Alternatively a string or object defining a number style can be used.
  1128. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  1129. * <p>
  1130. * The expression must return a <code>VerticalOrigin</code>.
  1131. * </p>
  1132. * <p>
  1133. * This expression is only applicable to point features in a Vector tile.
  1134. * </p>
  1135. *
  1136. * @memberof Cesium3DTileStyle.prototype
  1137. *
  1138. * @type {StyleExpression}
  1139. *
  1140. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  1141. *
  1142. * @example
  1143. * const style = new Cesium3DTileStyle({
  1144. * verticalOrigin : VerticalOrigin.TOP
  1145. * });
  1146. * style.verticalOrigin.evaluate(feature); // returns a VerticalOrigin
  1147. *
  1148. * @example
  1149. * const style = new Cesium.Cesium3DTileStyle();
  1150. * // Override verticalOrigin expression with a custom function
  1151. * style.verticalOrigin = {
  1152. * evaluate : function(feature) {
  1153. * return VerticalOrigin.CENTER;
  1154. * }
  1155. * };
  1156. */
  1157. verticalOrigin: {
  1158. get: function () {
  1159. return this._verticalOrigin;
  1160. },
  1161. set: function (value) {
  1162. this._verticalOrigin = getExpression(this, value);
  1163. this._style.verticalOrigin = getJsonFromExpression(this._verticalOrigin);
  1164. },
  1165. },
  1166. /**
  1167. Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>labelHorizontalOrigin</code> property. Alternatively a string or object defining a number style can be used.
  1168. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  1169. * <p>
  1170. * The expression must return a <code>HorizontalOrigin</code>.
  1171. * </p>
  1172. * <p>
  1173. * This expression is only applicable to point features in a Vector tile.
  1174. * </p>
  1175. *
  1176. * @memberof Cesium3DTileStyle.prototype
  1177. *
  1178. * @type {StyleExpression}
  1179. *
  1180. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  1181. *
  1182. * @example
  1183. * const style = new Cesium3DTileStyle({
  1184. * labelHorizontalOrigin : HorizontalOrigin.LEFT
  1185. * });
  1186. * style.labelHorizontalOrigin.evaluate(feature); // returns a HorizontalOrigin
  1187. *
  1188. * @example
  1189. * const style = new Cesium.Cesium3DTileStyle();
  1190. * // Override labelHorizontalOrigin expression with a custom function
  1191. * style.labelHorizontalOrigin = {
  1192. * evaluate : function(feature) {
  1193. * return HorizontalOrigin.CENTER;
  1194. * }
  1195. * };
  1196. */
  1197. labelHorizontalOrigin: {
  1198. get: function () {
  1199. return this._labelHorizontalOrigin;
  1200. },
  1201. set: function (value) {
  1202. this._labelHorizontalOrigin = getExpression(this, value);
  1203. this._style.labelHorizontalOrigin = getJsonFromExpression(
  1204. this._labelHorizontalOrigin,
  1205. );
  1206. },
  1207. },
  1208. /**
  1209. * Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>labelVerticalOrigin</code> property. Alternatively a string or object defining a number style can be used.
  1210. * The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
  1211. * <p>
  1212. * The expression must return a <code>VerticalOrigin</code>.
  1213. * </p>
  1214. * <p>
  1215. * This expression is only applicable to point features in a Vector tile.
  1216. * </p>
  1217. *
  1218. * @memberof Cesium3DTileStyle.prototype
  1219. *
  1220. * @type {StyleExpression}
  1221. *
  1222. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  1223. *
  1224. * @example
  1225. * const style = new Cesium3DTileStyle({
  1226. * labelVerticalOrigin : VerticalOrigin.TOP
  1227. * });
  1228. * style.labelVerticalOrigin.evaluate(feature); // returns a VerticalOrigin
  1229. *
  1230. * @example
  1231. * const style = new Cesium.Cesium3DTileStyle();
  1232. * // Override labelVerticalOrigin expression with a custom function
  1233. * style.labelVerticalOrigin = {
  1234. * evaluate : function(feature) {
  1235. * return VerticalOrigin.CENTER;
  1236. * }
  1237. * };
  1238. */
  1239. labelVerticalOrigin: {
  1240. get: function () {
  1241. return this._labelVerticalOrigin;
  1242. },
  1243. set: function (value) {
  1244. this._labelVerticalOrigin = getExpression(this, value);
  1245. this._style.labelVerticalOrigin = getJsonFromExpression(
  1246. this._labelVerticalOrigin,
  1247. );
  1248. },
  1249. },
  1250. /**
  1251. * Internal-only, supported in Vector Tiles with 3D Tiles 2.0.
  1252. * @memberof Cesium3DTileStyle.prototype
  1253. * @type {StyleExpression}
  1254. * @ignore
  1255. */
  1256. lineWidth: {
  1257. get: function () {
  1258. return this._lineWidth;
  1259. },
  1260. set: function (value) {
  1261. this._lineWidth = getExpression(this, value);
  1262. this._style.lineWidth = getJsonFromExpression(this._lineWidth);
  1263. },
  1264. },
  1265. /**
  1266. * Gets or sets the object containing application-specific expression that can be explicitly
  1267. * evaluated, e.g., for display in a UI.
  1268. *
  1269. * @memberof Cesium3DTileStyle.prototype
  1270. *
  1271. * @type {StyleExpression}
  1272. *
  1273. * @example
  1274. * const style = new Cesium3DTileStyle({
  1275. * meta : {
  1276. * description : '"Building id ${id} has height ${Height}."'
  1277. * }
  1278. * });
  1279. * style.meta.description.evaluate(feature); // returns a String with the substituted variables
  1280. */
  1281. meta: {
  1282. get: function () {
  1283. return this._meta;
  1284. },
  1285. set: function (value) {
  1286. this._meta = value;
  1287. },
  1288. },
  1289. });
  1290. /**
  1291. * Asynchronously creates a Cesium3DTileStyle from a url.
  1292. *
  1293. * @param {Resource|string} url The url of the style to be loaded.
  1294. *
  1295. * @returns {Promise<Cesium3DTileStyle>} A promise which resolves to the created style
  1296. *
  1297. * @private
  1298. */
  1299. Cesium3DTileStyle.fromUrl = function (url) {
  1300. //>>includeStart('debug', pragmas.debug);
  1301. if (!defined(url)) {
  1302. throw new DeveloperError("url is required");
  1303. }
  1304. //>>includeEnd('debug');
  1305. const resource = Resource.createIfNeeded(url);
  1306. return resource.fetchJson(url).then(function (styleJson) {
  1307. return new Cesium3DTileStyle(styleJson);
  1308. });
  1309. };
  1310. /**
  1311. * Gets the color shader function for this style.
  1312. *
  1313. * @param {string} functionSignature Signature of the generated function.
  1314. * @param {object} variableSubstitutionMap Maps variable names to shader variable names.
  1315. * @param {object} shaderState Stores information about the generated shader function, including whether it is translucent.
  1316. *
  1317. * @returns {string} The shader function.
  1318. *
  1319. * @private
  1320. */
  1321. Cesium3DTileStyle.prototype.getColorShaderFunction = function (
  1322. functionSignature,
  1323. variableSubstitutionMap,
  1324. shaderState,
  1325. ) {
  1326. if (this._colorShaderFunctionReady) {
  1327. shaderState.translucent = this._colorShaderTranslucent;
  1328. // Return the cached result, may be undefined
  1329. return this._colorShaderFunction;
  1330. }
  1331. this._colorShaderFunctionReady = true;
  1332. if (defined(this.color) && defined(this.color.getShaderFunction)) {
  1333. this._colorShaderFunction = this.color.getShaderFunction(
  1334. functionSignature,
  1335. variableSubstitutionMap,
  1336. shaderState,
  1337. "vec4",
  1338. );
  1339. } else {
  1340. this._colorShaderFunction = undefined;
  1341. }
  1342. this._colorShaderTranslucent = shaderState.translucent;
  1343. return this._colorShaderFunction;
  1344. };
  1345. /**
  1346. * Gets the show shader function for this style.
  1347. *
  1348. * @param {string} functionSignature Signature of the generated function.
  1349. * @param {object} variableSubstitutionMap Maps variable names to shader variable names.
  1350. * @param {object} shaderState Stores information about the generated shader function, including whether it is translucent.
  1351. *
  1352. * @returns {string} The shader function.
  1353. *
  1354. * @private
  1355. */
  1356. Cesium3DTileStyle.prototype.getShowShaderFunction = function (
  1357. functionSignature,
  1358. variableSubstitutionMap,
  1359. shaderState,
  1360. ) {
  1361. if (this._showShaderFunctionReady) {
  1362. // Return the cached result, may be undefined
  1363. return this._showShaderFunction;
  1364. }
  1365. this._showShaderFunctionReady = true;
  1366. if (defined(this.show) && defined(this.show.getShaderFunction)) {
  1367. this._showShaderFunction = this.show.getShaderFunction(
  1368. functionSignature,
  1369. variableSubstitutionMap,
  1370. shaderState,
  1371. "bool",
  1372. );
  1373. } else {
  1374. this._showShaderFunction = undefined;
  1375. }
  1376. return this._showShaderFunction;
  1377. };
  1378. /**
  1379. * Gets the pointSize shader function for this style.
  1380. *
  1381. * @param {string} functionSignature Signature of the generated function.
  1382. * @param {object} variableSubstitutionMap Maps variable names to shader variable names.
  1383. * @param {object} shaderState Stores information about the generated shader function, including whether it is translucent.
  1384. *
  1385. * @returns {string} The shader function.
  1386. *
  1387. * @private
  1388. */
  1389. Cesium3DTileStyle.prototype.getPointSizeShaderFunction = function (
  1390. functionSignature,
  1391. variableSubstitutionMap,
  1392. shaderState,
  1393. ) {
  1394. if (this._pointSizeShaderFunctionReady) {
  1395. // Return the cached result, may be undefined
  1396. return this._pointSizeShaderFunction;
  1397. }
  1398. this._pointSizeShaderFunctionReady = true;
  1399. if (defined(this.pointSize) && defined(this.pointSize.getShaderFunction)) {
  1400. this._pointSizeShaderFunction = this.pointSize.getShaderFunction(
  1401. functionSignature,
  1402. variableSubstitutionMap,
  1403. shaderState,
  1404. "float",
  1405. );
  1406. } else {
  1407. this._pointSizeShaderFunction = undefined;
  1408. }
  1409. return this._pointSizeShaderFunction;
  1410. };
  1411. /**
  1412. * Gets the variables used by the style.
  1413. *
  1414. * @returns {string[]} The variables used by the style.
  1415. *
  1416. * @private
  1417. */
  1418. Cesium3DTileStyle.prototype.getVariables = function () {
  1419. let variables = [];
  1420. if (defined(this.color) && defined(this.color.getVariables)) {
  1421. addAllToArray(variables, this.color.getVariables());
  1422. }
  1423. if (defined(this.show) && defined(this.show.getVariables)) {
  1424. addAllToArray(variables, this.show.getVariables());
  1425. }
  1426. if (defined(this.pointSize) && defined(this.pointSize.getVariables)) {
  1427. addAllToArray(variables, this.pointSize.getVariables());
  1428. }
  1429. // Remove duplicates
  1430. variables = variables.filter(function (variable, index, variables) {
  1431. return variables.indexOf(variable) === index;
  1432. });
  1433. return variables;
  1434. };
  1435. export default Cesium3DTileStyle;