Created
December 1, 2014 01:43
-
-
Save wboykinm/be609c9cefd9d1dff497 to your computer and use it in GitHub Desktop.
infowindow test
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>Custom infowindow 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; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartodb.com/cartodb.js/v3/3.11/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script type="infowindow/html" id="infowindow_template"> | |
<span> custom </span> | |
<div class="cartodb-popup"> | |
<a href="#close" class="cartodb-popup-close-button close">x</a> | |
<div class="cartodb-popup-content-wrapper"> | |
<div class="cartodb-popup-content"> | |
<img style="width: 100%" src="http://rambo.webcindario.com/images/18447755.jpg"> | |
<!-- content.data contains the field info --> | |
<h4>{{content.data.name}}</h4> | |
</div> | |
</div> | |
<div class="cartodb-popup-tip-container"></div> | |
</div> | |
</script> | |
<script src="http://libs.cartodb.com/cartodb.js/v3/3.11/cartodb.js"></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> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment