Add existing to tracked
This commit is contained in:
+97
@@ -0,0 +1,97 @@
|
||||
import {
|
||||
defined,
|
||||
destroyObject,
|
||||
DeveloperError,
|
||||
getElement,
|
||||
} from "@cesium/engine";
|
||||
import knockout from "../ThirdParty/knockout.js";
|
||||
import HomeButtonViewModel from "./HomeButtonViewModel.js";
|
||||
|
||||
/**
|
||||
* A single button widget for returning to the default camera view of the current scene.
|
||||
*
|
||||
* @alias HomeButton
|
||||
* @constructor
|
||||
*
|
||||
* @param {Element|string} container The DOM element or ID that will contain the widget.
|
||||
* @param {Scene} scene The Scene instance to use.
|
||||
* @param {number} [duration] The time, in seconds, it takes to complete the camera flight home.
|
||||
*/
|
||||
function HomeButton(container, scene, duration) {
|
||||
//>>includeStart('debug', pragmas.debug);
|
||||
if (!defined(container)) {
|
||||
throw new DeveloperError("container is required.");
|
||||
}
|
||||
//>>includeEnd('debug');
|
||||
|
||||
container = getElement(container);
|
||||
|
||||
const viewModel = new HomeButtonViewModel(scene, duration);
|
||||
|
||||
viewModel._svgPath =
|
||||
"M14,4l-10,8.75h20l-4.25-3.7188v-4.6562h-2.812v2.1875l-2.938-2.5625zm-7.0938,9.906v10.094h14.094v-10.094h-14.094zm2.1876,2.313h3.3122v4.25h-3.3122v-4.25zm5.8442,1.281h3.406v6.438h-3.406v-6.438z";
|
||||
|
||||
const element = document.createElement("button");
|
||||
element.type = "button";
|
||||
element.className = "cesium-button cesium-toolbar-button cesium-home-button";
|
||||
element.setAttribute(
|
||||
"data-bind",
|
||||
"\
|
||||
attr: { title: tooltip },\
|
||||
click: command,\
|
||||
cesiumSvgPath: { path: _svgPath, width: 28, height: 28 }",
|
||||
);
|
||||
|
||||
container.appendChild(element);
|
||||
|
||||
knockout.applyBindings(viewModel, element);
|
||||
|
||||
this._container = container;
|
||||
this._viewModel = viewModel;
|
||||
this._element = element;
|
||||
}
|
||||
|
||||
Object.defineProperties(HomeButton.prototype, {
|
||||
/**
|
||||
* Gets the parent container.
|
||||
* @memberof HomeButton.prototype
|
||||
*
|
||||
* @type {Element}
|
||||
*/
|
||||
container: {
|
||||
get: function () {
|
||||
return this._container;
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the view model.
|
||||
* @memberof HomeButton.prototype
|
||||
*
|
||||
* @type {HomeButtonViewModel}
|
||||
*/
|
||||
viewModel: {
|
||||
get: function () {
|
||||
return this._viewModel;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @returns {boolean} true if the object has been destroyed, false otherwise.
|
||||
*/
|
||||
HomeButton.prototype.isDestroyed = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys the widget. Should be called if permanently
|
||||
* removing the widget from layout.
|
||||
*/
|
||||
HomeButton.prototype.destroy = function () {
|
||||
knockout.cleanNode(this._element);
|
||||
this._container.removeChild(this._element);
|
||||
|
||||
return destroyObject(this);
|
||||
};
|
||||
export default HomeButton;
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
import { defined, DeveloperError } from "@cesium/engine";
|
||||
import knockout from "../ThirdParty/knockout.js";
|
||||
import createCommand from "../createCommand.js";
|
||||
|
||||
/**
|
||||
* The view model for {@link HomeButton}.
|
||||
* @alias HomeButtonViewModel
|
||||
* @constructor
|
||||
*
|
||||
* @param {Scene} scene The scene instance to use.
|
||||
* @param {number} [duration] The duration of the camera flight in seconds.
|
||||
*/
|
||||
function HomeButtonViewModel(scene, duration) {
|
||||
//>>includeStart('debug', pragmas.debug);
|
||||
if (!defined(scene)) {
|
||||
throw new DeveloperError("scene is required.");
|
||||
}
|
||||
//>>includeEnd('debug');
|
||||
|
||||
this._scene = scene;
|
||||
this._duration = duration;
|
||||
|
||||
const that = this;
|
||||
this._command = createCommand(function () {
|
||||
that._scene.camera.flyHome(that._duration);
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets or sets the tooltip. This property is observable.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.tooltip = "View Home";
|
||||
|
||||
knockout.track(this, ["tooltip"]);
|
||||
}
|
||||
|
||||
Object.defineProperties(HomeButtonViewModel.prototype, {
|
||||
/**
|
||||
* Gets the scene to control.
|
||||
* @memberof HomeButtonViewModel.prototype
|
||||
*
|
||||
* @type {Scene}
|
||||
*/
|
||||
scene: {
|
||||
get: function () {
|
||||
return this._scene;
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the Command that is executed when the button is clicked.
|
||||
* @memberof HomeButtonViewModel.prototype
|
||||
*
|
||||
* @type {Command}
|
||||
*/
|
||||
command: {
|
||||
get: function () {
|
||||
return this._command;
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets or sets the the duration of the camera flight in seconds.
|
||||
* A value of zero causes the camera to instantly switch to home view.
|
||||
* The duration will be computed based on the distance when undefined.
|
||||
* @memberof HomeButtonViewModel.prototype
|
||||
*
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
duration: {
|
||||
get: function () {
|
||||
return this._duration;
|
||||
},
|
||||
set: function (value) {
|
||||
//>>includeStart('debug', pragmas.debug);
|
||||
if (defined(value) && value < 0) {
|
||||
throw new DeveloperError("value must be positive.");
|
||||
}
|
||||
//>>includeEnd('debug');
|
||||
|
||||
this._duration = value;
|
||||
},
|
||||
},
|
||||
});
|
||||
export default HomeButtonViewModel;
|
||||
Reference in New Issue
Block a user