viewerPerformanceWatchdogMixin.js 2.2 KB

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