Skip to content

Commit

Permalink
Merge branch 'master' into polylinesOnTerrain-entity
Browse files Browse the repository at this point in the history
  • Loading branch information
likangning93 committed Jun 18, 2018
2 parents d6c37fa + 6f66dbf commit 16c2f0c
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 7 deletions.
113 changes: 113 additions & 0 deletions Apps/Sandcastle/gallery/Multiple Synced Views.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Multiple views synced across time and space.">
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
#cesiumContainer {
display: flex;
width: 100%;
height: 100%;
}
#view3D {
display: inline-block;
width: 100%;
}
#view2D {
display: inline-block;
width: 100%;
}
</style>
<div id="cesiumContainer" class="fullSize">
<div id="view3D"></div>
<div id="view2D"></div>
</div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
// We want our two views to be synced across time, so we create
// a shared clock object that both views share
var clockViewModel = new Cesium.ClockViewModel();
var options3D = {
fullscreenButton : false,
sceneModePicker : false,
clockViewModel : clockViewModel
};
var options2D = {
homeButton : false,
fullscreenButton : false,
sceneModePicker : false,
clockViewModel : clockViewModel,
infoBox : false,
geocoder : false,
sceneMode : Cesium.SceneMode.SCENE2D,
navigationHelpButton : false,
animation : false
};
// We create two viewers, a 2D and a 3D one
// The CSS is set up to place them side by side
var view3D = new Cesium.Viewer('view3D', options3D);
var view2D = new Cesium.Viewer('view2D', options2D);

var worldPosition;
var distance;

function sync2DView() {
// The center of the view is the point that the 3D camera is focusing on
var viewCenter = new Cesium.Cartesian2(Math.floor(view3D.canvas.clientWidth / 2), Math.floor(view3D.canvas.clientHeight / 2));
// Given the pixel in the center, get the world position
var newWorldPosition = view3D.scene.camera.pickEllipsoid(viewCenter);
if (Cesium.defined(newWorldPosition)){
// Guard against the case where the center of the screen
// does not fall on a position on the globe
worldPosition = newWorldPosition;
}
// Get the distance between the world position of the point the camera is focusing on, and the camera's world position
distance = Cesium.Cartesian3.distance(worldPosition, view3D.scene.camera.positionWC);
// Tell the 2D camera to look at the point of focus. The distance controls how zoomed in the 2D view is
// (try replacing `distance` in the line below with `1e7`. The view will still sync, but will have a constant zoom)
view2D.scene.camera.lookAt(worldPosition, new Cesium.Cartesian3(0.0, 0.0, distance));
}

// Apply our sync function every time the 3D camera view changes
view3D.camera.changed.addEventListener(sync2DView);
// By default, the `camera.changed` event will trigger when the camera has changed by 50%
// To make it more sensitive, we can bring down this sensitivity
view3D.camera.percentageChanged = 0.01;

// Since the 2D view follows the 3D view, we disable any
// camera movement on the 2D view
view2D.scene.screenSpaceCameraController.enableRotate = false;
view2D.scene.screenSpaceCameraController.enableTranslate = false;
view2D.scene.screenSpaceCameraController.enableZoom = false;
view2D.scene.screenSpaceCameraController.enableTilt = false;
view2D.scene.screenSpaceCameraController.enableLook = false;
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/Multiple Synced Views.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [William Ho](https://github.com/williamkho)
* [Srinivas Kaza](https://github.com/AnimatedRNG)
* [Hannah Bollar](https://github.com/hanbollar)
* [Jane Xu](https://github.com/janeyx99)
* [Luke San Antonio Bialecki](https://github.com/lukesanantonio)
* [Josh Lawrence](https://github.com/loshjawrence)
* [Omar Shehata](https://github.com/OmarShehata)
Expand Down
19 changes: 17 additions & 2 deletions Documentation/Contributors/CodingGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ Because result parameters aren't always required or returned, don't strictly rel
```js
Cartesian3.add(v0, v1, result);
Cartesian3.add(result, v2, result);
```
```
is better written as
```js
result = Cartesian3.add(v0, v1, result);
result = Cartesian3.add(v0, v1, result);
result = Cartesian3.add(result, v2, result);
```

Expand Down Expand Up @@ -544,6 +544,21 @@ var p = new Cartesian3(1.0, 2.0, 3.0);
p.x = 'Cesium'; // Changes x to a string, slows down property access
```

* In a constructor function, consider properties as write once; do not write to them or read them multiple times. Create a local variable if they need to be ready. For example:

Instead of
```javascript
this._x = 2;
this._xSquared = this._x * this._x;
```

prefer
```javascript
var x = 2;
this._x = x;
this._xSquared = x * x;
```

### `from` Constructors

:art: Constructor functions should take the basic components of the class as parameters. For example, `Cartesian3` takes `x`, `y`, and `z`.
Expand Down
14 changes: 14 additions & 0 deletions Source/Core/GroundPolylineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ define([
var normalNudgeScratch = new Cartesian3();

var scratchBoundingSpheres = [new BoundingSphere(), new BoundingSphere()];
var boundingSphereCenterCartographicScratch = new Cartographic();

// Winding order is reversed so each segment's volume is inside-out
var REFERENCE_INDICES = [
Expand Down Expand Up @@ -807,6 +808,9 @@ define([
var lengthSoFar3D = 0.0;
var lengthSoFar2D = 0.0;

// For translating bounding volume
var sumHeights = 0.0;

for (i = 0; i < segmentCount; i++) {
var startBottom = Cartesian3.clone(endBottom, segmentStartBottomScratch);
var startTop = Cartesian3.clone(endTop, segmentStartTopScratch);
Expand Down Expand Up @@ -1005,6 +1009,9 @@ define([
var minHeight = minMaxHeights.minimumTerrainHeight;
var maxHeight = minMaxHeights.maximumTerrainHeight;

sumHeights += minHeight;
sumHeights += maxHeight;

adjustHeights(startBottom, startTop, minHeight, maxHeight, adjustHeightStartBottom, adjustHeightStartTop);
adjustHeights(endBottom, endTop, minHeight, maxHeight, adjustHeightEndBottom, adjustHeightEndTop);

Expand Down Expand Up @@ -1068,6 +1075,13 @@ define([
BoundingSphere.fromVertices(topPositionsArray, Cartesian3.ZERO, 3, boundingSpheres[1]);
var boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);

// Adjust bounding sphere height and radius to cover whole volume
var midHeight = sumHeights / (segmentCount * 2.0);
var boundingSphereCenterCartographic = Cartographic.fromCartesian(boundingSphere.center, ellipsoid, boundingSphereCenterCartographicScratch);
boundingSphereCenterCartographic.height = midHeight;
boundingSphere.center = Cartographic.toCartesian(boundingSphereCenterCartographic, ellipsoid, boundingSphere.center);
boundingSphere.radius = Math.max(boundingSphere.radius, midHeight);

var attributes = {
position : new GeometryAttribute({
componentDatatype : ComponentDatatype.DOUBLE,
Expand Down
20 changes: 20 additions & 0 deletions Specs/Core/GroundPolylineGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,26 @@ defineSuite([
expect(Cartesian3.equalsEpsilon(result, new Cartesian3(1.0, 0.0, 0.0), CesiumMath.EPSILON7)).toBe(true);
});

it('creates bounding spheres that cover the entire polyline volume height', function() {
var positions = Cartesian3.fromDegreesArray([
-122.17580380403314, 46.19984918190237,
-122.17581380403314, 46.19984918190237
]);

// Mt. St. Helens - provided coordinates are a few meters apart
var groundPolylineGeometry = new GroundPolylineGeometry({
positions : positions,
granularity : 0.0 // no interpolative subdivision
});

var geometry = GroundPolylineGeometry.createGeometry(groundPolylineGeometry);

var boundingSphere = geometry.boundingSphere;
var pointsDistance = Cartesian3.distance(positions[0], positions[1]);

expect(boundingSphere.radius > pointsDistance).toBe(true);
});

var packedInstance = [positions.length];
Cartesian3.pack(positions[0], packedInstance, packedInstance.length);
Cartesian3.pack(positions[1], packedInstance, packedInstance.length);
Expand Down
9 changes: 5 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var gulpRename = require('gulp-rename');
var gulpReplace = require('gulp-replace');
var Promise = require('bluebird');
var requirejs = require('requirejs');
var karma = require('karma').Server;
var Karma = require('karma').Server;
var yargs = require('yargs');
var aws = require('aws-sdk');
var mime = require('mime');
Expand Down Expand Up @@ -634,16 +634,16 @@ gulp.task('test', function(done) {
files.push({pattern : 'Build/**', included : false});
}

karma.start({
var karma = new Karma({
configFile: karmaConfigFile,
browsers : browsers,
browsers: browsers,
specReporter: {
suppressErrorSummary: false,
suppressFailed: false,
suppressPassed: suppressPassed,
suppressSkipped: true
},
detectBrowsers : {
detectBrowsers: {
enabled: enableAllBrowsers
},
files: files,
Expand All @@ -653,6 +653,7 @@ gulp.task('test', function(done) {
}, function(e) {
return done(failTaskOnError ? e : undefined);
});
karma.start();
});

gulp.task('generateStubs', ['build'], function(done) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"gulp-zip": "^4.0.0",
"jasmine-core": "^3.1.0",
"jsdoc": "^3.4.3",
"karma": "^2.0.0",
"karma": "^2.0.3",
"karma-chrome-launcher": "^2.0.0",
"karma-detect-browsers": "^2.2.3",
"karma-edge-launcher": "^0.4.2",
Expand Down

0 comments on commit 16c2f0c

Please sign in to comment.