-
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.
Merge pull request #24 from Larcius/master
Handling tracked entities
- Loading branch information
Showing
22 changed files
with
1,842 additions
and
719 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,134 @@ | ||
/** | ||
* Created by G.Cordes on 01.06.16. | ||
*/ | ||
|
||
(function (Cesium) { | ||
/** | ||
* 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); | ||
}; | ||
|
||
Cesium.SpirographPositionProperty = SpirographPositionProperty; | ||
|
||
})(Cesium); |
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/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; | ||
}); |
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 |
---|---|---|
@@ -1,43 +1,39 @@ | ||
require([ | ||
'Cesium/Core/Cartesian3', | ||
'Cesium/Core/Math', | ||
'Cesium/Core/Transforms', | ||
'Cesium/Widgets/Viewer/Viewer', | ||
'Cesium/Cesium', | ||
'Source/SpirographPositionProperty_amd', | ||
'viewerCesiumNavigationMixin' | ||
], function( | ||
Cartesian3, | ||
CesiumMath, | ||
Transforms, | ||
Viewer, | ||
Cesium, | ||
SpirographPositionProperty, | ||
viewerCesiumNavigationMixin) { | ||
"use strict"; | ||
|
||
var cesiumViewer = new Viewer('cesiumContainer'); | ||
var cesiumViewer = new Cesium.Viewer('cesiumContainer'); | ||
|
||
// extend our view by the cesium navigaton mixin | ||
// extend our view by the cesium navigation mixin | ||
cesiumViewer.extend(viewerCesiumNavigationMixin, {}); | ||
// you can access the cesium navigation by cesiumViewer.cesiumNavigation or cesiumViewer.cesiumWidget.cesiumNavigation | ||
|
||
// just some entities | ||
function createModel(url, longitude, latitude, height) { | ||
var position = Cartesian3.fromDegrees(longitude, latitude, height); | ||
var heading = CesiumMath.toRadians(135); | ||
var pitch = 0; | ||
var roll = 0; | ||
var orientation = Transforms.headingPitchRollQuaternion(position, heading, pitch, roll); | ||
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); | ||
|
||
var entity = cesiumViewer.entities.add({ | ||
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 : position, | ||
orientation : orientation, | ||
position: spirographPositionProperty, | ||
orientation: new Cesium.VelocityOrientationProperty(spirographPositionProperty, cesiumViewer.scene.globe.ellipsoid), | ||
model : { | ||
uri : url, | ||
minimumPixelSize : 96 | ||
} | ||
}); | ||
} | ||
|
||
createModel('models/Cesium_Air.glb', -100, 44, 10000.0); | ||
createModel('models/Cesium_Ground.glb', -122, 45, 0); | ||
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); | ||
}); |
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.