diff --git a/CHANGES.md b/CHANGES.md
index c39547570e85..01580d82fe94 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -23,6 +23,15 @@ Beta Releases
* `TilingScheme.extentToNativeRectangle` -> `TilingScheme.rectangleToNativeRectangle`
* `TilingScheme.tileXYToNativeExtent` -> `TilingScheme.tileXYToNativeRectangle`
* `TilingScheme.tileXYToExtent` -> `TilingScheme.tileXYToRectangle`
+ * `BaseLayerPicker` has been extended to support terrain selection.
+ * The `BaseLayerPicker` constructor function now takes the container element and an options object instead of a CentralBody and ImageryLayerCollection.
+ * The `BaseLayerPickerViewModel` constructor function now takes an options object instead of a CentralBody and ImageryLayerCollection.
+ * `ImageryProviderViewModel` -> `ProviderViewModel`
+ * `BaseLayerPickerViewModel.selectedName` -> `BaseLayerPickerViewModel.buttonTooltip`
+ * `BaseLayerPickerViewModel.selectedIconUrl` -> `BaseLayerPickerViewModel.buttonImageUrl`
+ * `BaseLayerPickerViewModel.selectedItem` -> `BaseLayerPickerViewModel.selectedImagery`
+ * `BaseLayerPickerViewModel.imageryLayers`has been removed and replaced with `BaseLayerPickerViewModel.centralBody`
+ * See [#1607](https://github.com/AnalyticalGraphicsInc/cesium/pull/1607) for full details.
* `TimeIntervalCollection.clear` renamed to `TimeIntervalColection.removeAll`
* `Context` is now private
* Removed `Scene.context`: replaced by adding `drawingBufferWidth`, `drawingBufferHeight`, `maximumAliasedLineWidth` properties and `createTextureAtlas` function to `Scene`.
diff --git a/Source/Widgets/BaseLayerPicker/BaseLayerPicker.css b/Source/Widgets/BaseLayerPicker/BaseLayerPicker.css
index 0787882a08f2..ac0052aac628 100644
--- a/Source/Widgets/BaseLayerPicker/BaseLayerPicker.css
+++ b/Source/Widgets/BaseLayerPicker/BaseLayerPicker.css
@@ -28,7 +28,7 @@
position: absolute;
top: auto;
right: 0;
- width: 240px;
+ width: 320px;
max-height: 500px;
margin-top: 5px;
background-color: rgba(38, 38, 38, 0.75);
@@ -40,6 +40,21 @@
user-select: none;
}
+.cesium-baseLayerPicker-sectionTitle {
+ display: block;
+ font-family: sans-serif;
+ font-size: 16pt;
+ text-align: left;
+ color: #edffff;
+}
+
+.cesium-baseLayerPicker-choices {
+ display: block;
+ position: relative;
+ top: auto;
+ right: 0;
+}
+
.cesium-baseLayerPicker-item {
display: inline-block;
vertical-align: top;
diff --git a/Source/Widgets/BaseLayerPicker/BaseLayerPicker.js b/Source/Widgets/BaseLayerPicker/BaseLayerPicker.js
index 6e2e6d51a542..3904a85f010d 100644
--- a/Source/Widgets/BaseLayerPicker/BaseLayerPicker.js
+++ b/Source/Widgets/BaseLayerPicker/BaseLayerPicker.js
@@ -23,23 +23,27 @@ define([
*
BaseLayerPicker with its drop-panel open.
*
*
- * The BaseLayerPicker is a single button widget that displays a panel of available imagery
- * providers. When an item is selected, the corresponding imagery layer is created and inserted
- * as the base layer of the imagery collection; removing the existing base. Each item in the
- * available providers list contains a name, a representative icon, and a tooltip to display more
- * information when hovered. The list is initially empty, and must be configured before use, as
- * illustrated in the below example.
+ * The BaseLayerPicker is a single button widget that displays a panel of available imagery and
+ * terrain providers. When imagery is selected, the corresponding imagery layer is created and inserted
+ * as the base layer of the imagery collection; removing the existing base. When terrain is selected,
+ * it replaces the current terrain provider. Each item in the available providers list contains a name,
+ * a representative icon, and a tooltip to display more information when hovered. The list is initially
+ * empty, and must be configured before use, as illustrated in the below example.
*
* @alias BaseLayerPicker
* @constructor
*
* @param {Element} container The parent HTML container node for this widget.
- * @param {ImageryLayerCollection} imageryLayers The imagery layer collection to use.
+ * @param {CentralBody} options.centralBody The CentralBody to use.
+ * @param {ProviderViewModel[]} [options.imageryProviderViewModels=[]] The array of ProviderViewModel instances to use for imagery.
+ * @param {ProviderViewModel} [options.selectedImageryProviderViewModel] The view model for the current base imagery layer, if not supplied the first available imagery layer is used.
+ * @param {ProviderViewModel[]} [options.terrainProviderViewModels=[]] The array of ProviderViewModel instances to use for terrain.
+ * @param {ProviderViewModel} [options.selectedTerrainProviderViewModel] The view model for the current base terrain layer, if not supplied the first available terrain layer is used.
*
* @exception {DeveloperError} Element with id "container" does not exist in the document.
*
+ * @see TerrainProvider
* @see ImageryProvider
- * @see ImageryProviderViewModel
* @see ImageryLayerCollection
*
* @example
@@ -49,8 +53,8 @@ define([
*
* //Create the list of available providers we would like the user to select from.
* //This example uses 3, OpenStreetMap, The Black Marble, and a single, non-streaming world image.
- * var providerViewModels = [];
- * providerViewModels.push(new Cesium.ImageryProviderViewModel({
+ * var imageryViewModels = [];
+ * imageryViewModels.push(new Cesium.ProviderViewModel({
* name : 'Open\u00adStreet\u00adMap',
* iconUrl : Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/openStreetMap.png'),
* tooltip : 'OpenStreetMap (OSM) is a collaborative project to create a free editable \
@@ -62,7 +66,7 @@ define([
* }
* }));
*
- * providerViewModels.push(new Cesium.ImageryProviderViewModel({
+ * imageryViewModels.push(new Cesium.ProviderViewModel({
* name : 'Black Marble',
* iconUrl : Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/blackMarble.png'),
* tooltip : 'The lights of cities and villages trace the outlines of civilization \
@@ -76,7 +80,7 @@ define([
* }
* }));
*
- * providerViewModels.push(new Cesium.ImageryProviderViewModel({
+ * imageryViewModels.push(new Cesium.ProviderViewModel({
* name : 'Natural Earth\u00a0II',
* iconUrl : Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/naturalEarthII.png'),
* tooltip : 'Natural Earth II, darkened for contrast.\nhttp://www.naturalearthdata.com/',
@@ -92,30 +96,27 @@ define([
*
* //Finally, create the baseLayerPicker widget using our view models.
* var layers = cesiumWidget.centralBody.imageryLayers;
- * var baseLayerPicker = new Cesium.BaseLayerPicker('baseLayerPickerContainer', layers, providerViewModels);
+ * var baseLayerPicker = new Cesium.BaseLayerPicker('baseLayerPickerContainer', layers, imageryViewModels);
*
* //Use the first item in the list as the current selection.
- * baseLayerPicker.viewModel.selectedItem = providerViewModels[0];
+ * baseLayerPicker.viewModel.selectedItem = imageryViewModels[0];
*/
- var BaseLayerPicker = function(container, imageryLayers, imageryProviderViewModels) {
+ var BaseLayerPicker = function(container, options) {
//>>includeStart('debug', pragmas.debug);
if (!defined(container)) {
throw new DeveloperError('container is required.');
}
- if (!defined(imageryLayers)) {
- throw new DeveloperError('imageryLayers is required.');
- }
//>>includeEnd('debug');
container = getElement(container);
- var viewModel = new BaseLayerPickerViewModel(imageryLayers, imageryProviderViewModels);
+ var viewModel = new BaseLayerPickerViewModel(options);
var element = document.createElement('button');
element.type = 'button';
element.className = 'cesium-button cesium-toolbar-button';
element.setAttribute('data-bind', '\
-attr: { title: selectedName },\
+attr: { title: buttonTooltip },\
click: toggleDropDown');
container.appendChild(element);
@@ -123,47 +124,88 @@ click: toggleDropDown');
imgElement.setAttribute('draggable', 'false');
imgElement.className = 'cesium-baseLayerPicker-selected';
imgElement.setAttribute('data-bind', '\
-attr: { src: selectedIconUrl }');
+attr: { src: buttonImageUrl }');
element.appendChild(imgElement);
- var choices = document.createElement('div');
- choices.className = 'cesium-baseLayerPicker-dropDown';
- choices.setAttribute('data-bind', '\
+ var dropPanel = document.createElement('div');
+ dropPanel.className = 'cesium-baseLayerPicker-dropDown';
+ dropPanel.setAttribute('data-bind', '\
css: { "cesium-baseLayerPicker-visible" : dropDownVisible,\
- "cesium-baseLayerPicker-hidden" : !dropDownVisible },\
-foreach: imageryProviderViewModels');
- container.appendChild(choices);
-
- var provider = document.createElement('div');
- provider.className = 'cesium-baseLayerPicker-item';
- provider.setAttribute('data-bind', '\
-css: { "cesium-baseLayerPicker-selectedItem" : $data === $parent.selectedItem },\
+ "cesium-baseLayerPicker-hidden" : !dropDownVisible }');
+ container.appendChild(dropPanel);
+
+ var imageryTitle = document.createElement('div');
+ imageryTitle.className = 'cesium-baseLayerPicker-sectionTitle';
+ imageryTitle.setAttribute('data-bind', 'visible: imageryProviderViewModels.length > 0');
+ imageryTitle.innerHTML = 'Imagery
undefined
, the default stars are used.
@@ -128,7 +132,9 @@ define([
*
* @exception {DeveloperError} Element with id "container" does not exist in the document.
* @exception {DeveloperError} options.imageryProvider is not available when using the BaseLayerPicker widget, specify options.selectedImageryProviderViewModel instead.
+ * @exception {DeveloperError} options.terrainProvider is not available when using the BaseLayerPicker widget, specify options.selectedTerrainProviderViewModel instead.
* @exception {DeveloperError} options.selectedImageryProviderViewModel is not available when not using the BaseLayerPicker widget, specify options.imageryProvider instead.
+ * @exception {DeveloperError} options.selectedTerrainProviderViewModel is not available when not using the BaseLayerPicker widget, specify options.terrainProvider instead.
*
* @see Animation
* @see BaseLayerPicker
@@ -194,7 +200,6 @@ define([
var createBaseLayerPicker = !defined(options.baseLayerPicker) || options.baseLayerPicker !== false;
//>>includeStart('debug', pragmas.debug);
-
//If using BaseLayerPicker, imageryProvider is an invalid option
if (createBaseLayerPicker && defined(options.imageryProvider)) {
throw new DeveloperError('options.imageryProvider is not available when using the BaseLayerPicker widget. \
@@ -206,6 +211,18 @@ Either specify options.selectedImageryProviderViewModel instead or set options.b
throw new DeveloperError('options.selectedImageryProviderViewModel is not available when not using the BaseLayerPicker widget. \
Either specify options.imageryProvider instead or set options.baseLayerPicker to true.');
}
+
+ //If using BaseLayerPicker, terrainProvider is an invalid option
+ if (createBaseLayerPicker && defined(options.terrainProvider)) {
+ throw new DeveloperError('options.terrainProvider is not available when using the BaseLayerPicker widget. \
+Either specify options.selectedTerrainProviderViewModel instead or set options.baseLayerPicker to false.');
+ }
+
+ //If not using BaseLayerPicker, selectedTerrainProviderViewModel is an invalid option
+ if (!createBaseLayerPicker && defined(options.selectedTerrainProviderViewModel)) {
+ throw new DeveloperError('options.selectedTerrainProviderViewModel is not available when not using the BaseLayerPicker widget. \
+Either specify options.terrainProvider instead or set options.baseLayerPicker to true.');
+ }
//>>includeEnd('debug')
var viewerContainer = document.createElement('div');
@@ -296,9 +313,16 @@ Either specify options.imageryProvider instead or set options.baseLayerPicker to
//BaseLayerPicker
var baseLayerPicker;
if (createBaseLayerPicker) {
- var providerViewModels = defaultValue(options.imageryProviderViewModels, createDefaultBaseLayers());
- baseLayerPicker = new BaseLayerPicker(toolbar, cesiumWidget.centralBody.imageryLayers, providerViewModels);
- baseLayerPicker.viewModel.selectedItem = defaultValue(options.selectedImageryProviderViewModel, providerViewModels[0]);
+ var imageryProviderViewModels = defaultValue(options.imageryProviderViewModels, createDefaultImageryProviderViewModels());
+ var terrainProviderViewModels = defaultValue(options.terrainProviderViewModels, createDefaultTerrainProviderViewModels());
+
+ baseLayerPicker = new BaseLayerPicker(toolbar, {
+ centralBody : cesiumWidget.centralBody,
+ imageryProviderViewModels : imageryProviderViewModels,
+ selectedImageryProviderViewModel : options.selectedImageryProviderViewModel,
+ terrainProviderViewModels : terrainProviderViewModels,
+ selectedTerrainProviderViewModel : options.selectedTerrainProviderViewModel
+ });
//Grab the dropdown for resize code.
var elements = toolbar.getElementsByClassName('cesium-baseLayerPicker-dropDown');
diff --git a/Specs/Widgets/BaseLayerPicker/BaseLayerPickerSpec.js b/Specs/Widgets/BaseLayerPicker/BaseLayerPickerSpec.js
index 2cafe4a05e13..39862647dfa4 100644
--- a/Specs/Widgets/BaseLayerPicker/BaseLayerPickerSpec.js
+++ b/Specs/Widgets/BaseLayerPicker/BaseLayerPickerSpec.js
@@ -2,24 +2,32 @@
defineSuite([
'Widgets/BaseLayerPicker/BaseLayerPicker',
'Scene/ImageryLayerCollection',
+ 'Scene/EllipsoidTerrainProvider',
'Specs/EventHelper'
], function(
BaseLayerPicker,
ImageryLayerCollection,
+ EllipsoidTerrainProvider,
EventHelper) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/
+ var MockCentralBody = function(){
+ this.imageryLayers = new ImageryLayerCollection();
+ this.terrainProvider = new EllipsoidTerrainProvider();
+ };
+
it('can create and destroy', function() {
var container = document.createElement('div');
container.id = 'testContainer';
document.body.appendChild(container);
- var layers = new ImageryLayerCollection();
-
- var widget = new BaseLayerPicker('testContainer', layers);
+ var centralBody = new MockCentralBody();
+ var widget = new BaseLayerPicker('testContainer', {
+ centralBody : centralBody
+ });
expect(widget.container).toBe(container);
- expect(widget.viewModel.imageryLayers).toBe(layers);
+ expect(widget.viewModel.centralBody).toBe(centralBody);
expect(widget.isDestroyed()).toEqual(false);
widget.destroy();
expect(widget.isDestroyed()).toEqual(true);
@@ -32,7 +40,9 @@ defineSuite([
container.id = 'testContainer';
document.body.appendChild(container);
- var widget = new BaseLayerPicker('testContainer', new ImageryLayerCollection());
+ var widget = new BaseLayerPicker('testContainer', {
+ centralBody : new MockCentralBody()
+ });
widget.viewModel.dropDownVisible = true;
EventHelper.fireMouseDown(document.body);
@@ -51,7 +61,9 @@ defineSuite([
container.id = 'testContainer';
document.body.appendChild(container);
- var widget = new BaseLayerPicker('testContainer', new ImageryLayerCollection());
+ var widget = new BaseLayerPicker('testContainer', {
+ centralBody : new MockCentralBody()
+ });
widget.viewModel.dropDownVisible = true;
@@ -75,13 +87,17 @@ defineSuite([
it('constructor throws with no element', function() {
expect(function() {
- return new BaseLayerPicker(undefined, new ImageryLayerCollection());
+ return new BaseLayerPicker(undefined, {
+ centralBody : new MockCentralBody()
+ });
}).toThrowDeveloperError();
});
it('constructor throws with string element that does not exist', function() {
expect(function() {
- return new BaseLayerPicker('does not exist', new ImageryLayerCollection());
+ return new BaseLayerPicker('does not exist', {
+ centralBody : new MockCentralBody()
+ });
}).toThrowDeveloperError();
});
});
\ No newline at end of file
diff --git a/Specs/Widgets/BaseLayerPicker/BaseLayerPickerViewModelSpec.js b/Specs/Widgets/BaseLayerPicker/BaseLayerPickerViewModelSpec.js
index dbd1c68bdbda..5b3fc6ab9df3 100644
--- a/Specs/Widgets/BaseLayerPicker/BaseLayerPickerViewModelSpec.js
+++ b/Specs/Widgets/BaseLayerPicker/BaseLayerPickerViewModelSpec.js
@@ -1,15 +1,22 @@
/*global defineSuite*/
defineSuite([
'Widgets/BaseLayerPicker/BaseLayerPickerViewModel',
- 'Widgets/BaseLayerPicker/ImageryProviderViewModel',
+ 'Widgets/BaseLayerPicker/ProviderViewModel',
+ 'Scene/EllipsoidTerrainProvider',
'Scene/ImageryLayerCollection'
], function(
BaseLayerPickerViewModel,
- ImageryProviderViewModel,
+ ProviderViewModel,
+ EllipsoidTerrainProvider,
ImageryLayerCollection) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/
+ var MockCentralBody = function() {
+ this.imageryLayers = new ImageryLayerCollection();
+ this.terrainProvider = new EllipsoidTerrainProvider();
+ };
+
var testProvider = {
isReady : function() {
return false;
@@ -28,7 +35,7 @@ defineSuite([
}
};
- var testProviderViewModel = new ImageryProviderViewModel({
+ var testProviderViewModel = new ProviderViewModel({
name : 'name',
tooltip : 'tooltip',
iconUrl : 'url',
@@ -37,74 +44,138 @@ defineSuite([
}
});
- var testProviderViewModel2 = new ImageryProviderViewModel({
- name : 'name',
- tooltip : 'tooltip',
- iconUrl : 'url',
+ var testProviderViewModel2 = new ProviderViewModel({
+ name : 'name2',
+ tooltip : 'tooltip2',
+ iconUrl : 'url2',
creationFunction : function() {
return [testProvider, testProvider2];
}
});
+ var testProviderViewModel3 = new ProviderViewModel({
+ name : 'name3',
+ tooltip : 'tooltip3',
+ iconUrl : 'url3',
+ creationFunction : function() {
+ return testProvider3;
+ }
+ });
+
it('constructor sets expected values', function() {
- var array = [];
- var imageryLayers = new ImageryLayerCollection();
- var viewModel = new BaseLayerPickerViewModel(imageryLayers, array);
- expect(viewModel.imageryLayers).toBe(imageryLayers);
- expect(viewModel.imageryProviderViewModels).toEqual(array);
+ var imageryViewModels = [];
+ var terrainViewModels = [];
+
+ var centralBody = new MockCentralBody();
+
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ imageryProviderViewModels : imageryViewModels,
+ terrainProviderViewModels : terrainViewModels
+ });
+ expect(viewModel.centralBody).toBe(centralBody);
+ expect(viewModel.imageryProviderViewModels).toEqual(imageryViewModels);
+ expect(viewModel.terrainProviderViewModels).toEqual(terrainViewModels);
+ });
+
+ it('selecting imagery closes the dropDown', function() {
+ var imageryViewModels = [testProviderViewModel];
+ var centralBody = new MockCentralBody();
+ var imageryLayers = centralBody.imageryLayers;
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ imageryProviderViewModels : imageryViewModels
+ });
+
+ viewModel.dropDownVisible = true;
+ viewModel.selectedImagery = testProviderViewModel;
+ expect(viewModel.dropDownVisible).toEqual(false);
});
- it('selecting an item closes the dropDown', function() {
- var array = [testProviderViewModel];
- var imageryLayers = new ImageryLayerCollection();
- var viewModel = new BaseLayerPickerViewModel(imageryLayers, array);
+ it('selecting terrain closes the dropDown', function() {
+ var imageryViewModels = [testProviderViewModel];
+ var centralBody = new MockCentralBody();
+ var imageryLayers = centralBody.imageryLayers;
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ imageryProviderViewModels : imageryViewModels
+ });
viewModel.dropDownVisible = true;
- viewModel.selectedItem = testProviderViewModel;
+ viewModel.selectedTerrain = testProviderViewModel;
expect(viewModel.dropDownVisible).toEqual(false);
});
- it('selectedName, selectedIconUrl, and selectedItem all return expected values', function() {
- var array = [testProviderViewModel];
- var imageryLayers = new ImageryLayerCollection();
- var viewModel = new BaseLayerPickerViewModel(imageryLayers, array);
+ it('tooltip, buttonImageUrl, and selectedImagery all return expected values', function() {
+ var imageryViewModels = [testProviderViewModel];
+ var terrainViewModels = [testProviderViewModel3];
+ var centralBody = new MockCentralBody();
+ var imageryLayers = centralBody.imageryLayers;
+
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ imageryProviderViewModels : imageryViewModels,
+ terrainProviderViewModels : terrainViewModels
+ });
- expect(viewModel.selectedName).toBeUndefined();
- expect(viewModel.selectedIconUrl).toBeUndefined();
- expect(viewModel.selectedItem).toBeUndefined();
+ viewModel.selectedImagery = testProviderViewModel;
+ expect(viewModel.buttonTooltip).toEqual(testProviderViewModel.name + '\n' + testProviderViewModel3.name);
- viewModel.selectedItem = testProviderViewModel;
+ viewModel.selectedImagery = undefined;
+ expect(viewModel.buttonTooltip).toEqual(testProviderViewModel3.name);
- expect(viewModel.selectedName).toEqual(testProviderViewModel.name);
- expect(viewModel.selectedIconUrl).toEqual(testProviderViewModel.iconUrl);
- expect(viewModel.selectedItem).toBe(testProviderViewModel);
+ viewModel.selectedImagery = testProviderViewModel;
+ viewModel.selectedTerrain = undefined;
+ expect(viewModel.buttonTooltip).toEqual(testProviderViewModel.name);
+
+ expect(viewModel.buttonImageUrl).toEqual(testProviderViewModel.iconUrl);
});
- it('selectedItem actually sets base layer', function() {
- var array = [testProviderViewModel];
- var imageryLayers = new ImageryLayerCollection();
- var viewModel = new BaseLayerPickerViewModel(imageryLayers, array);
+ it('selectedImagery actually sets base layer', function() {
+ var imageryViewModels = [testProviderViewModel];
+ var centralBody = new MockCentralBody();
+ var imageryLayers = centralBody.imageryLayers;
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ imageryProviderViewModels : imageryViewModels
+ });
- expect(imageryLayers.length).toEqual(0);
+ expect(imageryLayers.length).toEqual(1);
- viewModel.selectedItem = testProviderViewModel;
+ viewModel.selectedImagery = testProviderViewModel;
expect(imageryLayers.length).toEqual(1);
expect(imageryLayers.get(0).imageryProvider).toBe(testProvider);
- viewModel.selectedItem = testProviderViewModel2;
+ viewModel.selectedImagery = testProviderViewModel2;
expect(imageryLayers.length).toEqual(2);
expect(imageryLayers.get(0).imageryProvider).toBe(testProvider);
expect(imageryLayers.get(1).imageryProvider).toBe(testProvider2);
});
- it('settings selectedItem only removes layers added by view model', function() {
- var array = [testProviderViewModel];
- var imageryLayers = new ImageryLayerCollection();
- var viewModel = new BaseLayerPickerViewModel(imageryLayers, array);
+ it('selectedTerrain actually sets terrainPRovider', function() {
+ var terrainProviderViewModels = [testProviderViewModel, testProviderViewModel3];
+ var centralBody = new MockCentralBody();
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ terrainProviderViewModels : terrainProviderViewModels
+ });
- expect(imageryLayers.length).toEqual(0);
+ viewModel.selectedTerrain = testProviderViewModel3;
+ expect(centralBody.terrainProvider).toBe(testProvider3);
+ });
+
+ it('settings selectedImagery only removes layers added by view model', function() {
+ var imageryViewModels = [testProviderViewModel];
+ var centralBody = new MockCentralBody();
+ var imageryLayers = centralBody.imageryLayers;
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : centralBody,
+ imageryProviderViewModels : imageryViewModels
+ });
- viewModel.selectedItem = testProviderViewModel2;
+ expect(imageryLayers.length).toEqual(1);
+
+ viewModel.selectedImagery = testProviderViewModel2;
expect(imageryLayers.length).toEqual(2);
expect(imageryLayers.get(0).imageryProvider).toBe(testProvider);
expect(imageryLayers.get(1).imageryProvider).toBe(testProvider2);
@@ -112,15 +183,16 @@ defineSuite([
imageryLayers.addImageryProvider(testProvider3, 1);
imageryLayers.remove(imageryLayers.get(0));
- viewModel.selectedItem = undefined;
+ viewModel.selectedImagery = undefined;
expect(imageryLayers.length).toEqual(1);
expect(imageryLayers.get(0).imageryProvider).toBe(testProvider3);
});
-
it('dropDownVisible and toggleDropDown work', function() {
- var viewModel = new BaseLayerPickerViewModel(new ImageryLayerCollection());
+ var viewModel = new BaseLayerPickerViewModel({
+ centralBody : new MockCentralBody()
+ });
expect(viewModel.dropDownVisible).toEqual(false);
viewModel.toggleDropDown();
@@ -129,16 +201,9 @@ defineSuite([
expect(viewModel.dropDownVisible).toEqual(false);
});
- it('constructor throws with no layer collection', function() {
- expect(function() {
- return new BaseLayerPickerViewModel(undefined);
- }).toThrowDeveloperError();
- });
-
- it('constructor throws if viewModels argument is not an array', function() {
- var imageryLayers = new ImageryLayerCollection();
+ it('constructor throws with no centralBody', function() {
expect(function() {
- return new BaseLayerPickerViewModel(imageryLayers, {});
+ return new BaseLayerPickerViewModel({});
}).toThrowDeveloperError();
});
});
\ No newline at end of file
diff --git a/Specs/Widgets/BaseLayerPicker/ImageryProviderViewModelSpec.js b/Specs/Widgets/BaseLayerPicker/ProviderViewModelSpec.js
similarity index 85%
rename from Specs/Widgets/BaseLayerPicker/ImageryProviderViewModelSpec.js
rename to Specs/Widgets/BaseLayerPicker/ProviderViewModelSpec.js
index 4ddf2cefd663..47911b14a982 100644
--- a/Specs/Widgets/BaseLayerPicker/ImageryProviderViewModelSpec.js
+++ b/Specs/Widgets/BaseLayerPicker/ProviderViewModelSpec.js
@@ -1,10 +1,10 @@
/*global defineSuite*/
defineSuite([
- 'Widgets/BaseLayerPicker/ImageryProviderViewModel',
+ 'Widgets/BaseLayerPicker/ProviderViewModel',
'Widgets/createCommand',
'ThirdParty/knockout'
], function(
- ImageryProviderViewModel,
+ ProviderViewModel,
createCommand,
knockout) {
"use strict";
@@ -24,7 +24,7 @@ defineSuite([
creationFunction : createCommand(spyCreationFunction)
};
- var viewModel = new ImageryProviderViewModel(description);
+ var viewModel = new ProviderViewModel(description);
expect(viewModel.name).toBe(description.name());
expect(viewModel.tooltip).toBe(description.tooltip());
expect(viewModel.iconUrl).toBe(description.iconUrl());
@@ -42,7 +42,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
@@ -54,7 +54,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
@@ -66,7 +66,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
@@ -78,7 +78,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
});
@@ -92,7 +92,7 @@ defineSuite([
creationFunction : spyCreationFunction
};
- var viewModel = new ImageryProviderViewModel(description);
+ var viewModel = new ProviderViewModel(description);
expect(viewModel.name).toEqual(description.name);
expect(viewModel.tooltip).toEqual(description.tooltip);
expect(viewModel.iconUrl).toEqual(description.iconUrl);
@@ -110,7 +110,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
@@ -122,7 +122,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
@@ -134,7 +134,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
@@ -146,7 +146,7 @@ defineSuite([
};
expect(function() {
- return new ImageryProviderViewModel(description);
+ return new ProviderViewModel(description);
}).toThrowDeveloperError();
});
});
diff --git a/Specs/Widgets/Viewer/ViewerSpec.js b/Specs/Widgets/Viewer/ViewerSpec.js
index 216dd8ae9325..27e11dfad6b4 100644
--- a/Specs/Widgets/Viewer/ViewerSpec.js
+++ b/Specs/Widgets/Viewer/ViewerSpec.js
@@ -3,7 +3,7 @@ defineSuite([
'Widgets/Viewer/Viewer',
'Widgets/Animation/Animation',
'Widgets/BaseLayerPicker/BaseLayerPicker',
- 'Widgets/BaseLayerPicker/ImageryProviderViewModel',
+ 'Widgets/BaseLayerPicker/ProviderViewModel',
'Widgets/CesiumWidget/CesiumWidget',
'Widgets/FullscreenButton/FullscreenButton',
'Widgets/HomeButton/HomeButton',
@@ -24,7 +24,7 @@ defineSuite([
Viewer,
Animation,
BaseLayerPicker,
- ImageryProviderViewModel,
+ ProviderViewModel,
CesiumWidget,
FullscreenButton,
HomeButton,
@@ -50,7 +50,7 @@ defineSuite([
}
};
- var testProviderViewModel = new ImageryProviderViewModel({
+ var testProviderViewModel = new ProviderViewModel({
name : 'name',
tooltip : 'tooltip',
iconUrl : 'url',
@@ -265,6 +265,7 @@ defineSuite([
var provider = new EllipsoidTerrainProvider();
viewer = new Viewer(container, {
+ baseLayerPicker : false,
terrainProvider : provider
});
expect(viewer.centralBody.terrainProvider).toBe(provider);
@@ -323,7 +324,7 @@ defineSuite([
});
expect(viewer.centralBody.imageryLayers.length).toEqual(1);
expect(viewer.centralBody.imageryLayers.get(0).imageryProvider).toBe(testProvider);
- expect(viewer.baseLayerPicker.viewModel.selectedItem).toBe(testProviderViewModel);
+ expect(viewer.baseLayerPicker.viewModel.selectedImagery).toBe(testProviderViewModel);
});
it('can set imageryProvider when BaseLayerPicker is disabled', function() {
@@ -343,7 +344,7 @@ defineSuite([
});
expect(viewer.centralBody.imageryLayers.length).toEqual(1);
expect(viewer.centralBody.imageryLayers.get(0).imageryProvider).toBe(testProvider);
- expect(viewer.baseLayerPicker.viewModel.selectedItem).toBe(testProviderViewModel);
+ expect(viewer.baseLayerPicker.viewModel.selectedImagery).toBe(testProviderViewModel);
expect(viewer.baseLayerPicker.viewModel.imageryProviderViewModels).toEqual(models);
});