Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created November 20, 2013 07:53
Show Gist options
  • Save javisantana/7559345 to your computer and use it in GitHub Desktop.
Save javisantana/7559345 to your computer and use it in GitHub Desktop.
<!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 {
height: 100%;
padding: 0;
margin: 0;
}
</style>
<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="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.uncompressed.js"></script>
<script>
function addCursorInteraction (viz, layer) {
var hovers = [];
var mapView = viz.mapView;
layer.bind('featureOver', function(e, latlon, pxPos, data, layer) {
hovers[layer] = 1;
if(_.any(hovers))
mapView.setCursor('pointer');
}, mapView);
layer.bind('featureOut', function(m, layer) {
hovers[layer] = 0;
if(!_.any(hovers))
mapView.setCursor('auto');
}, mapView);
}
function main() {
var vizjson_url= 'http://lischoir.cartodb.com/api/v2/viz/34cd557a-379e-11e3-817b-2d14fbc2df5a/viz.json';
cartodb.createVis('map', vizjson_url, {
cartodb_logo: false,
legends: false,
scrollwheel: false, // Doesn't allow the zoom with scroll wheel
zoom: 2,
zoomControl: true
})
.done(function(vis, layers) {
// layer 0 is the base layer, layer 1 is cartodb layer
// setInteraction is disabled by default: enabling it will enable
// interactions with the members circles
var sublayer = layers[1].getSubLayer(0);
sublayer.setInteraction(true);
// The CartoDB data passed to the features
sublayer.set({ 'interactivity': ['name', 'location', 'thumb'] });
// you can get the native map to work with it
// depending if you use google maps or leaflet
addCursorInteraction(vis, sublayer);
/*var infobox = vis.addOverlay({
type: 'infobox',
template: map,
});*/
})
.error(function(err) {
console.error(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