Last active
August 29, 2015 14:11
-
-
Save Xatpy/4f8a3d87d37a075cb006 to your computer and use it in GitHub Desktop.
Show image while loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Easy example | CartoDB.js</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
<style> | |
html, body, #map { | |
/*position:absolute;*/ | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
#image { | |
display:block;margin:-50px 0 0 -50px; | |
position:absolute; | |
z-index:10; | |
top:50%; | |
left:50%; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.11/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<!-- Image that was displayed while the map is being loaded --> | |
<img id= "image" src="http://www.itespresso.es/wp-content/uploads/2014/09/cartodb1-300x297.png"></img> | |
<!-- CartoDB map --> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.11/cartodb.js"></script> | |
<script type="text/javascript"> | |
var im = document.getElementById("image"); | |
function showImage(){ | |
im.style.display = 'block' ; | |
}; | |
function hideImage(){ | |
im.style.display = 'none'; | |
}; | |
function main() { | |
var vizjson_url = "http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json"; | |
cartodb.createVis("map", vizjson_url, { share: true, title: true, description: true, search: true }).done(function(vis, layers) { | |
}) | |
.done(function(vis, layer){ | |
console.log('done'); | |
}) | |
.on('load', function(){ | |
console.log('load'); | |
hideImage(); | |
}) | |
.on('loading', function(){ | |
console.log('loading'); | |
showImage(); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment