-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(the core has not been changed but only the build script and the examples) * improved AMD compatible version: it automatically checks if Cesium is accessible via the source directory (i.e. Cesium is pointing to <cesium>/Source folder), via the built version of Cesium (i.e. Cesium is pointing to <cesium>/Build/Cesium/Cesium.js) or globally (i.e. Cesium does not point anywhere but Cesium was loaded without AMD) * added new example where AMD is used but without require.optimize * slightly adapted examples to fit new version
- Loading branch information
Showing
14 changed files
with
350 additions
and
480 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
137 changes: 137 additions & 0 deletions
137
Examples/Source/SpirographPositionProperty_amd-build.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* Created by G.Cordes on 01.06.16. | ||
*/ | ||
|
||
define([ | ||
'Cesium' | ||
], function (Cesium) { | ||
"use strict"; | ||
|
||
/** | ||
* A position property that simulates a spirograph | ||
* @constructor | ||
* | ||
* @param {Cesium.Cartographic} center The center of the spirograph | ||
* @param {Number} radiusMedian The radius of the median circle | ||
* @param {Number} radiusSubCircle the maximum distance to the median circle | ||
* @param {Number} durationMedianCircle The duration in milliseconds to orbit the median circle | ||
* @param {Number} durationSubCircle The duration in milliseconds to orbit the sub circle | ||
* @param {Cesium.Ellipsoid} [ellipsoid=Cesium.Ellipsoid.WGS84] The ellipsoid to convert cartographic to cartesian | ||
*/ | ||
var SpirographPositionProperty = function(center, radiusMedian, radiusSubCircle, durationMedianCircle, durationSubCircle, ellipsoid) { | ||
this._center = center; | ||
this._radiusMedian = radiusMedian; | ||
this._radiusSubCircle = radiusSubCircle; | ||
|
||
this._durationMedianCircle = durationMedianCircle; | ||
this._durationSubCircle = durationSubCircle; | ||
|
||
if(!Cesium.defined(ellipsoid)) { | ||
ellipsoid = Cesium.Ellipsoid.WGS84; | ||
} | ||
this._ellipsoid = ellipsoid; | ||
|
||
this._definitionChanged = new Cesium.Event(); | ||
}; | ||
|
||
Cesium.defineProperties(SpirographPositionProperty.prototype, { | ||
/** | ||
* Gets a value indicating if this property is constant. A property is considered | ||
* constant if getValue always returns the same result for the current definition. | ||
* @memberof PositionProperty.prototype | ||
* | ||
* @type {Boolean} | ||
* @readonly | ||
*/ | ||
isConstant : { | ||
get : function() { | ||
return this._radiusMedian == 0 && this._radiusSubCircle == 0; | ||
} | ||
}, | ||
/** | ||
* Gets the event that is raised whenever the definition of this property changes. | ||
* The definition is considered to have changed if a call to getValue would return | ||
* a different result for the same time. | ||
* @memberof PositionProperty.prototype | ||
* | ||
* @type {Event} | ||
* @readonly | ||
*/ | ||
definitionChanged : { | ||
get : function() { | ||
return this._definitionChanged; | ||
} | ||
}, | ||
/** | ||
* Gets the reference frame that the position is defined in. | ||
* @memberof PositionProperty.prototype | ||
* @type {ReferenceFrame} | ||
*/ | ||
referenceFrame : { | ||
get : function() { | ||
return Cesium.ReferenceFrame.FIXED; | ||
} | ||
} | ||
}); | ||
|
||
/** | ||
* Gets the value of the property at the provided time in the fixed frame. | ||
* @function | ||
* | ||
* @param {JulianDate} time The time for which to retrieve the value. | ||
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. | ||
* @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. | ||
*/ | ||
SpirographPositionProperty.prototype.getValue = function(time, result) { | ||
return this.getValueInReferenceFrame(time, Cesium.ReferenceFrame.FIXED, result); | ||
}; | ||
|
||
var cartographicScratch = new Cesium.Cartographic(); | ||
|
||
/** | ||
* Gets the value of the property at the provided time and in the provided reference frame. | ||
* @function | ||
* | ||
* @param {JulianDate} time The time for which to retrieve the value. | ||
* @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. | ||
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. | ||
* @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. | ||
*/ | ||
SpirographPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) { | ||
var milliseconds = Cesium.JulianDate.toDate(time).getTime(); | ||
|
||
var radius = this._radiusMedian + this._radiusSubCircle * Math.sin(2 * Math.PI * (milliseconds / this._durationSubCircle)); | ||
|
||
cartographicScratch.latitude = this._center.latitude + radius * Math.cos(2 * Math.PI * (milliseconds / this._durationMedianCircle)); | ||
cartographicScratch.longitude = this._center.longitude + radius * Math.sin(2 * Math.PI * (milliseconds / this._durationMedianCircle)); | ||
cartographicScratch.height = this._center.height; | ||
|
||
result = this._ellipsoid.cartographicToCartesian(cartographicScratch, result); | ||
|
||
if(referenceFrame == Cesium.ReferenceFrame.FIXED) { | ||
return result; | ||
} | ||
|
||
return Cesium.PositionProperty.convertToReferenceFrame(time, result, Cesium.ReferenceFrame.FIXED, referenceFrame, result); | ||
}; | ||
|
||
/** | ||
* Compares this property to the provided property and returns | ||
* <code>true</code> if they are equal, <code>false</code> otherwise. | ||
* @function | ||
* | ||
* @param {Property} [other] The other property. | ||
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise. | ||
*/ | ||
SpirographPositionProperty.prototype.equals = function(other) { | ||
return other instanceof SpirographPositionProperty | ||
&& this._center.equals(other._center) | ||
&& this._radiusMedian == other._radiusMedian | ||
&& this._radiusSubCircle == other._radiusSubCircle | ||
&& this._durationMedianCircle == other._durationMedianCircle | ||
&& this._durationSubCircle == other._durationSubCircle | ||
&& this._ellipsoid.equals(other._ellipsoid); | ||
}; | ||
|
||
return SpirographPositionProperty; | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require([ | ||
'Cesium', | ||
'Source/SpirographPositionProperty_amd-build', | ||
'viewerCesiumNavigationMixin' | ||
], function( | ||
Cesium, | ||
SpirographPositionProperty, | ||
viewerCesiumNavigationMixin) { | ||
"use strict"; | ||
|
||
var cesiumViewer = new Cesium.Viewer('cesiumContainer'); | ||
|
||
// extend our view by the cesium navigation mixin | ||
cesiumViewer.extend(viewerCesiumNavigationMixin, {}); | ||
// you can access the cesium navigation by cesiumViewer.cesiumNavigation or cesiumViewer.cesiumWidget.cesiumNavigation | ||
|
||
function createSpirographEntity(url, longitude, latitude, height, radiusMedian, radiusSubCircle, | ||
durationMedianCircle, durationSubCircle) { | ||
var centerPosition = Cesium.Cartographic.fromDegrees(longitude, latitude, height); | ||
var spirographPositionProperty = new SpirographPositionProperty(centerPosition, radiusMedian, radiusSubCircle, | ||
durationMedianCircle, durationSubCircle, cesiumViewer.scene.globe.ellipsoid); | ||
|
||
cesiumViewer.entities.add({ | ||
name : url, | ||
description: 'It is supposed to have a useful desciption here<br />but instead there is just a placeholder to get a larger info box', | ||
position: spirographPositionProperty, | ||
orientation: new Cesium.VelocityOrientationProperty(spirographPositionProperty, cesiumViewer.scene.globe.ellipsoid), | ||
model : { | ||
uri : url, | ||
minimumPixelSize : 96 | ||
} | ||
}); | ||
} | ||
|
||
createSpirographEntity('models/Cesium_Air.glb', -100, 44, 10000.0, | ||
Cesium.Math.toRadians(0.5), Cesium.Math.toRadians(2), 1e6, 2e5); | ||
createSpirographEntity('models/Cesium_Ground.glb', -122, 45, 0, | ||
Cesium.Math.toRadians(0.1), Cesium.Math.toRadians(1), 5e6, 7e5); | ||
}); |
2 changes: 1 addition & 1 deletion
2
Examples/Source/amd/main.js → Examples/Source/amd/main-source.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Cesium-Navigation Example (using requirejs.optimize)</title> | ||
<script type="text/javascript" src="node_modules/requirejs/require.js"></script> | ||
<script type="text/javascript"> | ||
requirejs.config({ | ||
baseUrl: '.', | ||
paths: { | ||
// IMPORTANT: this path has to be set because | ||
// viewerCesiumNavigationMixin uses 'Cesium/...' for dependencies | ||
Cesium: "../node_modules/cesium/Source", | ||
viewerCesiumNavigationMixin: "../dist/amd/viewerCesiumNavigationMixin" | ||
} | ||
}); | ||
</script> | ||
<style> | ||
@import url(node_modules/cesium/Source/Widgets/widgets.css); | ||
html, body, #cesiumContainer { | ||
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="cesiumContainer"></div> | ||
<!-- This file was built with nodejs and requirejs.optimize --> | ||
<!-- The main file was Source/amd/main.js --> | ||
<!-- To build this file on your own, simply run `node build.js` (for the first time you might need to run `npm install`) --> | ||
<script type="text/javascript" src="Source/amd/main-source.js"></script> | ||
|
||
<script type="text/javascript"> | ||
// show info if accessed directly from disk | ||
if (window.location.protocol === 'file:') { | ||
document.body.innerHTML = ""; | ||
document.write('<p><b>This file must be hosted in a web server.</br>'); | ||
document.write('See our <a href="https://cesiumjs.org/tutorials/cesium-up-and-running/#setting-up-a-web-server">Getting Started</a> '); | ||
document.write('tutorial for a step-by-step guide.</b></p>'); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.