Created
June 8, 2015 17:28
-
-
Save iriberri/ce3a5a491939957f76c9 to your computer and use it in GitHub Desktop.
Set global bounds
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>Bounds 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 { | |
height: 95%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<link rel="stylesheet" | |
href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" | |
href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" /> | |
<![endif]--> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<script> | |
var layer; | |
function main() { | |
var map; | |
var layerUrl = 'https://team.cartodb.com/u/iriberri/api/v2/viz/431ca5d0-02f5-11e5-9e34-0e4fddd5de28/viz.json'; | |
cartodb.createVis('map', layerUrl) | |
.on('done', function(vis, layer) { | |
map = vis.getNativeMap(); | |
setInterval(function(){ | |
var sql = new cartodb.SQL({ user: 'iriberri' }); | |
sql.getBounds("SELECT * FROM world_borders_9").done(function(bounds) { | |
map.fitBounds(bounds) | |
}); | |
}, 3000); | |
}).on('error', function() { | |
cartodb.log.log("some error occurred"); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment