earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
65 lines (64 loc) • 2.33 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>
#three-js {
pointer-events: all;
}
</style>
</head>
<body>
<svg id="earth-js"></svg>
<canvas id="three-js"></canvas>
<script>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5, transparent: true})
.register(earthjs.plugins.threejsPlugin())
.register(earthjs.plugins.inertiaPlugin())
.register(earthjs.plugins.autorotatePlugin())
.register(earthjs.plugins.graticuleThreejs())
.register(earthjs.plugins.canvasThreejs('../d/world-110m.json'))
.register(earthjs.plugins.dotsThreejs('../data/geonames_cities100k.csv'));
g.inertiaPlugin.selectAll('#three-js');
g.dotsThreejs.ready = function(err, csv) {
const features = csv.map(d => {
return {
type: 'Feature',
properties: {
name: d.name,
population: d.population
},
geometry: {
type: 'Point',
coordinates: [d.longitude, d.latitude]}
}
});
const geometry = {radius: 2}
g.dotsThreejs.data({geometry, features});
};
let hovering = null;
g.dotsThreejs.onHover({
dotHoverIn(event) {
hovering = event;
console.log('hovering in:', event.target.__data__.properties);
}
})
g.canvasThreejs.onHover({
dotHoverOut(event) {
if (hovering) {
hovering = null
console.log('hovering out...');
}
}
})
g.ready(function(){
g.create();
})
</script>
</body>
</html>