earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
53 lines (51 loc) • 2.01 kB
HTML
<html>
<head>
<style media="screen">
.input-area {
position: absolute;
z-index: 5;
}
</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/three.min.js'></script>
<script type='text/javascript' src="../js/topojson.min.js"></script>
<script type='text/javascript' src='../js/earthjs.js'></script>
</head>
<body>
<svg id="earth-js"></svg>
<canvas id="three-js"></canvas>
<svg class="ej-svg" width="100%" height="100%"></svg>
<script>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5})
.register(earthjs.plugins.inertiaPlugin())
.register(earthjs.plugins.threejsPlugin())
.register(earthjs.plugins.worldThreejs('../d/world-110m.json')) //../globe/world.png
.register(earthjs.plugins.imageThreejs('../globe/graticule.svg'))
.register(earthjs.plugins.dotsThreejs('../data/bars.json'))
.register(earthjs.plugins.oceanSvg())
.register(earthjs.plugins.barSvg())
.register(earthjs.plugins.barTooltipSvg());
g.inertiaPlugin.selectAll('.ej-svg');
g.barSvg.selectAll('.ej-svg');
g.dotsThreejs.ready = function(err, json) {
json.features.forEach(function(d) {
d.geometry.value = d.properties.mag;
});
json.geometry = {radius: 2}
g.dotsThreejs.data(json);
g.barSvg.data(json);
};
g.barTooltipSvg.show = function(data, tooltip) {
const props = data.properties;
const title = Object.keys(props).map(k => k+': '+props[k]).join('<br/>');
return tooltip.html('<h3>Bar:</h3>'+title);
};
g.ready(function(){
g.create();
})
</script>
</body>
</html>