oneTimeWarning.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import defaultValue from "./defaultValue.js";
  2. import defined from "./defined.js";
  3. import DeveloperError from "./DeveloperError.js";
  4. const warnings = {};
  5. /**
  6. * Logs a one time message to the console. Use this function instead of
  7. * <code>console.log</code> directly since this does not log duplicate messages
  8. * unless it is called from multiple workers.
  9. *
  10. * @function oneTimeWarning
  11. *
  12. * @param {String} identifier The unique identifier for this warning.
  13. * @param {String} [message=identifier] The message to log to the console.
  14. *
  15. * @example
  16. * for(let i=0;i<foo.length;++i) {
  17. * if (!defined(foo[i].bar)) {
  18. * // Something that can be recovered from but may happen a lot
  19. * oneTimeWarning('foo.bar undefined', 'foo.bar is undefined. Setting to 0.');
  20. * foo[i].bar = 0;
  21. * // ...
  22. * }
  23. * }
  24. *
  25. * @private
  26. */
  27. function oneTimeWarning(identifier, message) {
  28. //>>includeStart('debug', pragmas.debug);
  29. if (!defined(identifier)) {
  30. throw new DeveloperError("identifier is required.");
  31. }
  32. //>>includeEnd('debug');
  33. if (!defined(warnings[identifier])) {
  34. warnings[identifier] = true;
  35. console.warn(defaultValue(message, identifier));
  36. }
  37. }
  38. oneTimeWarning.geometryOutlines =
  39. "Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.";
  40. oneTimeWarning.geometryZIndex =
  41. "Entity geometry with zIndex are unsupported when height or extrudedHeight are defined. zIndex will be ignored";
  42. oneTimeWarning.geometryHeightReference =
  43. "Entity corridor, ellipse, polygon or rectangle with heightReference must also have a defined height. heightReference will be ignored";
  44. oneTimeWarning.geometryExtrudedHeightReference =
  45. "Entity corridor, ellipse, polygon or rectangle with extrudedHeightReference must also have a defined extrudedHeight. extrudedHeightReference will be ignored";
  46. export default oneTimeWarning;