Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
social infowindow in cartodb
<!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;
}
.bravos { position: relative;
width: 350px;
background-color: white;
}
.cartodb-popup-close-button {
position: absolute;
top: -3px;
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="bravos" id="tweet">
<a href="#close" class="cartodb-popup-close-button close">x</a>
<div class="cartodb-popup-content">
<%= insert_tw(content) %>
</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>
// helper to include tweet html
function insert_tw(content) {
return "<div id='tweet_embed'></div><script>twttr.widgets.createTweet('" + content.data.twitter_id + "', document.getElementById('tweet_embed'))</sc" + "ript>";
}
function main() {
cartodb.createVis('map', 'http://osm2.cartodb.com/api/v2/viz/wimbledon/viz.json', { description: true, search: true, shareable: true})
.on('done', function(vis,layers) {
var layer = layers[1];
var infowindow = layer.getSubLayer(0).infowindow;
infowindow.set('template_type', 'underscore');
infowindow.set('template', $('#infowindow_template').html());
})
}
window.onload = main;
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment