发布于 2016-08-03 21:38:06
不幸的是,这有点晚了,但我希望它能帮助那些正在寻找这样的东西的人。你不会找到一个独立的解决方案(或者你必须编写自己的javascript实现来处理创建球体所需的所有数学运算),但你可以使用D3.js库和.geo (几何)扩展(默认情况下随D3.js一起提供),一个很好的例子是这样的:
var width = 500, height = width,
projection, path,
svg, features, graticule;
projection = d3.geo.orthographic()
.translate([width / 2, height / 2])
.scale(250)
.clipAngle(90)
.precision(0.1)
.rotate([0, -30]);
path = d3.geo.path()
.projection(projection);
svg = d3.select('.globe')
.append('svg')
.attr('width', width)
.attr('height', height)
.attr('viewBox', '0, 0, ' + width + ', ' + height);
features = svg.append('g');
features.append('path')
.datum({type: 'Sphere'})
.attr('class', 'background')
.attr('d', path);
graticule = d3.geo.graticule();
features.append('path')
.datum(graticule)
.attr('class', 'graticule')
.attr('d', path);svg {
width: 100%
}
path {
fill: none;
stroke: black
}
.background {
fill: rgba(200,212,220,.5);
stroke-width: .8px;
stroke: black;
}
.graticule {
stroke: rgba(0,0,0, .2);
stroke-width: .5px;
}
.country {
cursor: pointer;
}
.country .land, .state .land {
fill: white;
stroke: rgba(0,0,0, .2);
stroke-width .3px;
}
.state .overlay {
fill: blue;
fill-opacity: 0;
}
.country .overlay {
fill: orange;
fill-opacity: 0;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
<div class="globe"></div>
我猜在下面的教程中,你会发现这个例子的版本2是你工作的最佳选择:
http://jsfiddle.net/GordyD/uwp5vu87/2/
https://stackoverflow.com/questions/33444603
复制相似问题