All files / widgets/Source/BaseLayerPicker ProviderViewModel.js

100% Statements 20/20
100% Branches 12/12
100% Functions 3/3
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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