Wait globe to load world.jpg before display it

This commit is contained in:
HelloZeroNet 2016-03-18 19:20:49 +01:00
parent 5af32f21fd
commit a3bba8c14c
2 changed files with 47 additions and 39 deletions

View file

@ -351,22 +351,25 @@ class Sidebar extends Class
displayGlobe: => displayGlobe: =>
wrapper.ws.cmd "sidebarGetPeers", [], (globe_data) => img = new Image();
if @globe img.src = "/uimedia/globe/world.jpg";
@globe.scene.remove(@globe.points) img.onload = =>
@globe.addData( globe_data, {format: 'magnitude', name: "hello", animated: false} ) wrapper.ws.cmd "sidebarGetPeers", [], (globe_data) =>
@globe.createPoints() if @globe
else @globe.scene.remove(@globe.points)
try @globe.addData( globe_data, {format: 'magnitude', name: "hello", animated: false} )
@globe = new DAT.Globe( @tag.find(".globe")[0], {"imgDir": "/uimedia/globe/"} )
@globe.addData( globe_data, {format: 'magnitude', name: "hello"} )
@globe.createPoints() @globe.createPoints()
@globe.animate() else
catch e try
console.log "WebGL error", e @globe = new DAT.Globe( @tag.find(".globe")[0], {"imgDir": "/uimedia/globe/"} )
@tag.find(".globe").addClass("error").text("WebGL not supported") @globe.addData( globe_data, {format: 'magnitude', name: "hello"} )
@globe.createPoints()
@globe.animate()
catch e
console.log "WebGL error", e
@tag.find(".globe").addClass("error").text("WebGL not supported")
@tag.find(".globe").removeClass("loading") @tag.find(".globe").removeClass("loading")
unloadGlobe: => unloadGlobe: =>

View file

@ -601,37 +601,42 @@ window.initScrollable = function () {
}; };
Sidebar.prototype.displayGlobe = function() { Sidebar.prototype.displayGlobe = function() {
return wrapper.ws.cmd("sidebarGetPeers", [], (function(_this) { var img;
return function(globe_data) { img = new Image();
var e; img.src = "/uimedia/globe/world.jpg";
if (_this.globe) { return img.onload = (function(_this) {
_this.globe.scene.remove(_this.globe.points); return function() {
_this.globe.addData(globe_data, { return wrapper.ws.cmd("sidebarGetPeers", [], function(globe_data) {
format: 'magnitude', var e;
name: "hello", if (_this.globe) {
animated: false _this.globe.scene.remove(_this.globe.points);
});
_this.globe.createPoints();
} else {
try {
_this.globe = new DAT.Globe(_this.tag.find(".globe")[0], {
"imgDir": "/uimedia/globe/"
});
_this.globe.addData(globe_data, { _this.globe.addData(globe_data, {
format: 'magnitude', format: 'magnitude',
name: "hello" name: "hello",
animated: false
}); });
_this.globe.createPoints(); _this.globe.createPoints();
_this.globe.animate(); } else {
} catch (_error) { try {
e = _error; _this.globe = new DAT.Globe(_this.tag.find(".globe")[0], {
console.log("WebGL error", e); "imgDir": "/uimedia/globe/"
_this.tag.find(".globe").addClass("error").text("WebGL not supported"); });
_this.globe.addData(globe_data, {
format: 'magnitude',
name: "hello"
});
_this.globe.createPoints();
_this.globe.animate();
} catch (_error) {
e = _error;
console.log("WebGL error", e);
_this.tag.find(".globe").addClass("error").text("WebGL not supported");
}
} }
} return _this.tag.find(".globe").removeClass("loading");
return _this.tag.find(".globe").removeClass("loading"); });
}; };
})(this)); })(this);
}; };
Sidebar.prototype.unloadGlobe = function() { Sidebar.prototype.unloadGlobe = function() {