Skip to content

Instantly share code, notes, and snippets.

@juanignaciosl
Forked from javisantana/index.html
Last active August 29, 2015 14:13
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 juanignaciosl/368db08219ba7f8a4955 to your computer and use it in GitHub Desktop.
Save juanignaciosl/368db08219ba7f8a4955 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;
}
.list {
position: absolute;
background: white;
top: 180px;
left: 20px;
padding: 20px;
z-index: 10;
}
</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>
<div class="list">
<a href="#" class="link">open infowindow</a>
</div>
<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.uncompressed.js"></script>
<script>
function openInfowindow(layer, latlng, cartodb_id) {
layer.trigger('featureClick', null, latlng, null, { cartodb_id: cartodb_id }, 0);
}
function main() {
cartodb.createVis('map', 'http://team.cartodb.com/api/v2/viz/007e475c-967f-11e4-9d8c-0e4fddd5de28/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];
layer.getSubLayer(0).setSQL("SELECT * FROM untitled_table_10 where cartodb_id = 2");
$('.link').click(function() {
openInfowindow(layer, [40.4000262645, -3.683351686], 5324)
return false;
});
})
.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