earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
95 lines (93 loc) • 3.74 kB
HTML
<html>
<head>
<link type="text/css" rel="stylesheet" href="../css/earthjs.css">
<script type='text/javascript' src="../js/d3.min.js"></script>
<script type='text/javascript' src='../js/three.min.js'></script>
<script type='text/javascript' src='../js/threex.domevents.js'></script>
<script type='text/javascript' src="../js/topojson.min.js"></script>
<script type='text/javascript' src='../js/earthjs.js'></script>
<style>
body {
background: #393c54;
background-image: url("../images/tiles.png");
}
#three-js {
pointer-events: all;
}
</style>
</head>
<body>
<div class="input-area">
<button id="auto-rotate">Auto Rotate</button>
[<button id="line">Line</button>
<button id="light">Light</button>]
<button id="light-flow">Light Flow</button>
<button id="color-chg">Change color</button>
</div>
<svg id="earth-js" class="ej-center"></svg>
<canvas id="three-js" class="ej-center"></canvas>
<script type='text/javascript'>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5})
.register(earthjs.plugins.inertiaPlugin())
.register(earthjs.plugins.clickCanvas())
.register(earthjs.plugins.threejsPlugin())
.register(earthjs.plugins.autorotatePlugin())
.register(earthjs.plugins.dropShadowSvg())
.register(earthjs.plugins.globeThreejs('../globe/world_1.jpg'))
.register(earthjs.plugins.worldThreejs('../d/world-110m.json'))
.register(earthjs.plugins.flightLineThreejs('../data/flights2.json','../globe/point3.png'))
g.inertiaPlugin.selectAll('#three-js');
g.worldThreejs.ready = function(err, csv) {
g.worldThreejs.data(csv);
g.clickCanvas.data(csv);
}
g.flightLineThreejs.ready = function(err, csv) {
g.flightLineThreejs.data(csv, true, [30,100],100,1);
}
g.flightLineThreejs.onHover({
checkLine(event) {
console.log('checkLine')
}
})
var flightLine;
g.ready(function(){
g.create();
g.flightLineThreejs.lightFlow(false);
flightLine = g.flightLineThreejs.sphere().children;
flightLine[0].visible = false;
flightLine[1].visible = false;
})
d3.select('#auto-rotate').on('click', function() {
var toggle = g.autorotatePlugin.spin();
g.autorotatePlugin.spin(!toggle);
})
d3.select('#light-flow').on('click', function() {
var toggle = g.flightLineThreejs.lightFlow();
g.flightLineThreejs.lightFlow(!toggle);
})
d3.select('#line').on('click', function() {
flightLine[0].visible = !flightLine[0].visible;
g.threejsPlugin.renderThree();
})
d3.select('#light').on('click', function() {
flightLine[1].visible = !flightLine[1].visible;
g.flightLineThreejs.lightFlow(flightLine[1].visible);
g.threejsPlugin.renderThree();
})
var colorChg = false;
d3.select('#color-chg').on('click', function() {
var data = g.flightLineThreejs.data();
colorChg = !colorChg;
if (colorChg) {
g.flightLineThreejs.data(data, ['#aaffff','#ff0011'], [30,100],100,1);
} else {
g.flightLineThreejs.data(data, true, [30,100],100,1);
}
g.flightLineThreejs.reload();
flightLine = g.flightLineThreejs.sphere().children;
})
</script>
</body>
</html>