Skip to content

Commit

Permalink
preliminary support for Proj4JS and Custom Projections in Columbus View
Browse files Browse the repository at this point in the history
  • Loading branch information
likangning93 committed Aug 31, 2018
1 parent c8cf473 commit 187963c
Show file tree
Hide file tree
Showing 50 changed files with 8,278 additions and 283 deletions.
95 changes: 95 additions & 0 deletions Apps/Sandcastle/gallery/Custom Projection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!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 Custom projections.">
<meta name="cesium-sandcastle-labels" content="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">
if(typeof require === "function") {
require.config({
baseUrl : '../../../Source',
waitSeconds : 120
});
}
</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"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin

var projectionTextUrl = 'data:,' +
'function projectionFactory(callback) {\n' +
' function project(longitude, latitude, result) {\n' +
' result[0] = longitude * 6378137.0;\n' +
' result[1] = latitude * 2.0 * 6378137.0;\n' +
' }\n' +
' function unproject(x, y, result) {\n' +
' result[0] = x / 6378137.0;\n' +
' result[1] = y / (2.0 * 6378137.0);\n' +
' }\n' +
' callback(project, unproject);\n' +
' }\n';

var customProjection = new Cesium.CustomProjection(projectionTextUrl, 'projectionFactory');
customProjection.readyPromise
.then(function(projection) {

var viewer = new Cesium.Viewer('cesiumContainer', {
sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
mapProjection : projection
});

var pointEntities = [];
function addPoint(longitude, latitude) {
pointEntities.push(viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
point : {
pixelSize : 5,
color : Cesium.Color.PURPLE,
disableDepthTestDistance : Number.POSITIVE_INFINITY
},
id : 'longitude: ' + longitude + ' latitude: ' + latitude
}));
}

// Add lat/long points
for (var x = -175; x < 180; x += 10) {
for (var y = -85; y < 90; y += 10) {
addPoint(x, y);
}
}

Sandcastle.addToolbarButton('Show/Hide Points', function() {
for (var i = 0; i < pointEntities.length; i++) {
pointEntities[i].show = !pointEntities[i].show;
}
});

}).otherwise(function(e) {
console.log(e);
});

//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/Custom Projection.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions Apps/Sandcastle/gallery/Proj4Js Projection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!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 Proj4JS projections.">
<meta name="cesium-sandcastle-labels" content="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">
if(typeof require === "function") {
require.config({
baseUrl : '../../../Source',
waitSeconds : 120
});
}
</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"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
mapProjection : new Cesium.Proj4Projection('+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs')
});

var pointEntities = [];
function addPoint(longitude, latitude) {
pointEntities.push(viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
point : {
pixelSize : 5,
color : Cesium.Color.PURPLE,
disableDepthTestDistance : Number.POSITIVE_INFINITY
},
id : 'longitude: ' + longitude + ' latitude: ' + latitude
}));
}

// Add lat/long points
for (var x = -175; x < 180; x += 10) {
for (var y = -85; y < 90; y += 10) {
addPoint(x, y);
}
}

Sandcastle.addToolbarButton('Show/Hide Points', function() {
for (var i = 0; i < pointEntities.length; i++) {
pointEntities[i].show = !pointEntities[i].show;
}
});

//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/Proj4Js Projection.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,37 @@ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

### proj4js

> Authors:
> - Mike Adair madairATdmsolutions.ca
> - Richard Greenwood richATgreenwoodmap.com
> - Didier Richard didier.richardATign.fr
> - Stephen Irons stephen.ironsATclear.net.nz
> - Olivier Terral oterralATgmail.com
> - Calvin Metcalf cmetcalfATappgeo.com
> Copyright (c) 2014, Mike Adair, Richard Greenwood, Didier Richard, Stephen Irons, Olivier Terral and Calvin Metcalf
> Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

> The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

>
_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE._

### crunch

https://github.com/BinomialLLC/crunch
Expand Down
76 changes: 61 additions & 15 deletions Source/Core/BoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ define([
'./Cartesian3',
'./Cartographic',
'./Check',
'./CustomProjection',
'./defaultValue',
'./defined',
'./Ellipsoid',
Expand All @@ -11,11 +12,13 @@ define([
'./Math',
'./Matrix3',
'./Matrix4',
'./Proj4Projection',
'./Rectangle'
], function(
Cartesian3,
Cartographic,
Check,
CustomProjection,
defaultValue,
defined,
Ellipsoid,
Expand All @@ -25,6 +28,7 @@ define([
CesiumMath,
Matrix3,
Matrix4,
Proj4Projection,
Rectangle) {
'use strict';

Expand Down Expand Up @@ -235,6 +239,19 @@ define([
return BoundingSphere.fromRectangleWithHeights2D(rectangle, projection, 0.0, 0.0, result);
};

var projectedPointsScratch = [
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3(),
new Cartesian3(), new Cartesian3()
];
var sampleScratch = new Cartographic();
var cornerScratch = new Cartographic();

/**
* Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the
* object's minimum and maximum heights over the rectangle.
Expand All @@ -259,24 +276,53 @@ define([

projection = defaultValue(projection, defaultProjection);

Rectangle.southwest(rectangle, fromRectangle2DSouthwest);
fromRectangle2DSouthwest.height = minimumHeight;
Rectangle.northeast(rectangle, fromRectangle2DNortheast);
fromRectangle2DNortheast.height = maximumHeight;
if (projection.isEquatorialCylindrical) {
Rectangle.southwest(rectangle, fromRectangle2DSouthwest);
fromRectangle2DSouthwest.height = minimumHeight;
Rectangle.northeast(rectangle, fromRectangle2DNortheast);
fromRectangle2DNortheast.height = maximumHeight;

var lowerLeft = projection.project(fromRectangle2DSouthwest, fromRectangle2DLowerLeft);
var upperRight = projection.project(fromRectangle2DNortheast, fromRectangle2DUpperRight);
var lowerLeft = projection.project(fromRectangle2DSouthwest, fromRectangle2DLowerLeft);
var upperRight = projection.project(fromRectangle2DNortheast, fromRectangle2DUpperRight);

var width = upperRight.x - lowerLeft.x;
var height = upperRight.y - lowerLeft.y;
var elevation = upperRight.z - lowerLeft.z;
var width = upperRight.x - lowerLeft.x;
var height = upperRight.y - lowerLeft.y;
var elevation = upperRight.z - lowerLeft.z;

result.radius = Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;
var center = result.center;
center.x = lowerLeft.x + width * 0.5;
center.y = lowerLeft.y + height * 0.5;
center.z = lowerLeft.z + elevation * 0.5;
return result;
result.radius = Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;
var center = result.center;
center.x = lowerLeft.x + width * 0.5;
center.y = lowerLeft.y + height * 0.5;
center.z = lowerLeft.z + elevation * 0.5;
return result;
}

var southwest = Rectangle.southwest(rectangle, cornerScratch);
var halfWidth = rectangle.width * 0.5;
var halfHeight = rectangle.height * 0.5;
var sample = sampleScratch;
var index = 0;

// Project 18 points, one for each corner, the edge centers, and minimum/maximum height
for (var x = 0; x < 3; x++) {
for (var y = 0; y < 3; y++) {
if (x === 1 && y === 1) {
continue;
}
sample.longitude = southwest.longitude + x * halfWidth;
sample.latitude = southwest.latitude + y * halfHeight;
sample.height = minimumHeight;

projection.project(sample, projectedPointsScratch[index]);

sample.height = maximumHeight;
projection.project(sample, projectedPointsScratch[index + 8]);

index++;
}
}

return BoundingSphere.fromPoints(projectedPointsScratch, result);
};

var fromRectangle3DScratch = [];
Expand Down
Loading

0 comments on commit 187963c

Please sign in to comment.