viewerPerformanceWatchdogMixin.js 1.8 KB

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