/
ImageryProviderViewModel.js
95 lines (83 loc) · 3.18 KB
/
ImageryProviderViewModel.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
92
93
94
95
/*global define*/
define([
'../../Core/defineProperties',
'../../Core/DeveloperError',
'../createCommand',
'../../ThirdParty/knockout'
], function(
defineProperties,
DeveloperError,
createCommand,
knockout) {
"use strict";
/**
* A view model that represents each item in the BaseLayerPicker.
*
* @alias ImageryProviderViewModel
* @constructor
*
* @param {Object} description The object containing all parameters.
* @param {String|Observable} description.name The name of the layer.
* @param {String|Observable} description.tooltip The tooltip to show when the item is moused over.
* @param {String|Observable} description.iconUrl An icon representing the layer.
* @param {Function|Command} description.creationFunction A function or Command which creates the ImageryProvider or array of ImageryProviders to be added to the layers collection.
*
* @exception {DeveloperError} description.name is required.
* @exception {DeveloperError} description.tooltip is required.
* @exception {DeveloperError} description.iconUrl is required.
* @exception {DeveloperError} description.creationCommand is required.
*
* @see BaseLayerPicker
* @see ImageryProvider
*/
var ImageryProviderViewModel = function(description) {
if (typeof description.name === 'undefined') {
throw new DeveloperError('description.name is required.');
}
if (typeof description.tooltip === 'undefined') {
throw new DeveloperError('description.tooltip is required.');
}
if (typeof description.iconUrl === 'undefined') {
throw new DeveloperError('description.iconUrl is required.');
}
if (typeof description.creationFunction !== 'function') {
throw new DeveloperError('description.creationFunction is required.');
}
var creationCommand = description.creationFunction;
if (typeof creationCommand.canExecute === 'undefined') {
creationCommand = createCommand(creationCommand);
}
this._creationCommand = creationCommand;
/**
* Gets the display name. This property is observable.
* @type {String}
*/
this.name = description.name;
/**
* Gets the tooltip. This property is observable.
* @type {String}
*/
this.tooltip = description.tooltip;
/**
* Gets the icon. This property is observable.
* @type {String}
*/
this.iconUrl = description.iconUrl;
knockout.track(this, ['name', 'tooltip', 'iconUrl']);
};
defineProperties(ImageryProviderViewModel.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 ImageryProviderViewModel.prototype
*
* @type {Command}
*/
creationCommand : {
get : function() {
return this._creationCommand;
}
}
});
return ImageryProviderViewModel;
});