Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Last active July 19, 2016 07:32
Show Gist options
  • Save ramiroaznar/38fd39f35a55e8d99c25f9742e2a2d0a to your computer and use it in GitHub Desktop.
Save ramiroaznar/38fd39f35a55e8d99c25f9742e2a2d0a to your computer and use it in GitHub Desktop.
createVis + setSQL with CARTO.js
<!DOCTYPE html>
<html>
<head>
<title> createVis + setSQL | Carto.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>
var dataLayer;
function main() {
// Change your viz.json below
cartodb.createVis('map', 'https://edufierro.carto.com/api/v2/viz/9b41aee6-280b-11e5-9412-0e0c41326911/viz.json')
.done(function(vis, layers) {
//getting the data layer
dataLayer = layers[1].getSubLayer(0);
//Apply a query into that layer
dataLayer.setSQL("select * from municipios_kellogg where type ilike 'Region Chiapas'")
//Apply a CartoCSS for that layer
dataLayer.setCartoCSS("#municipios_kellogg{ polygon-fill: #000; polygon-opacity: 0.8; line-color: #FFF; line-width: 1; line-opacity: 0.5; } ");
})
.error(function(err) {
console.log(err);
});
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment