Land-use map using CartoDB
Last active
August 30, 2016 02:25
-
-
Save bshiro/0d6400ba37a99b491f64 to your computer and use it in GitHub Desktop.
Land-use Map (CartoDB)
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> | |
<title>CartoDB Test</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
#selector_menu{ | |
position: absolute; | |
top: 20px; | |
left: 20px; | |
z-index: 9000; | |
} | |
#properties{ | |
[type='Public Sector']{ | |
polygon-fill: #3E7BB6; | |
polygon-opacity: 0.7; | |
line-color: #FFF; | |
line-width: 0.5; | |
line-opacity: 1; | |
} | |
[type='Private Sector']{ | |
polygon-fill: #FF6600; | |
polygon-opacity: 0.7; | |
line-color: #FFF; | |
line-width: 0.5; | |
line-opacity: 1; | |
} | |
} | |
</style> | |
<script src="https://code.jquery.com/jquery-1.9.1.min.js" integrity="sha256-wS9gmOZBqsqWxgIVgA8Y9WcQOa7PgSIX+rPA0VL2rbQ=" crossorigin="anonymous"></script> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css"> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script> | |
<!-- include cartodb css --> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
</head> | |
<body> | |
<div id='map'></div> | |
<div id='selector_menu'> | |
<select id='selector' class='selectpicker'> | |
<option value='layer0'>All</option> | |
<option value='layer1'>Public</option> | |
<option value = 'layer2'>Private</option> | |
</select> | |
</div> | |
<script> | |
function init(){ | |
var sublayer; | |
// create leaflet map and define some properties | |
var map = L.map('map', { | |
zoomControl: false, | |
center: [42.35,-88], | |
zoom: 10 | |
}) | |
// add a base layer to map | |
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
attribution: 'Stamen' | |
}).addTo(map); | |
var layerUrl = 'https://bshiro.cartodb.com/api/v2/viz/8d707b18-ec18-11e5-b99c-0e98b61680bf/viz.json' ; | |
//console.log(layerUrl); | |
cartodb.createLayer(map,layerUrl) | |
.addTo(map) | |
.on('done', function(layer){ | |
//console.log(layer); | |
sublayer = layer.getSubLayer(1); | |
//console.log(sublayer); | |
var LayerActions = { | |
layer0: function(){ | |
sublayer.setSQL("SELECT * FROM properties"); | |
//sublayer.setCartoCSS("#properties{polygon-fill: #3E7BB6;polygon-opacity: 0.7;line-color: #FFF;line-width: 0.5;line-opacity: 1;}"); | |
return true; | |
}, | |
layer1: function(){ | |
sublayer.setSQL("SELECT * FROM properties WHERE type='Public Sector'"); | |
return true; | |
}, | |
layer2: function(){ | |
sublayer.setSQL("SELECT * FROM properties WHERE type='Private Sector'"); | |
return true; | |
} | |
} | |
$('#selector').change(function() { | |
LayerActions[$(this).val()](); | |
}); | |
}); | |
} | |
window.onload = init; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment