CreditDisplay.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. import AssociativeArray from "../Core/AssociativeArray.js";
  2. import buildModuleUrl from "../Core/buildModuleUrl.js";
  3. import Check from "../Core/Check.js";
  4. import Credit from "../Core/Credit.js";
  5. import defaultValue from "../Core/defaultValue.js";
  6. import defined from "../Core/defined.js";
  7. import deprecationWarning from "../Core/deprecationWarning.js";
  8. import destroyObject from "../Core/destroyObject.js";
  9. import Uri from "urijs";
  10. const mobileWidth = 576;
  11. const lightboxHeight = 100;
  12. const textColor = "#ffffff";
  13. const highlightColor = "#48b";
  14. /**
  15. * Used to sort the credits by frequency of appearance
  16. * when they are later displayed.
  17. *
  18. * @alias CreditDisplay.CreditDisplayElement
  19. * @constructor
  20. *
  21. * @private
  22. */
  23. function CreditDisplayElement(credit, count) {
  24. this.credit = credit;
  25. this.count = defaultValue(count, 1);
  26. }
  27. function contains(credits, credit) {
  28. const len = credits.length;
  29. for (let i = 0; i < len; i++) {
  30. const existingCredit = credits[i];
  31. if (Credit.equals(existingCredit, credit)) {
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. function swapCesiumCredit(creditDisplay) {
  38. // We don't want to clutter the screen with the Cesium logo and the Cesium ion
  39. // logo at the same time. Since the ion logo is required, we just replace the
  40. // Cesium logo or add the logo if the Cesium one was removed.
  41. const previousCredit = creditDisplay._previousCesiumCredit;
  42. const currentCredit = creditDisplay._currentCesiumCredit;
  43. if (Credit.equals(currentCredit, previousCredit)) {
  44. return;
  45. }
  46. if (defined(previousCredit)) {
  47. creditDisplay._cesiumCreditContainer.removeChild(previousCredit.element);
  48. }
  49. if (defined(currentCredit)) {
  50. creditDisplay._cesiumCreditContainer.appendChild(currentCredit.element);
  51. }
  52. creditDisplay._previousCesiumCredit = currentCredit;
  53. }
  54. const delimiterClassName = "cesium-credit-delimiter";
  55. function createDelimiterElement(delimiter) {
  56. const delimiterElement = document.createElement("span");
  57. delimiterElement.textContent = delimiter;
  58. delimiterElement.className = delimiterClassName;
  59. return delimiterElement;
  60. }
  61. function createCreditElement(element, elementWrapperTagName) {
  62. // may need to wrap the credit in another element
  63. if (defined(elementWrapperTagName)) {
  64. const wrapper = document.createElement(elementWrapperTagName);
  65. wrapper._creditId = element._creditId;
  66. wrapper.appendChild(element);
  67. element = wrapper;
  68. }
  69. return element;
  70. }
  71. function displayCredits(container, credits, delimiter, elementWrapperTagName) {
  72. const childNodes = container.childNodes;
  73. let domIndex = -1;
  74. // Sort the credits such that more frequent credits appear first
  75. credits.sort(function (credit1, credit2) {
  76. return credit2.count - credit1.count;
  77. });
  78. for (let creditIndex = 0; creditIndex < credits.length; ++creditIndex) {
  79. const credit = credits[creditIndex].credit;
  80. if (defined(credit)) {
  81. domIndex = creditIndex;
  82. if (defined(delimiter)) {
  83. // credits may be separated by delimiters
  84. domIndex *= 2;
  85. if (creditIndex > 0) {
  86. const delimiterDomIndex = domIndex - 1;
  87. if (childNodes.length <= delimiterDomIndex) {
  88. container.appendChild(createDelimiterElement(delimiter));
  89. } else {
  90. const existingDelimiter = childNodes[delimiterDomIndex];
  91. if (existingDelimiter.className !== delimiterClassName) {
  92. container.replaceChild(
  93. createDelimiterElement(delimiter),
  94. existingDelimiter
  95. );
  96. }
  97. }
  98. }
  99. }
  100. const element = credit.element;
  101. // check to see if the correct credit is in the right place
  102. if (childNodes.length <= domIndex) {
  103. container.appendChild(
  104. createCreditElement(element, elementWrapperTagName)
  105. );
  106. } else {
  107. const existingElement = childNodes[domIndex];
  108. if (existingElement._creditId !== credit._id) {
  109. // not the right credit, swap it in
  110. container.replaceChild(
  111. createCreditElement(element, elementWrapperTagName),
  112. existingElement
  113. );
  114. }
  115. }
  116. }
  117. }
  118. // any remaining nodes in the container are unnecessary
  119. ++domIndex;
  120. while (domIndex < childNodes.length) {
  121. container.removeChild(childNodes[domIndex]);
  122. }
  123. }
  124. function styleLightboxContainer(that) {
  125. const lightboxCredits = that._lightboxCredits;
  126. const width = that.viewport.clientWidth;
  127. const height = that.viewport.clientHeight;
  128. if (width !== that._lastViewportWidth) {
  129. if (width < mobileWidth) {
  130. lightboxCredits.className =
  131. "cesium-credit-lightbox cesium-credit-lightbox-mobile";
  132. lightboxCredits.style.marginTop = "0";
  133. } else {
  134. lightboxCredits.className =
  135. "cesium-credit-lightbox cesium-credit-lightbox-expanded";
  136. lightboxCredits.style.marginTop = `${Math.floor(
  137. (height - lightboxCredits.clientHeight) * 0.5
  138. )}px`;
  139. }
  140. that._lastViewportWidth = width;
  141. }
  142. if (width >= mobileWidth && height !== that._lastViewportHeight) {
  143. lightboxCredits.style.marginTop = `${Math.floor(
  144. (height - lightboxCredits.clientHeight) * 0.5
  145. )}px`;
  146. that._lastViewportHeight = height;
  147. }
  148. }
  149. function addStyle(selector, styles) {
  150. let style = `${selector} {`;
  151. for (const attribute in styles) {
  152. if (styles.hasOwnProperty(attribute)) {
  153. style += `${attribute}: ${styles[attribute]}; `;
  154. }
  155. }
  156. style += " }\n";
  157. return style;
  158. }
  159. function appendCss(container) {
  160. let style = "";
  161. style += addStyle(".cesium-credit-lightbox-overlay", {
  162. display: "none",
  163. "z-index": "1", //must be at least 1 to draw over top other Cesium widgets
  164. position: "absolute",
  165. top: "0",
  166. left: "0",
  167. width: "100%",
  168. height: "100%",
  169. "background-color": "rgba(80, 80, 80, 0.8)",
  170. });
  171. style += addStyle(".cesium-credit-lightbox", {
  172. "background-color": "#303336",
  173. color: textColor,
  174. position: "relative",
  175. "min-height": `${lightboxHeight}px`,
  176. margin: "auto",
  177. });
  178. style += addStyle(
  179. ".cesium-credit-lightbox > ul > li a, .cesium-credit-lightbox > ul > li a:visited",
  180. {
  181. color: textColor,
  182. }
  183. );
  184. style += addStyle(".cesium-credit-lightbox > ul > li a:hover", {
  185. color: highlightColor,
  186. });
  187. style += addStyle(".cesium-credit-lightbox.cesium-credit-lightbox-expanded", {
  188. border: "1px solid #444",
  189. "border-radius": "5px",
  190. "max-width": "370px",
  191. });
  192. style += addStyle(".cesium-credit-lightbox.cesium-credit-lightbox-mobile", {
  193. height: "100%",
  194. width: "100%",
  195. });
  196. style += addStyle(".cesium-credit-lightbox-title", {
  197. padding: "20px 20px 0 20px",
  198. });
  199. style += addStyle(".cesium-credit-lightbox-close", {
  200. "font-size": "18pt",
  201. cursor: "pointer",
  202. position: "absolute",
  203. top: "0",
  204. right: "6px",
  205. color: textColor,
  206. });
  207. style += addStyle(".cesium-credit-lightbox-close:hover", {
  208. color: highlightColor,
  209. });
  210. style += addStyle(".cesium-credit-lightbox > ul", {
  211. margin: "0",
  212. padding: "12px 20px 12px 40px",
  213. "font-size": "13px",
  214. });
  215. style += addStyle(".cesium-credit-lightbox > ul > li", {
  216. "padding-bottom": "6px",
  217. });
  218. style += addStyle(".cesium-credit-lightbox > ul > li *", {
  219. padding: "0",
  220. margin: "0",
  221. });
  222. style += addStyle(".cesium-credit-expand-link", {
  223. "padding-left": "5px",
  224. cursor: "pointer",
  225. "text-decoration": "underline",
  226. color: textColor,
  227. });
  228. style += addStyle(".cesium-credit-expand-link:hover", {
  229. color: highlightColor,
  230. });
  231. style += addStyle(".cesium-credit-text", {
  232. color: textColor,
  233. });
  234. style += addStyle(
  235. ".cesium-credit-textContainer *, .cesium-credit-logoContainer *",
  236. {
  237. display: "inline",
  238. }
  239. );
  240. function getShadowRoot(container) {
  241. if (container.shadowRoot) {
  242. return container.shadowRoot;
  243. }
  244. if (container.getRootNode) {
  245. const root = container.getRootNode();
  246. if (root instanceof ShadowRoot) {
  247. return root;
  248. }
  249. }
  250. return undefined;
  251. }
  252. const shadowRootOrDocumentHead = defaultValue(
  253. getShadowRoot(container),
  254. document.head
  255. );
  256. const css = document.createElement("style");
  257. css.innerHTML = style;
  258. shadowRootOrDocumentHead.appendChild(css);
  259. }
  260. /**
  261. * The credit display is responsible for displaying credits on screen.
  262. *
  263. * @param {HTMLElement} container The HTML element where credits will be displayed
  264. * @param {string} [delimiter= ' • '] The string to separate text credits
  265. * @param {HTMLElement} [viewport=document.body] The HTML element that will contain the credits popup
  266. *
  267. * @alias CreditDisplay
  268. * @constructor
  269. *
  270. * @example
  271. * // Add a credit with a tooltip, image and link to display onscreen
  272. * const credit = new Cesium.Credit(`<a href="https://cesium.com/" target="_blank"><img src="/images/cesium_logo.png" title="Cesium"/></a>`, true);
  273. * viewer.creditDisplay.addStaticCredit(credit);
  274. *
  275. * @example
  276. * // Add a credit with a plaintext link to display in the lightbox
  277. * const credit = new Cesium.Credit('<a href="https://cesium.com/" target="_blank">Cesium</a>');
  278. * viewer.creditDisplay.addStaticCredit(credit);
  279. */
  280. function CreditDisplay(container, delimiter, viewport) {
  281. //>>includeStart('debug', pragmas.debug);
  282. Check.defined("container", container);
  283. //>>includeEnd('debug');
  284. const that = this;
  285. viewport = defaultValue(viewport, document.body);
  286. const lightbox = document.createElement("div");
  287. lightbox.className = "cesium-credit-lightbox-overlay";
  288. viewport.appendChild(lightbox);
  289. const lightboxCredits = document.createElement("div");
  290. lightboxCredits.className = "cesium-credit-lightbox";
  291. lightbox.appendChild(lightboxCredits);
  292. function hideLightbox(event) {
  293. if (lightboxCredits.contains(event.target)) {
  294. return;
  295. }
  296. that.hideLightbox();
  297. }
  298. lightbox.addEventListener("click", hideLightbox, false);
  299. const title = document.createElement("div");
  300. title.className = "cesium-credit-lightbox-title";
  301. title.textContent = "Data provided by:";
  302. lightboxCredits.appendChild(title);
  303. const closeButton = document.createElement("a");
  304. closeButton.onclick = this.hideLightbox.bind(this);
  305. closeButton.innerHTML = "&times;";
  306. closeButton.className = "cesium-credit-lightbox-close";
  307. lightboxCredits.appendChild(closeButton);
  308. const creditList = document.createElement("ul");
  309. lightboxCredits.appendChild(creditList);
  310. const cesiumCreditContainer = document.createElement("div");
  311. cesiumCreditContainer.className = "cesium-credit-logoContainer";
  312. cesiumCreditContainer.style.display = "inline";
  313. container.appendChild(cesiumCreditContainer);
  314. const screenContainer = document.createElement("div");
  315. screenContainer.className = "cesium-credit-textContainer";
  316. screenContainer.style.display = "inline";
  317. container.appendChild(screenContainer);
  318. const expandLink = document.createElement("a");
  319. expandLink.className = "cesium-credit-expand-link";
  320. expandLink.onclick = this.showLightbox.bind(this);
  321. expandLink.textContent = "Data attribution";
  322. container.appendChild(expandLink);
  323. appendCss(container);
  324. const cesiumCredit = Credit.clone(CreditDisplay.cesiumCredit);
  325. this._delimiter = defaultValue(delimiter, " • ");
  326. this._screenContainer = screenContainer;
  327. this._cesiumCreditContainer = cesiumCreditContainer;
  328. this._lastViewportHeight = undefined;
  329. this._lastViewportWidth = undefined;
  330. this._lightboxCredits = lightboxCredits;
  331. this._creditList = creditList;
  332. this._lightbox = lightbox;
  333. this._hideLightbox = hideLightbox;
  334. this._expandLink = expandLink;
  335. this._expanded = false;
  336. this._staticCredits = [];
  337. this._cesiumCredit = cesiumCredit;
  338. this._previousCesiumCredit = undefined;
  339. this._currentCesiumCredit = cesiumCredit;
  340. this._creditDisplayElementPool = [];
  341. this._creditDisplayElementIndex = 0;
  342. this._currentFrameCredits = {
  343. screenCredits: new AssociativeArray(),
  344. lightboxCredits: new AssociativeArray(),
  345. };
  346. this._defaultCredit = undefined;
  347. this.viewport = viewport;
  348. /**
  349. * The HTML element where credits will be displayed.
  350. * @type {HTMLElement}
  351. */
  352. this.container = container;
  353. }
  354. function setCredit(creditDisplay, credits, credit, count) {
  355. count = defaultValue(count, 1);
  356. let creditDisplayElement = credits.get(credit.id);
  357. if (!defined(creditDisplayElement)) {
  358. const pool = creditDisplay._creditDisplayElementPool;
  359. const poolIndex = creditDisplay._creditDisplayElementPoolIndex;
  360. if (poolIndex < pool.length) {
  361. creditDisplayElement = pool[poolIndex];
  362. creditDisplayElement.credit = credit;
  363. creditDisplayElement.count = count;
  364. } else {
  365. creditDisplayElement = new CreditDisplayElement(credit, count);
  366. pool.push(creditDisplayElement);
  367. }
  368. ++creditDisplay._creditDisplayElementPoolIndex;
  369. credits.set(credit.id, creditDisplayElement);
  370. } else if (creditDisplayElement.count < Number.MAX_VALUE) {
  371. creditDisplayElement.count += count;
  372. }
  373. }
  374. /**
  375. * Adds a credit to the list of current credits to be displayed in the credit container
  376. * for the next frame
  377. *
  378. * @param {Credit} credit The credit to display
  379. * @deprecated
  380. */
  381. CreditDisplay.prototype.addCredit = function (credit) {
  382. deprecationWarning(
  383. "CreditDisplay.addCredit",
  384. "CreditDisplay.addCredit was deprecated in CesiumJS 1.105. It will be removed in CesiumJS 1.107. Use CreditDisplay.addCreditToNextFrame instead."
  385. );
  386. this.addCreditToNextFrame(credit);
  387. };
  388. /**
  389. * Adds a {@link Credit} that will show on screen or in the lightbox until
  390. * the next frame. This is mostly for internal use. Use {@link CreditDisplay.addStaticCredit} to add a persistent credit to the screen.
  391. *
  392. * @see CreditDisplay.addStaticCredit
  393. *
  394. * @param {Credit} credit The credit to display in the next frame.
  395. */
  396. CreditDisplay.prototype.addCreditToNextFrame = function (credit) {
  397. //>>includeStart('debug', pragmas.debug);
  398. Check.defined("credit", credit);
  399. //>>includeEnd('debug');
  400. if (credit._isIon) {
  401. // If this is the an ion logo credit from the ion server
  402. // Just use the default credit (which is identical) to avoid blinking
  403. if (!defined(this._defaultCredit)) {
  404. this._defaultCredit = Credit.clone(getDefaultCredit());
  405. }
  406. this._currentCesiumCredit = this._defaultCredit;
  407. return;
  408. }
  409. let credits;
  410. if (!credit.showOnScreen) {
  411. credits = this._currentFrameCredits.lightboxCredits;
  412. } else {
  413. credits = this._currentFrameCredits.screenCredits;
  414. }
  415. setCredit(this, credits, credit);
  416. };
  417. /**
  418. * Adds credits that will persist until they are removed
  419. *
  420. * @param {Credit} credit The credit to added to defaults
  421. *
  422. * @deprecated
  423. */
  424. CreditDisplay.prototype.addDefaultCredit = function (credit) {
  425. //>>includeStart('debug', pragmas.debug);
  426. Check.defined("credit", credit);
  427. //>>includeEnd('debug');
  428. deprecationWarning(
  429. "CreditDisplay.addDefaultCredit",
  430. "CreditDisplay.addDefaultCredit was deprecated in CesiumJS 1.105. It will be removed in CesiumJS 1.107. Use CreditDisplay.addStaticCredit instead."
  431. );
  432. const defaultCredits = this._staticCredits;
  433. if (!contains(defaultCredits, credit)) {
  434. credit.showOnScreen = true;
  435. defaultCredits.push(credit);
  436. }
  437. };
  438. /**
  439. * Adds a {@link Credit} that will show on screen or in the lightbox until removed with {@link CreditDisplay.removeStaticCredit}.
  440. *
  441. * @param {Credit} credit The credit to added
  442. *
  443. * @example
  444. * // Add a credit with a tooltip, image and link to display onscreen
  445. * const credit = new Cesium.Credit(`<a href="https://cesium.com/" target="_blank"><img src="/images/cesium_logo.png" title="Cesium"/></a>`, true);
  446. * viewer.creditDisplay.addStaticCredit(credit);
  447. *
  448. * @example
  449. * // Add a credit with a plaintext link to display in the lightbox
  450. * const credit = new Cesium.Credit('<a href="https://cesium.com/" target="_blank">Cesium</a>');
  451. * viewer.creditDisplay.addStaticCredit(credit);
  452. */
  453. CreditDisplay.prototype.addStaticCredit = function (credit) {
  454. //>>includeStart('debug', pragmas.debug);
  455. Check.defined("credit", credit);
  456. //>>includeEnd('debug');
  457. const staticCredits = this._staticCredits;
  458. if (!contains(staticCredits, credit)) {
  459. staticCredits.push(credit);
  460. }
  461. };
  462. /**
  463. * Removes a static credit shown on screen or in the lightbox.
  464. *
  465. * @param {Credit} credit The credit to be removed.
  466. */
  467. CreditDisplay.prototype.removeStaticCredit = function (credit) {
  468. //>>includeStart('debug', pragmas.debug);
  469. Check.defined("credit", credit);
  470. //>>includeEnd('debug');
  471. const staticCredits = this._staticCredits;
  472. const index = staticCredits.indexOf(credit);
  473. if (index !== -1) {
  474. staticCredits.splice(index, 1);
  475. }
  476. };
  477. /**
  478. * Removes a default credit.
  479. *
  480. * @param {Credit} credit The credit to be removed from defaults
  481. */
  482. CreditDisplay.prototype.removeDefaultCredit = function (credit) {
  483. deprecationWarning(
  484. "CreditDisplay.removeDefaultCredit",
  485. "CreditDisplay.removeDefaultCredit was deprecated in CesiumJS 1.105. It will be removed in CesiumJS 1.107. Use CreditDisplay.addStaticCredit instead."
  486. );
  487. this.removeStaticCredit(credit);
  488. };
  489. /**
  490. * @private
  491. */
  492. CreditDisplay.prototype.showLightbox = function () {
  493. this._lightbox.style.display = "block";
  494. this._expanded = true;
  495. };
  496. /**
  497. * @private
  498. */
  499. CreditDisplay.prototype.hideLightbox = function () {
  500. this._lightbox.style.display = "none";
  501. this._expanded = false;
  502. };
  503. /**
  504. * Updates the credit display before a new frame is rendered.
  505. */
  506. CreditDisplay.prototype.update = function () {
  507. if (this._expanded) {
  508. styleLightboxContainer(this);
  509. }
  510. };
  511. /**
  512. * Resets the credit display to a beginning of frame state, clearing out current credits.
  513. */
  514. CreditDisplay.prototype.beginFrame = function () {
  515. const currentFrameCredits = this._currentFrameCredits;
  516. this._creditDisplayElementPoolIndex = 0;
  517. const screenCredits = currentFrameCredits.screenCredits;
  518. const lightboxCredits = currentFrameCredits.lightboxCredits;
  519. screenCredits.removeAll();
  520. lightboxCredits.removeAll();
  521. const staticCredits = this._staticCredits;
  522. for (let i = 0; i < staticCredits.length; ++i) {
  523. const staticCredit = staticCredits[i];
  524. const creditCollection = staticCredit.showOnScreen
  525. ? screenCredits
  526. : lightboxCredits;
  527. if (
  528. staticCredit._isIon &&
  529. Credit.equals(CreditDisplay.cesiumCredit, this._cesiumCredit)
  530. ) {
  531. // If this is an ion logo credit from the ion server,
  532. // make sure to de-duplicate with the default ion credit
  533. continue;
  534. }
  535. setCredit(this, creditCollection, staticCredit, Number.MAX_VALUE);
  536. }
  537. if (!Credit.equals(CreditDisplay.cesiumCredit, this._cesiumCredit)) {
  538. this._cesiumCredit = Credit.clone(CreditDisplay.cesiumCredit);
  539. }
  540. this._currentCesiumCredit = this._cesiumCredit;
  541. };
  542. /**
  543. * Sets the credit display to the end of frame state, displaying credits from the last frame in the credit container.
  544. */
  545. CreditDisplay.prototype.endFrame = function () {
  546. const screenCredits = this._currentFrameCredits.screenCredits.values;
  547. displayCredits(
  548. this._screenContainer,
  549. screenCredits,
  550. this._delimiter,
  551. undefined
  552. );
  553. const lightboxCredits = this._currentFrameCredits.lightboxCredits.values;
  554. this._expandLink.style.display =
  555. lightboxCredits.length > 0 ? "inline" : "none";
  556. displayCredits(this._creditList, lightboxCredits, undefined, "li");
  557. swapCesiumCredit(this);
  558. };
  559. /**
  560. * Destroys the resources held by this object. Destroying an object allows for deterministic
  561. * release of resources, instead of relying on the garbage collector to destroy this object.
  562. * <br /><br />
  563. * Once an object is destroyed, it should not be used; calling any function other than
  564. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  565. * assign the return value (<code>undefined</code>) to the object as done in the example.
  566. *
  567. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  568. */
  569. CreditDisplay.prototype.destroy = function () {
  570. this._lightbox.removeEventListener("click", this._hideLightbox, false);
  571. this.container.removeChild(this._cesiumCreditContainer);
  572. this.container.removeChild(this._screenContainer);
  573. this.container.removeChild(this._expandLink);
  574. this.viewport.removeChild(this._lightbox);
  575. return destroyObject(this);
  576. };
  577. /**
  578. * Returns true if this object was destroyed; otherwise, false.
  579. * <br /><br />
  580. *
  581. * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  582. */
  583. CreditDisplay.prototype.isDestroyed = function () {
  584. return false;
  585. };
  586. CreditDisplay._cesiumCredit = undefined;
  587. CreditDisplay._cesiumCreditInitialized = false;
  588. let defaultCredit;
  589. function getDefaultCredit() {
  590. if (!defined(defaultCredit)) {
  591. let logo = buildModuleUrl("Assets/Images/ion-credit.png");
  592. // When hosting in a WebView, the base URL scheme is file:// or ms-appx-web://
  593. // which is stripped out from the Credit's <img> tag; use the full path instead
  594. if (
  595. logo.indexOf("http://") !== 0 &&
  596. logo.indexOf("https://") !== 0 &&
  597. logo.indexOf("data:") !== 0
  598. ) {
  599. const logoUrl = new Uri(logo);
  600. logo = logoUrl.path();
  601. }
  602. defaultCredit = new Credit(
  603. `<a href="https://cesium.com/" target="_blank"><img src="${logo}" title="Cesium ion"/></a>`,
  604. true
  605. );
  606. }
  607. if (!CreditDisplay._cesiumCreditInitialized) {
  608. CreditDisplay._cesiumCredit = defaultCredit;
  609. CreditDisplay._cesiumCreditInitialized = true;
  610. }
  611. return defaultCredit;
  612. }
  613. Object.defineProperties(CreditDisplay, {
  614. /**
  615. * Gets or sets the Cesium logo credit.
  616. * @memberof CreditDisplay
  617. * @type {Credit}
  618. */
  619. cesiumCredit: {
  620. get: function () {
  621. getDefaultCredit();
  622. return CreditDisplay._cesiumCredit;
  623. },
  624. set: function (value) {
  625. CreditDisplay._cesiumCredit = value;
  626. CreditDisplay._cesiumCreditInitialized = true;
  627. },
  628. },
  629. });
  630. CreditDisplay.CreditDisplayElement = CreditDisplayElement;
  631. export default CreditDisplay;