Created
November 30, 2017 14:30
-
-
Save Pabloska/b7a9f6a052d8d7b91c6595cc38086113 to your computer and use it in GitHub Desktop.
clusters_rohingya
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> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<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" /> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<!--BOOTSTRAP SET--> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
font-family: "Lato",sans-serif; | |
} | |
ul.share-buttons{ | |
list-style: none; | |
padding: 0; | |
} | |
.cartodb-legend { | |
width: 220px; | |
height: auto; | |
position: absolute; | |
bottom: 20px !important; | |
background-color:rgba(0, 0, 0, 0.5); | |
right: 20px; | |
} | |
@media screen and (max-width: 501px) { | |
.cartodb-legend { display: none; } /* hide it elsewhere */} | |
<!-- Attribution--> | |
.leaflet-container .leaflet-control-attribution{ | |
color: red; -> change color of text | |
background-color: transparent; | |
} | |
.leaflet-container .leaflet-control-attribution a{ | |
color: grey; -> change the color of the hyperlinks | |
opacity:0; | |
} | |
div.cartodb-timeslider{ display: none!important; } | |
<!-- DROPDOWN MENU--> | |
.btn-group-vertical>.btn, .btn-group>.btn{ | |
padding: 0px; | |
min-width: 170px; | |
} | |
.dropdown-menu{ | |
padding: 0px; | |
margin:0px; | |
max-width: 170px; | |
font-size:13px; | |
} | |
.row { | |
// min-width: 200px; | |
text-align:center; | |
margin-top:20px | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!--FILTERs--> | |
<div style="position:absolute;top: 50px;right: 50%;left: 50%;z-index: 900;margin-left:-85px"> | |
<!--genders--> | |
<div class="btn-group"> | |
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> | |
<span class="selection">Population </span><span class="caret"></span> | |
</button> | |
<ul class="dropdown-menu" role="menu"> | |
<li><a href="#a" id="a" class="button">< 250000</a></li> | |
<li><a href="#b" id="b" class="button">> 250000</a></li> | |
<li><a href="#c" id="c" class="button">< 5000 </a></li> | |
</ul> | |
</div> | |
</div> | |
<script> | |
function main(){ | |
vizJson='https://migrantreport.carto.com/api/v2/viz/7b6b3058-a693-40c9-82dd-4cace7e3cf52/viz.json' | |
cartodb.createVis('map', vizJson, {zoom:10}) | |
.on('done', function(vis,layers) { | |
// get layer | |
let subLayer = layers[1].getSubLayer(0), | |
// get SQL cluster query | |
query = subLayer._parent.layers[0].options.sql; | |
console.log(query); | |
console.log(subLayer); | |
// add button action | |
$('#a').on('click', function() { | |
subLayer.setSQL(query.replace('SELECT * FROM rohingya_entry_points_1', 'SELECT * FROM rohingya_entry_points_1 where crossing_cost < "250000"')); | |
}); | |
$('#b').on('click', function() { | |
subLayer.setSQL(query.replace('SELECT * FROM rohingya_entry_points_1', 'SELECT * FROM rohingya_entry_points_1 where crossing_cost > "25000"')); | |
}); | |
$('#c').on('click', function() { | |
subLayer.setSQL(query.replace('SELECT * FROM rohingya_entry_points_1', 'SELECT * FROM rohingya_entry_points_1 where crossing_cost < "50000"')); | |
}); | |
}).on('error', function() { | |
console.log("some error occurred"); | |
}); | |
} | |
// 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