Created
July 2, 2014 15:31
-
-
Save xavijam/378c6dc0d43654280757 to your computer and use it in GitHub Desktop.
Applying LEFT JOIN and showind data in the infowindow (createVis)
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.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<script type="text/javascript"> | |
var layer; | |
function main() { | |
cartodb.createVis(map, 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json') | |
.on('done', function(vis, layers) { | |
var lyr = layers[1].getSubLayer(0); | |
lyr.setSQL("SELECT e.cartodb_id, e.area, w.subregion, w.un, e.the_geom, e.the_geom_webmercator FROM european_countries_e e LEFT JOIN world_borders w ON e.iso_2_code = w.iso2"); | |
lyr.infowindow.set( | |
"fields", | |
[ | |
{ name: 'area', position: 0, title: true }, | |
{ name: 'un', position: 0, title: true }, | |
{ name: 'subregion', position: 0, title: true } | |
]); | |
}).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