54 lines
1.7 KiB
HTML
54 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Adding Cursor interaction to your map example | CartoDB.js</title>
|
|
<!--
|
|
This example shows you how to add cursor interaction to your map using CartoDB.js
|
|
-->
|
|
<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;
|
|
background-color: #E5F5F7;
|
|
}
|
|
</style>
|
|
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
|
|
</head>
|
|
<body>
|
|
<div id="map"></div>
|
|
|
|
<!-- include cartodb.js library -->
|
|
<script src="https://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.uncompressed.js"></script>
|
|
|
|
<script>
|
|
|
|
function main() {
|
|
var map = new L.Map('map', {
|
|
zoomControl: false,
|
|
center: [43, -30],
|
|
zoom: 3
|
|
});
|
|
|
|
cartodb.createLayer(map, 'http://examples.cartodb.com/api/v2/viz/255729a6-e28c-11e3-bcb7-0e10bcd91c2b/viz.json')
|
|
.addTo(map)
|
|
.on('done', function(layer) {
|
|
var subLayer = layer.getSubLayer(0);
|
|
subLayer.setInteraction(true); // Interaction for that layer must be enabled
|
|
cdb.vis.Vis.addCursorInteraction(map, subLayer); // undo with removeCursorInteraction
|
|
layer.on('featureOver', featureOver);
|
|
})
|
|
|
|
function featureOver(e, latlng, pos, data) {
|
|
console.log(data.cartodb_id)
|
|
}
|
|
}
|
|
window.onload = main;
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|