Last active
June 22, 2016 08:10
-
-
Save xavijam/7283a403afb6a54eda9a to your computer and use it in GitHub Desktop.
Close infowindow programatically
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>Close infowindow programatically | 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; | |
} | |
/* css */ | |
.list { | |
position: absolute; | |
background: white; | |
top: 180px; | |
left: 20px; | |
padding: 20px; | |
z-index: 10; | |
} | |
/* end */ | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<!-- html --> | |
<div id="map"></div> | |
<div class="list"> | |
<a href="#" class="link">Close infowindow</a> | |
</div> | |
<!-- end --> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.uncompressed.js"></script> | |
<script> | |
// js | |
function main() { | |
cartodb.createVis('map', 'http://documentation.cartodb.com/api/v2/viz/7eb2096a-51d9-11e3-89a7-5404a6a683d5/viz.json', { | |
shareable: false, | |
title: false, | |
description: false, | |
search: false, | |
tiles_loader: true, | |
center_lat: 42, | |
center_lon: -3, | |
zoom: 6, | |
legends: false | |
}) | |
.done(function(vis, layers) { | |
// layer 0 is the base layer, layer 1 is cartodb layer | |
var layer = layers[1]; | |
var infowindow = layer.infowindow; | |
$('.link').click(function() { | |
infowindow.set('visibility', false); | |
return false; | |
}); | |
}) | |
.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