Skip to content

Commit 43131e1

Browse files
committed
preliminary support for Proj4JS and Custom Projections in Columbus View
1 parent c8cf473 commit 43131e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8290
-283
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
7+
<meta name="description" content="Demonstration of Custom projections.">
8+
<meta name="cesium-sandcastle-labels" content="Showcases">
9+
<title>Cesium Demo</title>
10+
<script type="text/javascript" src="../Sandcastle-header.js"></script>
11+
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
12+
<script type="text/javascript">
13+
if(typeof require === "function") {
14+
require.config({
15+
baseUrl : '../../../Source',
16+
waitSeconds : 120
17+
});
18+
}
19+
</script>
20+
</head>
21+
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
22+
<style>
23+
@import url(../templates/bucket.css);
24+
</style>
25+
<div id="cesiumContainer" class="fullSize"></div>
26+
<div id="loadingOverlay"><h1>Loading...</h1></div>
27+
<div id="toolbar"></div>
28+
<script id="cesium_sandcastle_script">
29+
function startup(Cesium) {
30+
'use strict';
31+
//Sandcastle_Begin
32+
33+
var projectionTextUrl = 'data:,' +
34+
'function projectionFactory(callback) {\n' +
35+
' function project(longitude, latitude, result) {\n' +
36+
' result[0] = longitude * 6378137.0;\n' +
37+
' result[1] = latitude * 2.0 * 6378137.0;\n' +
38+
' }\n' +
39+
' function unproject(x, y, result) {\n' +
40+
' result[0] = x / 6378137.0;\n' +
41+
' result[1] = y / (2.0 * 6378137.0);\n' +
42+
' }\n' +
43+
' callback(project, unproject);\n' +
44+
' }\n';
45+
46+
var customProjection = new Cesium.CustomProjection(projectionTextUrl, 'projectionFactory');
47+
customProjection.readyPromise
48+
.then(function(projection) {
49+
50+
var viewer = new Cesium.Viewer('cesiumContainer', {
51+
sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
52+
mapProjection : projection
53+
});
54+
55+
var pointEntities = [];
56+
function addPoint(longitude, latitude) {
57+
pointEntities.push(viewer.entities.add({
58+
position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
59+
point : {
60+
pixelSize : 5,
61+
color : Cesium.Color.PURPLE,
62+
disableDepthTestDistance : Number.POSITIVE_INFINITY
63+
},
64+
id : 'longitude: ' + longitude + ' latitude: ' + latitude
65+
}));
66+
}
67+
68+
// Add lat/long points
69+
for (var x = -175; x < 180; x += 10) {
70+
for (var y = -85; y < 90; y += 10) {
71+
addPoint(x, y);
72+
}
73+
}
74+
75+
Sandcastle.addToolbarButton('Show/Hide Points', function() {
76+
for (var i = 0; i < pointEntities.length; i++) {
77+
pointEntities[i].show = !pointEntities[i].show;
78+
}
79+
});
80+
81+
}).otherwise(function(e) {
82+
console.log(e);
83+
});
84+
85+
//Sandcastle_End
86+
Sandcastle.finishedLoading();
87+
}
88+
if (typeof Cesium !== "undefined") {
89+
startup(Cesium);
90+
} else if (typeof require === "function") {
91+
require(["Cesium"], startup);
92+
}
93+
</script>
94+
</body>
95+
</html>
20.8 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
7+
<meta name="description" content="Demonstration of Proj4JS projections.">
8+
<meta name="cesium-sandcastle-labels" content="Showcases">
9+
<title>Cesium Demo</title>
10+
<script type="text/javascript" src="../Sandcastle-header.js"></script>
11+
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
12+
<script type="text/javascript">
13+
if(typeof require === "function") {
14+
require.config({
15+
baseUrl : '../../../Source',
16+
waitSeconds : 120
17+
});
18+
}
19+
</script>
20+
</head>
21+
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
22+
<style>
23+
@import url(../templates/bucket.css);
24+
</style>
25+
<div id="cesiumContainer" class="fullSize"></div>
26+
<div id="loadingOverlay"><h1>Loading...</h1></div>
27+
<div id="toolbar"></div>
28+
<script id="cesium_sandcastle_script">
29+
function startup(Cesium) {
30+
'use strict';
31+
//Sandcastle_Begin
32+
var viewer = new Cesium.Viewer('cesiumContainer', {
33+
sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
34+
mapProjection : new Cesium.Proj4Projection('+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs')
35+
});
36+
37+
var pointEntities = [];
38+
function addPoint(longitude, latitude) {
39+
pointEntities.push(viewer.entities.add({
40+
position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
41+
point : {
42+
pixelSize : 5,
43+
color : Cesium.Color.PURPLE,
44+
disableDepthTestDistance : Number.POSITIVE_INFINITY
45+
},
46+
id : 'longitude: ' + longitude + ' latitude: ' + latitude
47+
}));
48+
}
49+
50+
// Add lat/long points
51+
for (var x = -175; x < 180; x += 10) {
52+
for (var y = -85; y < 90; y += 10) {
53+
addPoint(x, y);
54+
}
55+
}
56+
57+
Sandcastle.addToolbarButton('Show/Hide Points', function() {
58+
for (var i = 0; i < pointEntities.length; i++) {
59+
pointEntities[i].show = !pointEntities[i].show;
60+
}
61+
});
62+
63+
//Sandcastle_End
64+
Sandcastle.finishedLoading();
65+
}
66+
if (typeof Cesium !== "undefined") {
67+
startup(Cesium);
68+
} else if (typeof require === "function") {
69+
require(["Cesium"], startup);
70+
}
71+
</script>
72+
</body>
73+
</html>
27.5 KB
Loading

LICENSE.md

+31
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,37 @@ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
555555
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
556556
THIS SOFTWARE.
557557

558+
### proj4js
559+
560+
> Authors:
561+
> - Mike Adair madairATdmsolutions.ca
562+
> - Richard Greenwood richATgreenwoodmap.com
563+
> - Didier Richard didier.richardATign.fr
564+
> - Stephen Irons stephen.ironsATclear.net.nz
565+
> - Olivier Terral oterralATgmail.com
566+
> - Calvin Metcalf cmetcalfATappgeo.com
567+
568+
> Copyright (c) 2014, Mike Adair, Richard Greenwood, Didier Richard, Stephen Irons, Olivier Terral and Calvin Metcalf
569+
570+
> Permission is hereby granted, free of charge, to any person obtaining a
571+
copy of this software and associated documentation files (the "Software"),
572+
to deal in the Software without restriction, including without limitation
573+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
574+
and/or sell copies of the Software, and to permit persons to whom the
575+
Software is furnished to do so, subject to the following conditions:
576+
577+
> The above copyright notice and this permission notice shall be included
578+
in all copies or substantial portions of the Software.
579+
580+
>
581+
_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
582+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
583+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
584+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
585+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
586+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
587+
DEALINGS IN THE SOFTWARE._
588+
558589
### crunch
559590

560591
https://github.com/BinomialLLC/crunch

Source/Core/BoundingSphere.js

+61-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ define([
22
'./Cartesian3',
33
'./Cartographic',
44
'./Check',
5+
'./CustomProjection',
56
'./defaultValue',
67
'./defined',
78
'./Ellipsoid',
@@ -11,11 +12,13 @@ define([
1112
'./Math',
1213
'./Matrix3',
1314
'./Matrix4',
15+
'./Proj4Projection',
1416
'./Rectangle'
1517
], function(
1618
Cartesian3,
1719
Cartographic,
1820
Check,
21+
CustomProjection,
1922
defaultValue,
2023
defined,
2124
Ellipsoid,
@@ -25,6 +28,7 @@ define([
2528
CesiumMath,
2629
Matrix3,
2730
Matrix4,
31+
Proj4Projection,
2832
Rectangle) {
2933
'use strict';
3034

@@ -235,6 +239,19 @@ define([
235239
return BoundingSphere.fromRectangleWithHeights2D(rectangle, projection, 0.0, 0.0, result);
236240
};
237241

242+
var projectedPointsScratch = [
243+
new Cartesian3(), new Cartesian3(),
244+
new Cartesian3(), new Cartesian3(),
245+
new Cartesian3(), new Cartesian3(),
246+
new Cartesian3(), new Cartesian3(),
247+
new Cartesian3(), new Cartesian3(),
248+
new Cartesian3(), new Cartesian3(),
249+
new Cartesian3(), new Cartesian3(),
250+
new Cartesian3(), new Cartesian3()
251+
];
252+
var sampleScratch = new Cartographic();
253+
var cornerScratch = new Cartographic();
254+
238255
/**
239256
* Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the
240257
* object's minimum and maximum heights over the rectangle.
@@ -259,24 +276,53 @@ define([
259276

260277
projection = defaultValue(projection, defaultProjection);
261278

262-
Rectangle.southwest(rectangle, fromRectangle2DSouthwest);
263-
fromRectangle2DSouthwest.height = minimumHeight;
264-
Rectangle.northeast(rectangle, fromRectangle2DNortheast);
265-
fromRectangle2DNortheast.height = maximumHeight;
279+
if (projection.isEquatorialCylindrical) {
280+
Rectangle.southwest(rectangle, fromRectangle2DSouthwest);
281+
fromRectangle2DSouthwest.height = minimumHeight;
282+
Rectangle.northeast(rectangle, fromRectangle2DNortheast);
283+
fromRectangle2DNortheast.height = maximumHeight;
266284

267-
var lowerLeft = projection.project(fromRectangle2DSouthwest, fromRectangle2DLowerLeft);
268-
var upperRight = projection.project(fromRectangle2DNortheast, fromRectangle2DUpperRight);
285+
var lowerLeft = projection.project(fromRectangle2DSouthwest, fromRectangle2DLowerLeft);
286+
var upperRight = projection.project(fromRectangle2DNortheast, fromRectangle2DUpperRight);
269287

270-
var width = upperRight.x - lowerLeft.x;
271-
var height = upperRight.y - lowerLeft.y;
272-
var elevation = upperRight.z - lowerLeft.z;
288+
var width = upperRight.x - lowerLeft.x;
289+
var height = upperRight.y - lowerLeft.y;
290+
var elevation = upperRight.z - lowerLeft.z;
273291

274-
result.radius = Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;
275-
var center = result.center;
276-
center.x = lowerLeft.x + width * 0.5;
277-
center.y = lowerLeft.y + height * 0.5;
278-
center.z = lowerLeft.z + elevation * 0.5;
279-
return result;
292+
result.radius = Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;
293+
var center = result.center;
294+
center.x = lowerLeft.x + width * 0.5;
295+
center.y = lowerLeft.y + height * 0.5;
296+
center.z = lowerLeft.z + elevation * 0.5;
297+
return result;
298+
}
299+
300+
var southwest = Rectangle.southwest(rectangle, cornerScratch);
301+
var halfWidth = rectangle.width * 0.5;
302+
var halfHeight = rectangle.height * 0.5;
303+
var sample = sampleScratch;
304+
var index = 0;
305+
306+
// Project 18 points, one for each corner, the edge centers, and minimum/maximum height
307+
for (var x = 0; x < 3; x++) {
308+
for (var y = 0; y < 3; y++) {
309+
if (x === 1 && y === 1) {
310+
continue;
311+
}
312+
sample.longitude = southwest.longitude + x * halfWidth;
313+
sample.latitude = southwest.latitude + y * halfHeight;
314+
sample.height = minimumHeight;
315+
316+
projection.project(sample, projectedPointsScratch[index]);
317+
318+
sample.height = maximumHeight;
319+
projection.project(sample, projectedPointsScratch[index + 8]);
320+
321+
index++;
322+
}
323+
}
324+
325+
return BoundingSphere.fromPoints(projectedPointsScratch, result);
280326
};
281327

282328
var fromRectangle3DScratch = [];

0 commit comments

Comments
 (0)