-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.html
More file actions
123 lines (123 loc) · 4.43 KB
/
Copy pathindex.html
File metadata and controls
123 lines (123 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Cesium Editor</title>
<script src="./node_modules/cesium/Build/Cesium/Cesium.js"></script>
<script src="./node_modules/codemirror/lib/codemirror.js"></script>
<script src="./node_modules/codemirror/mode/javascript/javascript.js"></script>
<link rel="stylesheet" href="./node_modules/codemirror/lib/codemirror.css">
<style>
@import url(./node_modules/cesium/Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
height: 100%; margin: 0; padding: 0; overflow: hidden;
}
#edits {
height: 100%; float: left; width: 50%;
}
</style>
</head>
<body>
<div id="edits">
<div id="buttons">
<button id="openFile" onclick="openFile();">Open File</button>
<button id="saveFile" onclick="saveFile();">Save File</button>
<button id="loadData" onclick="loadData();">Load Data</button>
<button id="clearData" onclick="clearData();">Clear Data</button>
<button id="run" onclick="run();">Run</button>
</div>
<textarea id="code" name="code"></textarea>
</div>
<div id="cesiumContainer"></div>
<script type="text/javascript" src="./code.js"></script>
<script>
var fs = require('fs');
var path = require('path');
var remote = require('remote');
var dialog = remote.require('dialog');
var pathToCode = path.join(__dirname, 'code.js');
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById('code'), {
mode : 'javascript',
lineNumbers : true
});
myCodeMirror.setSize(550, 780);
fs.readFile(pathToCode, 'utf-8', function (err, data) {
myCodeMirror.setValue(data);
});
function openFile () {
dialog.showOpenDialog({filters : [{name : 'javascript', extensions : ['js']}]},
function (fileNames) {
if (fileNames === undefined) {
return;
}
var fileName = fileNames[0];
fs.readFile(fileName, 'utf-8', function (err, data) {
myCodeMirror.setValue(data);
});
});
}
function saveFile () {
dialog.showSaveDialog({filters : [{ name : 'javascript', extensions : ['js']}]},
function (fileName) {
if (fileName === undefined) {
return;
}
fs.writeFile(fileName, myCodeMirror.getValue(), function (err) {});
});
}
function loadData() {
dialog.showOpenDialog({filters : [{name : 'data', extensions : ['geojson', 'topojson', 'czml', 'kml', 'kmz', 'gltf']}]},
function (fileNames) {
if (fileNames === undefined) {
return;
}
var tempFileName = fileNames[0];
var fileName;
if (process.platform != 'darwin') {
for (var i = 0; i < tempFileName.length; i++) {
if (tempFileName.charAt(i) === '\\') {
tempFileName = tempFileName.substr(0, i) + '/' + tempFileName.substr(i + 1);
}
}
}
fileName = tempFileName;
var extension = path.extname(fileName);
switch(extension) {
case '.geojson':
viewer.dataSources.add(Cesium.GeoJsonDataSource.load(fileName));
break;
case '.topojson':
viewer.dataSources.add(Cesium.GeoJsonDataSource.load(fileName));
break;
case '.czml':
viewer.dataSources.add(Cesium.CzmlDataSource.load(fileName));
break;
case '.kml':
viewer.dataSources.add(Cesium.KmlDataSource.load(fileName));
break;
case '.kmz':
viewer.dataSources.add(Cesium.KmlDataSource.load(fileName));
break;
case '.gltf':
viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000),
model : {
uri : fileName
}
});
break;
}
});
}
function clearData() {
viewer.dataSources.removeAll();
viewer.entities.removeAll();
}
function run() {
fs.writeFile(pathToCode, myCodeMirror.getValue(), function (err) {});
window.location.reload();
}
</script>
</body>
</html>