Skip to content

Instantly share code, notes, and snippets.

@iriberri
Created September 14, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iriberri/77c5f60ea238e95a98f0 to your computer and use it in GitHub Desktop.
Save iriberri/77c5f60ea238e95a98f0 to your computer and use it in GitHub Desktop.
Retrieving data through the interactivity of a private dataset
<!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