Skip to content

Instantly share code, notes, and snippets.

@michellechandra
Last active December 17, 2015 16:35
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 michellechandra/96d9a6ab39dcb0f4172a to your computer and use it in GitHub Desktop.
Save michellechandra/96d9a6ab39dcb0f4172a to your computer and use it in GitHub Desktop.
CreateVis Map with YouTube Infowindow Embed
<!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"/>
<link rel="stylesheet" href="http://libs.cartodb.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
div.cartodb-popup.v2 {
width: 250px;
}
.infowindow-custom{
position: relative;
width: 250px;
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-content-wrapper {
width: 250px;
}
.cartodb-popup-content {
width: 250px;
}
.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 {
width: 250px;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
<script type="infowindow/html" id="infowindow_template">
<div class="cartodb-popup v2">
<div class="infowindow-custom">
<a href="#close" class="cartodb-popup-close-button close">x</a>
<div class="cartodb-popup-content-wrapper">
<div class="cartodb-popup-content">
<!-- content.data contains the field info -->
<h4>San Francisco</h4>
<p><iframe width="240" src="{{content.data.youtube_url}}" frameborder="0" allowfullscreen></iframe></p>
</div>
</div>
</div>
<div class="cartodb-popup-tip-container"></div>
</div>
</script>
<script src="http://libs.cartodb.com/cartodb.js/v3/3.15/cartodb.js"></script>
<script async src="http://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script>
function main() {
cartodb.createVis('map', 'https://team.cartodb.com/u/chandra/api/v2/viz/fd5891d6-7db4-11e5-84fe-0e31c9be1b51/viz.json', { description: true, search: true, shareable: true })
.on('done', function(vis,layers) {
var layer = layers[1].getSubLayer(0);
layer.infowindow.set('template', $('#infowindow_template').html());
layer.infowindow.set('sanitizeTemplate', 'false');
layer.on('error', function(err) {
console.log('error: ' + err);
});
}).on('error', function() {
console.log("some error has occurred");
});
}
window.onload = main;
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment