earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
78 lines (75 loc) • 2.61 kB
HTML
<html>
<head>
<style media="screen">
.input-area {
position: absolute;
z-index: 5;
}
</style>
<style id="js-controlled">
</style>
<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/topojson.min.js"></script>
<script type='text/javascript' src='../js/earthjs.js'></script>
<style>
#earth-js, #earth-js2 {
position: absolute;
top: 0px;
left: 0px;
}
#earth-js2 {
z-index: 4;
}
</style>
</head>
<body>
<div class="input-area">
<input id="pan" type="range" min="0" max="400" step="1" value="0"/>
</div>
<svg id="earth-js"></svg>
<canvas class="ej-canvas"></canvas>
<svg class="ej-svg" width="100%" height="100%"></svg>
<script>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth/3, height: offsetHeight, padding:5, transparent: true})
.register(earthjs.plugins.inertiaPlugin())
.register(earthjs.plugins.autorotatePlugin())
.register(earthjs.plugins.canvasPlugin())
.register(earthjs.plugins.dropShadowSvg())
.register(earthjs.plugins.oceanSvg())
.register(earthjs.plugins.fauxGlobeSvg())
.register(earthjs.plugins.barSvg('../data/bars.json'))
.register(earthjs.plugins.graticuleCanvas())
.register(earthjs.plugins.worldCanvas('../d/world-110m.json'));
g._.options.showCountries = false;
g._.options.showLakes = false;
g.inertiaPlugin.selectAll('.ej-svg');
g.canvasPlugin.selectAll('.ej-canvas');
g.fauxGlobeSvg.selectAll('.ej-svg');
g.barSvg.selectAll('.ej-svg');
g.worldCanvas.style({land: 'green'});
// g.register(earthjs.plugins.placesSvg('../d/places.json'));
g.barSvg.ready = function(err, json) {
json.features.forEach(d => d.geometry.value = d.properties.mag);
g.barSvg.data(json);
};
// g.placesSvg.selectAll('#earth-js2');
g.ready(function(){
g.create();
});
const st = d3.select('#js-controlled');
d3.select('#pan').attr('max',offsetWidth/3-5).on('input', function() {
st.text(`
canvas.ej-canvas {
/*top: ${this.value}px;*/
left: ${this.value}px;
}
svg.ej-svg {
/*top: ${this.value*2}px;*/
left: ${this.value*2}px;
}` );
})
</script>
</body>
</html>