我正在尝试将WebGL地球与d3.geo.satellite投影相结合。
我已经设法将两个投影叠加在一起,并同步旋转,但我在同步缩放时遇到了麻烦。当我同步它们以匹配大小时,WebGL投影变形,但d3.geo.satellite保持不变。我尝试了projection.scale,projection.distance的不同组合,但没有太多成功。
下面是JS fiddle (加载资源需要一些时间)。您可以拖动它以进行旋转(效果很好)。但是如果你放大(使用鼠标滚轮),你可以看到问题所在。
https://jsfiddle.net/nxtwrld/7x7dLj4n/2/
重要的代码在脚本的底部- scale函数。
function scale(){
var scale = d3.event.scale;
var ratio = scale/scale0;
// scale projection
projection.scale(scale);
// scale Three.js earth
earth.scale.x = earth.scale.y = earth.scale.z = ratio;
}发布于 2017-09-23 17:26:22
我也没有使用WebGL地球,检查你的jsfiddle不再起作用了,我假设你的问题是你想要集成D3.js和Threejs作为3d globe的解决方案。
我建议您尝试使用earthjs作为您的解决方案。在引擎盖下它使用的是D3.js v4和Threejs revision 8x都是最新的,并且它可以在Svg,canvas和threejs(WebGL)之间进行组合。
const g = earthjs({padding:60})
.register(earthjs.plugins.mousePlugin())
.register(earthjs.plugins.threejsPlugin())
.register(earthjs.plugins.autorotatePlugin())
.register(earthjs.plugins.dropShadowSvg(),'dropshadow')
.register(earthjs.plugins.worldSvg('../d/world-110m.json'))
.register(earthjs.plugins.globeThreejs('../globe/world.jpg'))
g._.options.showLakes = false;
g.ready(function(){
g.create();
})上面的代码片段你可以从here运行它。
https://stackoverflow.com/questions/39434107
复制相似问题