Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created September 25, 2013 07:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save javisantana/6696187 to your computer and use it in GitHub Desktop.
Save javisantana/6696187 to your computer and use it in GitHub Desktop.
infowindow with custom size
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
.infowindow-custom{ 
position: relative;
width: 350px;
background-color: white;
margin-bottom: 11px;
}
.cartodb-popup-close-button {
position: absolute;
top: -12px;
right: -11px;
width: 26px;
height: 26px;
background: url('http://libs.cartodb.com/cartodb.js/v3/themes/img/light.png') no-repeat 0 -23px;
text-indent: -9999px;
font-size: 0;
line-height: 0;
opacity: 1;
text-transform: uppercase;
z-index: 3;
}
.cartodb-popup-tip-container {
position: absolute;
bottom: -3px;
left: 23px;
width: 16px;
height: 14px;
background: url('http://libs.cartodb.com/cartodb.js/v3/themes/img/light.png') no-repeat -23px -7px;
text-indent: -9999px;
font-size: 0;
line-height: 0;
opacity: 1;
z-index: 3;
}
blockquote {
display: hidden;
}
.cartodb-popup-content {
min-height: 80px;
}
</style>
<link rel="stylesheet" href="http://libs.cartodb.com/cartodb.js/v3/themes/css/cartodb.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://libs.cartodb.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
<![endif]-->
</head>
<body>
<div id="map"></div>
</body>
<script type="infowindow/html" id="infowindow_template">
<div class="infowindow-custom" >
<a href="#close" class="cartodb-popup-close-button close">x</a>
<div class="cartodb-popup-content">
<div class="content" style="padding:20px">
{{content.data.name}}
</div>
</div>
<div class="cartodb-popup-tip-container"></div>
</div>
</script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.0.05-dev/cartodb.js"></script>
<script async src="http://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script>
function main() {
var map = L.map('map', {
zoomControl: false,
center: [0, 0],
zoom: 3
});
// add a nice baselayer from Stamen
L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', {
attribution: 'Stamen'
}).addTo(map);
cartodb.createLayer(map, 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json')
.addTo(map)
.on('done', function(layer) {
// get sublayer 0 and set the infowindow template
var sublayer = layer.getSubLayer(0);
sublayer.infowindow.set('template', $('#infowindow_template').html());
}).on('error', function() {
console.log("some error occurred");
});
}
window.onload = main;
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment