基本上,我导入了一个 WebGL 地球仪,并希望在单击该地球仪时使其停止旋转。
这是我试图阻止它的尝试:
setInterval(function() {
var c = earth.getPosition();
earth.setCenter([c[0], c[1] + 0.9]);
earth.onclick.setCenter({c[0], c[1]);
}, 50);
基本上我想摆脱+0.9
onClick。如果有帮助,还可以添加以下带有地球对象的函数:
<script src="http://www.webglearth.com/v2/api.js"></script>
<script>
function initialize() {
var options = {atmosphere: true, center: [0, 0], zoom: 0};
var earth = new WE.map('earth_div', options);
WE.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {
subdomains: '1234',
attribution: 'Tiles Courtesy of MapQuest'
}).addTo(earth);
</script>
我猜测 .onclick
的语法不正确。应该是什么?
最佳答案
检查 webglearth 上的示例,onClick
定义为:
earth.on('click', callback)
所以你需要将回调函数定义为:
callback = function(){···}
或者简而言之:
earth.on('click', function(e){···});
如果需要停止动画,则必须在 onClick
事件上使用 clearInterval
var interval = setInterval(function() {
var c = earth.getPosition();
earth.setCenter([c[0], c[1] + 0.9]);
}, 50);
···
earth.on('click', function(){
clearInterval(interval);
});
关于javascript - 如何在 onClick 函数内转换值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25756484/