Created
September 14, 2015 12:09
-
-
Save iriberri/77c5f60ea238e95a98f0 to your computer and use it in GitHub Desktop.
Retrieving data through the interactivity of a private dataset
This file contains hidden or 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>Private data 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: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<script> | |
function main() { | |
var sublayer; | |
cartodb.createVis('map', 'https://team.cartodb.com/u/iriberri/api/v2/viz/8a497570-5ad7-11e5-a679-0e853d047bba/viz.json') | |
.done(function(vis, layers) { | |
sublayer = layers[1].getSubLayer(0); | |
sublayer.on('featureClick', function(e, pos, latlng, data) { | |
console.log(data); | |
//This data comes from a private table in which URL and Name columns are enabled in the HOVER infoiwindow | |
alert("Hey! this is the URL: " + data.url + " for the " + data.name + " point."); | |
}); | |
}) | |
.error(function(err) { | |
console.log(err); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment