Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Last active June 6, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramiroaznar/dc75b084c3bf4c52999c82884021b93b to your computer and use it in GitHub Desktop.
Save ramiroaznar/dc75b084c3bf4c52999c82884021b93b to your computer and use it in GitHub Desktop.
Deep-Insights.js with 2 Layers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Deep-Insights.js | 2 Layers </title>
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
<meta name=viewport content="width=device-width initial-scale=1">
<link rel="stylesheet" href="http://libs.cartocdn.com/di.js/v0/themes/css/deep-insights.css" />
<script src=" http://libs.cartocdn.com/di.js/v0/deep-insights.uncompressed.js"></script>
<style type="text/css">
html, body {
position:relative;
height: 100%;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="dashboard"></div>
<script>
window.onload = function() {
// set vizJson
var vizJSON = "https://team.cartodb.com/u/ramirocartodb/api/v3/viz/eb59350c-231e-11e6-8458-0e3ff518bd15/viz.json";
// create dashboard
cartodb.deepInsights.createDashboard('#dashboard', vizJSON, {
no_cdn: false,
cartodb_logo: false
},function(err,dashboard){
// get map object
var map = dashboard.getMap();
// set widget parameters
var sum = {
"type": "formula",
"title": "Total Population",
"column": "pop_max",
"operation": "sum"
};
var avg = {
"type": "formula",
"title": "Average Population",
"column": "pop_max",
"operation": "avg"
};
var histo = {
"type": "histogram",
"title": "Population Histogram",
"column": "pop_max",
"bins": 10
};
var country = {
"type": "category",
"title": "Country Borders Category",
"column": "name"
};
var city = {
"type": "category",
"title": "City Category",
"column": "name"
};
// add widgets to the dashboard
// layer 2 - populated places
dashboard.createFormulaWidget(sum,map.getLayer(2));
dashboard.createFormulaWidget(avg,map.getLayer(2));
dashboard.createHistogramWidget(histo,map.getLayer(2));
dashboard.createCategoryWidget(city,map.getLayer(2));
// layer 1 - world borders
dashboard.createCategoryWidget(country,map.getLayer(1));
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment