Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Last active July 19, 2016 15:45
Show Gist options
  • Save ramiroaznar/bb184bbc04c8b1c869d17362073d9de8 to your computer and use it in GitHub Desktop.
Save ramiroaznar/bb184bbc04c8b1c869d17362073d9de8 to your computer and use it in GitHub Desktop.
createLayer + set SQL query with CARTO.js
<!DOCTYPE html>
<html>
<head>
<title>createLayer + set SQL query</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" />
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
<style>
html, body,#map {
width:100%;
height:100%;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id='map'></div>
<script type="text/javascript">
function main() {
var map = new L.Map('map', {
center: [17,-93],
zoom: 8
});
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {
attribution: 'Stamen'
}).addTo(map);
cartodb.createLayer(map, {
user_name: 'ramirocartodb', // Required
type: 'cartodb', // Required
sublayers: [
{
sql: "SELECT cartodb_id, the_geom_webmercator, type FROM municipios_mex where type = 'Region Chiapas'", // Required
cartocss: '#municipios_mex{ polygon-fill: red; polygon-opacity: 0.8; line-color: #FFF; line-width: 1; line-opacity: 0.5; }', // Required
}]
})
.addTo(map);
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment