Skip to content

Commit

Permalink
version 1.1.3
Browse files Browse the repository at this point in the history
(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
Larcius committed Oct 19, 2016
1 parent e83aa26 commit 542840a
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 480 deletions.
494 changes: 48 additions & 446 deletions Examples/Build/amd.min.js

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions Examples/Source/SpirographPositionProperty_amd-build.js
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;
});
39 changes: 39 additions & 0 deletions Examples/Source/amd/main-build.js
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);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require([
'Cesium/Cesium',
'Source/SpirographPositionProperty_amd',
'Source/SpirographPositionProperty_amd-source',
'viewerCesiumNavigationMixin'
], function(
Cesium,
Expand Down
12 changes: 10 additions & 2 deletions Examples/Source/mainConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ requirejs.config({
paths: {
// IMPORTANT: this path has to be set because
// viewerCesiumNavigationMixin uses 'Cesium/...' for dependencies
Cesium: "../node_modules/cesium/Source",
viewerCesiumNavigationMixin: "../dist/amd/viewerCesiumNavigationMixin.min"
Cesium: "../node_modules/cesium/Build/Cesium/Cesium",
viewerCesiumNavigationMixin: "../dist/amd/viewerCesiumNavigationMixin"
},
shim: {
"Cesium": {
exports: "Cesium",
// deps: [
// "require-css!../../node_modules/cesium/Build/Cesium/Widgets/widgets.css"
// ]
}
}
});
15 changes: 15 additions & 0 deletions Examples/amd.html → Examples/amd_build.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
<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/Build/Cesium/Cesium"
},
shim: {
"Cesium": {
exports: "Cesium",
}
}
});
</script>
<style>
@import url(node_modules/cesium/Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
Expand Down
2 changes: 1 addition & 1 deletion Examples/amd_except_cesium.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div id="cesiumContainer"></div>
<script>
// IMPORTANT: because the cesium navigation viewer mixin depends on Cesium be sure to load Cesium before the first attempt of using it
require(['dist/standalone/viewerCesiumNavigationMixin.min'], function(viewerCesiumNavigationMixin) {
require(['dist/amd/viewerCesiumNavigationMixin.min'], function(viewerCesiumNavigationMixin) {
'use strict';

// You can also access viewerCesiumNavigationMixin via
Expand Down
41 changes: 41 additions & 0 deletions Examples/amd_source.html
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>
6 changes: 5 additions & 1 deletion Examples/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ var config = {
baseUrl: '.',
optimize: 'uglify2',
mainConfigFile: 'Source/mainConfig.js',
name: "Source/amd/main",
name: "Source/amd/main-build",
out: "Build/amd.min.js",
paths: {
// do not include Cesium in the build file but rather access it seperately from browser
Cesium: "empty:"
},
logLevel: 0
};

Expand Down
12 changes: 7 additions & 5 deletions Examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
</head>
<body>
<h1>Cesium-Navigation Examples</h1>
<p>Three examples are available, one demonstrating the standalone, one the AMD compatible edition and one the combination of using AMD but with a global Cesium access</p>
<p>Five examples are available where the output is always the same concerning only the user interface but they differ in how they were created.</p>
<dl>
<dt><a href="sources.html">Sources Example</a></dt>
<dd>Using the sources without building anything. This is also great for developing/debugging the source since any changes are available on browser refresh.</dd>
<dd>Using the sources without building anything. This is also great for developing/debugging the sources since any changes are available on browser refresh.</dd>
<dt><a href="standalone.html">Standalone Example</a></dt>
<dd>No AMD loader is needed but Cesium has to be defined as global variable.</dd>
<dt><a href="amd_except_cesium.html">Using AMD except for Cesium Example</a></dt>
<dd>Using AMD except for Cesium (so Cesium is not accessed via AMD but is a global variable). In this case, of course, no path to Cesium has to be set and so one can use the standalone edition.</dd>
<dt><a href="amd.html">Asynchronous Module Definition (AMD) with requirejs.optimize Example (needs to be built)</a></dt>
<dd>When using the AMD compatible version make sure to set 'Cesium' to point to the Cesium source directory.</dd>
<dd>Using AMD except for Cesium (so Cesium is not accessed via AMD but is a global variable). Since this mixin is accessed via AMD the AMD compatible version is used. The version automatically checks if Cesium is globally accessible and if so it does not try to load Cesium via AMD.</dd>
<dt><a href="amd_source.html">Asynchronous Module Definition (AMD) without requirejs.optimize Example</a></dt>
<dd>When using the AMD compatible version make sure to set 'Cesium' either to point to the Cesium source directory or to the built Cesium.js file.</dd>
<dt><a href="amd_build.html">Asynchronous Module Definition (AMD) with requirejs.optimize Example (needs to be built)</a></dt>
<dd>When using the AMD compatible version make sure to set 'Cesium' either to point to the Cesium source directory or to the built Cesium.js file.</dd>
</dl>

<script type="text/javascript">
Expand Down
4 changes: 2 additions & 2 deletions Examples/sources.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
});
</script>
<style>
@import url(node_modules/cesium/Build/Cesium/Widgets/widgets.css);
@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>
<script type="text/javascript" src="Source/amd/main.js"></script>
<script type="text/javascript" src="Source/amd/main-source.js"></script>
</body>
</html>
Loading

0 comments on commit 542840a

Please sign in to comment.