/
ProviderViewModel.js
91 lines (82 loc) · 2.84 KB
/
ProviderViewModel.js
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
/*global define*/
define([
'../../Core/defined',
'../../Core/defineProperties',
'../../Core/DeveloperError',
'../../ThirdParty/knockout',
'../createCommand'
], function(
defined,
defineProperties,
DeveloperError,
knockout,
createCommand) {
"use strict";
/**
* A view model that represents each item in the 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 {Function|Command} options.creationFunction A function or Command which creates the ImageryProvider or array of ImageryProviders to be added to the layers collection.
*
* @see BaseLayerPicker
* @see ImageryProvider
*/
var ProviderViewModel = function(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');
var 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;
knockout.track(this, ['name', 'tooltip', 'iconUrl']);
};
defineProperties(ProviderViewModel.prototype, {
/**
* Gets the Command called to create the imagery provider or array of
* imagery providers to be added to the bottom of the layer collection.
* @memberof ProviderViewModel.prototype
*
* @type {Command}
*/
creationCommand : {
get : function() {
return this._creationCommand;
}
}
});
return ProviderViewModel;
});