viewerPerformanceWatchdogMixin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import defaultValue from "../../Core/defaultValue.js";
  2. import defined from "../../Core/defined.js";
  3. import DeveloperError from "../../Core/DeveloperError.js";
  4. import PerformanceWatchdog from "../PerformanceWatchdog/PerformanceWatchdog.js";
  5. /**
  6. * A mixin which adds the {@link PerformanceWatchdog} widget to the {@link Viewer} widget.
  7. * Rather than being called directly, this function is normally passed as
  8. * a parameter to {@link Viewer#extend}, as shown in the example below.
  9. * @function
  10. *
  11. * @param {Viewer} viewer The viewer instance.
  12. * @param {Object} [options] An object with properties.
  13. * @param {String} [options.lowFrameRateMessage='This application appears to be performing poorly on your system. Please try using a different web browser or updating your video drivers.'] The
  14. * message to display when a low frame rate is detected. The message is interpeted as HTML, so make sure
  15. * it comes from a trusted source so that your application is not vulnerable to cross-site scripting attacks.
  16. *
  17. * @exception {DeveloperError} viewer is required.
  18. *
  19. * @example
  20. * const viewer = new Cesium.Viewer('cesiumContainer');
  21. * viewer.extend(Cesium.viewerPerformanceWatchdogMixin, {
  22. * lowFrameRateMessage : 'Why is this going so <em>slowly</em>?'
  23. * });
  24. */
  25. function viewerPerformanceWatchdogMixin(viewer, options) {
  26. //>>includeStart('debug', pragmas.debug);
  27. if (!defined(viewer)) {
  28. throw new DeveloperError("viewer is required.");
  29. }
  30. //>>includeEnd('debug');
  31. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  32. const performanceWatchdog = new PerformanceWatchdog({
  33. scene: viewer.scene,
  34. container: viewer.bottomContainer,
  35. lowFrameRateMessage: options.lowFrameRateMessage,
  36. });
  37. Object.defineProperties(viewer, {
  38. performanceWatchdog: {
  39. get: function () {
  40. return performanceWatchdog;
  41. },
  42. },
  43. });
  44. }
  45. export default viewerPerformanceWatchdogMixin;