ProviderViewModel.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*global define*/
  2. define([
  3. '../../Core/defined',
  4. '../../Core/defineProperties',
  5. '../../Core/DeveloperError',
  6. '../../ThirdParty/knockout',
  7. '../createCommand'
  8. ], function(
  9. defined,
  10. defineProperties,
  11. DeveloperError,
  12. knockout,
  13. createCommand) {
  14. "use strict";
  15. /**
  16. * A view model that represents each item in the {@link BaseLayerPicker}.
  17. *
  18. * @alias ProviderViewModel
  19. * @constructor
  20. *
  21. * @param {Object} options The object containing all parameters.
  22. * @param {String} options.name The name of the layer.
  23. * @param {String} options.tooltip The tooltip to show when the item is moused over.
  24. * @param {String} options.iconUrl An icon representing the layer.
  25. * @param {ProviderViewModel~CreationFunction|Command} options.creationFunction A function or Command
  26. * that creates one or more providers which will be added to the globe when this item is selected.
  27. *
  28. * @see BaseLayerPicker
  29. * @see ImageryProvider
  30. * @see TerrainProvider
  31. */
  32. var ProviderViewModel = function(options) {
  33. //>>includeStart('debug', pragmas.debug);
  34. if (!defined(options.name)) {
  35. throw new DeveloperError('options.name is required.');
  36. }
  37. if (!defined(options.tooltip)) {
  38. throw new DeveloperError('options.tooltip is required.');
  39. }
  40. if (!defined(options.iconUrl)) {
  41. throw new DeveloperError('options.iconUrl is required.');
  42. }
  43. if (typeof options.creationFunction !== 'function') {
  44. throw new DeveloperError('options.creationFunction is required.');
  45. }
  46. //>>includeEnd('debug');
  47. var creationCommand = options.creationFunction;
  48. if (!defined(creationCommand.canExecute)) {
  49. creationCommand = createCommand(creationCommand);
  50. }
  51. this._creationCommand = creationCommand;
  52. /**
  53. * Gets the display name. This property is observable.
  54. * @type {String}
  55. */
  56. this.name = options.name;
  57. /**
  58. * Gets the tooltip. This property is observable.
  59. * @type {String}
  60. */
  61. this.tooltip = options.tooltip;
  62. /**
  63. * Gets the icon. This property is observable.
  64. * @type {String}
  65. */
  66. this.iconUrl = options.iconUrl;
  67. knockout.track(this, ['name', 'tooltip', 'iconUrl']);
  68. };
  69. defineProperties(ProviderViewModel.prototype, {
  70. /**
  71. * Gets the Command that creates one or more providers which will be added to
  72. * the globe when this item is selected.
  73. * @memberof ProviderViewModel.prototype
  74. *
  75. * @type {Command}
  76. */
  77. creationCommand : {
  78. get : function() {
  79. return this._creationCommand;
  80. }
  81. }
  82. });
  83. /**
  84. * A function which creates one or more providers.
  85. * @callback ProviderViewModel~CreationFunction
  86. * @returns {ImageryProvider|TerrainProvider|ImageryProvider[]|TerrainProvider[]}
  87. * The ImageryProvider or TerrainProvider, or array of providers, to be added
  88. * to the globe.
  89. */
  90. return ProviderViewModel;
  91. });