Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into delay-load-gihugic-…
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
mramato committed Oct 15, 2018
2 parents eaef93b + e0e76ba commit b7cae12
Show file tree
Hide file tree
Showing 12 changed files with 459 additions and 110 deletions.
158 changes: 158 additions & 0 deletions Apps/Sandcastle/gallery/Imagery Cutout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!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="Demonstration of imagery layers with rectangular cutouts.">
<meta name="cesium-sandcastle-labels" content="Tutorials">
<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);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
<table class="infoPanel">
<tbody>
<tr>
<td>Click on the Cesium display to start.</td>
</tr>
<tr>
<td>w/s - move cutout north/south</td>
</tr>
<tr>
<td>a/d - move cutout west/east</td>
</tr>
</tbody>
</table>
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider : Cesium.createTileMapServiceImageryProvider({
url : Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
}),
baseLayerPicker : false
});

var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
canvas.onclick = function() {
canvas.focus();
};

var scene = viewer.scene;

var defaultImageryLayerCutout = Cesium.Rectangle.fromDegrees(-90, 20, -70, 40);

// Cut a rectangle out of the base layer
var layers = viewer.imageryLayers;
var imageryBaseLayer = layers.get(0);

imageryBaseLayer.cutoutRectangle = defaultImageryLayerCutout;

// Fit a SingleTileImageryProvider inside the cutout on the lowest layer
layers.addImageryProvider(new Cesium.SingleTileImageryProvider({
url : '../images/Cesium_Logo_overlay.png',
rectangle : defaultImageryLayerCutout
}));

// Add an Earth at Night layer and a "traveling" cutout
var earthAtNight = layers.addImageryProvider(new Cesium.IonImageryProvider({ assetId: 3812 }));
earthAtNight.cutoutRectangle = Cesium.Rectangle.fromDegrees(-100, 10, -60, 50);
earthAtNight.alpha = 0.9;

// "traveling" code
var flags = {
moveEast : false,
moveWest : false,
moveNorth : false,
moveSouth : false
};

function getFlagForKeyCode(keyCode) {
switch (keyCode) {
case 'W'.charCodeAt(0):
return 'moveNorth';
case 'S'.charCodeAt(0):
return 'moveSouth';
case 'D'.charCodeAt(0):
return 'moveEast';
case 'A'.charCodeAt(0):
return 'moveWest';
default:
return undefined;
}
}

document.addEventListener('keydown', function(e) {
var flagName = getFlagForKeyCode(e.keyCode);
if (typeof flagName !== 'undefined') {
flags[flagName] = true;
}
}, false);

document.addEventListener('keyup', function(e) {
var flagName = getFlagForKeyCode(e.keyCode);
if (typeof flagName !== 'undefined') {
flags[flagName] = false;
}
}, false);

var moveIncrement = 0.05;
viewer.clock.onTick.addEventListener(function(clock) {
var travelingRectangle = earthAtNight.cutoutRectangle;
if (flags.moveNorth && travelingRectangle.north + moveIncrement < Cesium.Math.PI_OVER_TWO) {
travelingRectangle.north += moveIncrement;
travelingRectangle.south += moveIncrement;
}
if (flags.moveSouth && travelingRectangle.south - moveIncrement > -Cesium.Math.PI_OVER_TWO) {
travelingRectangle.north -= moveIncrement;
travelingRectangle.south -= moveIncrement;
}
if (flags.moveEast) {
travelingRectangle.east += moveIncrement;
travelingRectangle.west += moveIncrement;
}
if (flags.moveWest) {
travelingRectangle.east -= moveIncrement;
travelingRectangle.west -= moveIncrement;
}
travelingRectangle.east = wrapLongitude(travelingRectangle.east);
travelingRectangle.west = wrapLongitude(travelingRectangle.west);
});

function wrapLongitude(value) {
if (value < -Cesium.Math.PI) {
return value + Cesium.Math.TWO_PI;
}
if (value > Cesium.Math.PI) {
return value - Cesium.Math.TWO_PI;
}
return value;
}

//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/Imagery Cutout.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Change Log
##### Additions :tada:
* Shrink minified and gzipped Cesium.js by 27 KB (~3.7%) by delay loading seldom-used third-party dependencies. [#7140](https://github.com/AnalyticalGraphicsInc/cesium/pull/7140)
* Added WMS-T (time) support in WebMapServiceImageryProvider [#2581](https://github.com/AnalyticalGraphicsInc/cesium/issues/2581)
* Added `cutoutRectangle` to `ImageryLayer`, which allows cutting out rectangular areas in imagery layers to reveal underlying imagery. [#7056](https://github.com/AnalyticalGraphicsInc/cesium/pull/7056)

##### Fixes :wrench:
* Fixed an issue where `pickPosition` would return incorrect results when called after `sampleHeight` or `clampToHeight`. [#7113](https://github.com/AnalyticalGraphicsInc/cesium/pull/7113)

### 1.50 - 2018-10-01

Expand Down
176 changes: 88 additions & 88 deletions Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,94 +120,94 @@ define([
* @return {localFrameToFixedFrameGenerator~resultat} The function that will computes a
* 4x4 transformation matrix from a reference frame, with first axis and second axis compliant with the parameters,
*/
Transforms.localFrameToFixedFrameGenerator = function( firstAxis, secondAxis) {
if (!vectorProductLocalFrame.hasOwnProperty(firstAxis) || !vectorProductLocalFrame[firstAxis].hasOwnProperty(secondAxis)) {
throw new DeveloperError('firstAxis and secondAxis must be east, north, up, west, south or down.');
}
var thirdAxis = vectorProductLocalFrame[firstAxis][secondAxis];

/**
* Computes a 4x4 transformation matrix from a reference frame
* centered at the provided origin to the provided ellipsoid's fixed reference frame.
* @callback Transforms~LocalFrameToFixedFrame
* @param {Cartesian3} origin The center point of the local reference frame.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Matrix4} [result] The object onto which to store the result.
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
*/
var resultat;
var hashAxis = firstAxis + secondAxis;
if (defined(localFrameToFixedFrameCache[hashAxis])) {
resultat = localFrameToFixedFrameCache[hashAxis];
} else {
resultat = function(origin, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(origin)) {
throw new DeveloperError('origin is required.');
}
//>>includeEnd('debug');
if (!defined(result)) {
result = new Matrix4();
}
// If x and y are zero, assume origin is at a pole, which is a special case.
if (CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) && CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)) {
var sign = CesiumMath.sign(origin.z);

Cartesian3.unpack(degeneratePositionLocalFrame[firstAxis], 0, scratchFirstCartesian);
if (firstAxis !== 'east' && firstAxis !== 'west') {
Cartesian3.multiplyByScalar(scratchFirstCartesian, sign, scratchFirstCartesian);
}

Cartesian3.unpack(degeneratePositionLocalFrame[secondAxis], 0, scratchSecondCartesian);
if (secondAxis !== 'east' && secondAxis !== 'west') {
Cartesian3.multiplyByScalar(scratchSecondCartesian, sign, scratchSecondCartesian);
}

Cartesian3.unpack(degeneratePositionLocalFrame[thirdAxis], 0, scratchThirdCartesian);
if (thirdAxis !== 'east' && thirdAxis !== 'west') {
Cartesian3.multiplyByScalar(scratchThirdCartesian, sign, scratchThirdCartesian);
}
} else {
ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
ellipsoid.geodeticSurfaceNormal(origin, scratchCalculateCartesian.up);

var up = scratchCalculateCartesian.up;
var east = scratchCalculateCartesian.east;
east.x = -origin.y;
east.y = origin.x;
east.z = 0.0;
Cartesian3.normalize(east, scratchCalculateCartesian.east);
Cartesian3.cross(up, east, scratchCalculateCartesian.north);

Cartesian3.multiplyByScalar(scratchCalculateCartesian.up, -1, scratchCalculateCartesian.down);
Cartesian3.multiplyByScalar(scratchCalculateCartesian.east, -1, scratchCalculateCartesian.west);
Cartesian3.multiplyByScalar(scratchCalculateCartesian.north, -1, scratchCalculateCartesian.south);

scratchFirstCartesian = scratchCalculateCartesian[firstAxis];
scratchSecondCartesian = scratchCalculateCartesian[secondAxis];
scratchThirdCartesian = scratchCalculateCartesian[thirdAxis];
}
result[0] = scratchFirstCartesian.x;
result[1] = scratchFirstCartesian.y;
result[2] = scratchFirstCartesian.z;
result[3] = 0.0;
result[4] = scratchSecondCartesian.x;
result[5] = scratchSecondCartesian.y;
result[6] = scratchSecondCartesian.z;
result[7] = 0.0;
result[8] = scratchThirdCartesian.x;
result[9] = scratchThirdCartesian.y;
result[10] = scratchThirdCartesian.z;
result[11] = 0.0;
result[12] = origin.x;
result[13] = origin.y;
result[14] = origin.z;
result[15] = 1.0;
return result;
};
localFrameToFixedFrameCache[hashAxis] = resultat;
}
return resultat;
Transforms.localFrameToFixedFrameGenerator = function (firstAxis, secondAxis) {
if (!vectorProductLocalFrame.hasOwnProperty(firstAxis) || !vectorProductLocalFrame[firstAxis].hasOwnProperty(secondAxis)) {
throw new DeveloperError('firstAxis and secondAxis must be east, north, up, west, south or down.');
}
var thirdAxis = vectorProductLocalFrame[firstAxis][secondAxis];

/**
* Computes a 4x4 transformation matrix from a reference frame
* centered at the provided origin to the provided ellipsoid's fixed reference frame.
* @callback Transforms~LocalFrameToFixedFrame
* @param {Cartesian3} origin The center point of the local reference frame.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Matrix4} [result] The object onto which to store the result.
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
*/
var resultat;
var hashAxis = firstAxis + secondAxis;
if (defined(localFrameToFixedFrameCache[hashAxis])) {
resultat = localFrameToFixedFrameCache[hashAxis];
} else {
resultat = function (origin, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(origin)) {
throw new DeveloperError('origin is required.');
}
//>>includeEnd('debug');
if (!defined(result)) {
result = new Matrix4();
}
// If x and y are zero, assume origin is at a pole, which is a special case.
if (CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) && CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)) {
var sign = CesiumMath.sign(origin.z);

Cartesian3.unpack(degeneratePositionLocalFrame[firstAxis], 0, scratchFirstCartesian);
if (firstAxis !== 'east' && firstAxis !== 'west') {
Cartesian3.multiplyByScalar(scratchFirstCartesian, sign, scratchFirstCartesian);
}

Cartesian3.unpack(degeneratePositionLocalFrame[secondAxis], 0, scratchSecondCartesian);
if (secondAxis !== 'east' && secondAxis !== 'west') {
Cartesian3.multiplyByScalar(scratchSecondCartesian, sign, scratchSecondCartesian);
}

Cartesian3.unpack(degeneratePositionLocalFrame[thirdAxis], 0, scratchThirdCartesian);
if (thirdAxis !== 'east' && thirdAxis !== 'west') {
Cartesian3.multiplyByScalar(scratchThirdCartesian, sign, scratchThirdCartesian);
}
} else {
ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
ellipsoid.geodeticSurfaceNormal(origin, scratchCalculateCartesian.up);

var up = scratchCalculateCartesian.up;
var east = scratchCalculateCartesian.east;
east.x = -origin.y;
east.y = origin.x;
east.z = 0.0;
Cartesian3.normalize(east, scratchCalculateCartesian.east);
Cartesian3.cross(up, east, scratchCalculateCartesian.north);

Cartesian3.multiplyByScalar(scratchCalculateCartesian.up, -1, scratchCalculateCartesian.down);
Cartesian3.multiplyByScalar(scratchCalculateCartesian.east, -1, scratchCalculateCartesian.west);
Cartesian3.multiplyByScalar(scratchCalculateCartesian.north, -1, scratchCalculateCartesian.south);

scratchFirstCartesian = scratchCalculateCartesian[firstAxis];
scratchSecondCartesian = scratchCalculateCartesian[secondAxis];
scratchThirdCartesian = scratchCalculateCartesian[thirdAxis];
}
result[0] = scratchFirstCartesian.x;
result[1] = scratchFirstCartesian.y;
result[2] = scratchFirstCartesian.z;
result[3] = 0.0;
result[4] = scratchSecondCartesian.x;
result[5] = scratchSecondCartesian.y;
result[6] = scratchSecondCartesian.z;
result[7] = 0.0;
result[8] = scratchThirdCartesian.x;
result[9] = scratchThirdCartesian.y;
result[10] = scratchThirdCartesian.z;
result[11] = 0.0;
result[12] = origin.x;
result[13] = origin.y;
result[14] = origin.z;
result[15] = 1.0;
return result;
};
localFrameToFixedFrameCache[hashAxis] = resultat;
}
return resultat;
};

/**
Expand Down
Loading

0 comments on commit b7cae12

Please sign in to comment.