Created
September 3, 2015 13:07
-
-
Save iriberri/c337e1e71ea7d389ed97 to your computer and use it in GitHub Desktop.
Creating a single layer with different datasets data
This file contains hidden or 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>Change marker 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/3.15/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<script> | |
function main() { | |
var my_layer; | |
// create leaflet map | |
var map = L.map('map', { | |
zoomControl: false, | |
center: [43, 0], | |
zoom: 3 | |
}) | |
// add a base layer | |
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
attribution: 'Map tiles by Stament. CartoDB attribution.' | |
}).addTo(map); | |
// add cartodb layer with one sublayer | |
cartodb.createLayer(map, { | |
user_name: 'iriberri', | |
type: 'cartodb', | |
sublayers: [{ | |
sql: 'select world_borders_1.*, world_data_marker.popula from world_borders_1, world_data_marker where world_borders_1.name = world_data_marker.country', | |
cartocss: '#world_data_marker{ polygon-fill: #FFFFB2; polygon-opacity: 0.8; line-color: #FFF; line-width: 0.5; line-opacity: 1; } #world_data_marker [ popula <= 400] { polygon-fill: #B10026; } #world_data_marker [ popula <= 400] { polygon-fill: #E31A1C; } #world_data_marker [ popula <= 300] { polygon-fill: #FC4E2A; } #world_data_marker [ popula <= 300] { polygon-fill: #FD8D3C; } #world_data_marker [ popula <= 200] { polygon-fill: #FEB24C; } #world_data_marker [ popula <= 200] { polygon-fill: #FED976; } #world_data_marker [ popula <= 100] { polygon-fill: #FFFFB2; }', | |
interactivity: 'cartodb_id' | |
}] | |
}) | |
.addTo(map) | |
.done(function(layer) { | |
}); | |
} | |
// you could use $(window).load(main); | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment