earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
32 lines (31 loc) • 1.25 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/topojson.min.js"></script>
<script type='text/javascript' src='../js/earthjs.js'></script>
</head>
<body>
<svg id="earth-js"></svg>
<script>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5, transparent: true})
.register(earthjs.plugins.inertiaPlugin())
.register(earthjs.plugins.graticuleSvg())
.register(earthjs.plugins.barSvg('../data/bars.json'))
.register(earthjs.plugins.barTooltipSvg());
g.barSvg.ready = function(err, json) {
json.features.forEach(d => d.geometry.value = d.properties.mag);
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>