Created
May 21, 2015 16:47
-
-
Save xavijam/3c86b6a84bc5c4523704 to your computer and use it in GitHub Desktop.
Add tooltip to a visualization
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>Create tooltip · 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: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
/* end */ | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.14/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.14/cartodb.js"></script> | |
<script> | |
// js | |
function main() { | |
var url = 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json'; | |
cartodb.createVis('map', url, { | |
search: true, | |
tiles_loader: true, | |
layer_selector: true, | |
https: true | |
}) | |
.done(function(vis, layers) { | |
var lyr = layers[1].getSubLayer(0); | |
var tooltip = vis.addOverlay({ | |
layer: lyr, | |
type: 'tooltip', | |
template: '<p>{{cartodb_id}}</p>' // mustache template | |
}); | |
}) | |
.error(function(err) { | |
console.log(err); | |
}); | |
} | |
window.onload = main; | |
// end | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment