Cesium3DTileStyle.js 49 KB

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