Created
December 27, 2012 01:41
-
-
Save wboykinm/4384727 to your computer and use it in GitHub Desktop.
Fleshing out bootstrap map switch controls
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> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
#footer { | |
position:absolute; | |
bottom:0px; | |
left:0px; | |
right:0px; | |
background:#fff; | |
z-index:999; | |
overflow:auto; | |
padding:30px; | |
opacity:0.8; | |
} | |
#zoom { | |
top: 50px; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.css" /> | |
<link rel="stylesheet" href="http://geosprocket.com/assets/bootstrap/css/bootstrap-cosmo.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.ie.css" /> | |
<![endif]--> | |
</head> | |
<body> | |
<div class="navbar navbar-fixed-top"> | |
<div class="navbar-inner"> | |
<div class="container"> | |
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</a> | |
<a class="brand" href="#">MECCartes</a> | |
<div class="nav-collapse collapse"> | |
<ul class="nav"> | |
<li class="active"><a href="#">Affaires</a></li> | |
<li><a href="#contact">Irrigation</a></li> | |
<li class="dropdown"> | |
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Type de Culture <b class="caret"></b></a> | |
<ul id="layer_selector" class="dropdown-menu"> | |
<li><a href="#" data="tout" class="selected">Tout</a></li> | |
<li class="divider"></li> | |
<li><a href="#" data="ble">Ble</a></li> | |
<li><a href="#" data="fourr">Fourrage</a></li> | |
<li><a href="#" data="jache">Jacherre</a></li> | |
<li><a href="#" data="mais">Mais</a></li> | |
</ul> | |
</li> | |
</ul> | |
</div><!--/.nav-collapse --> | |
</div> | |
</div> | |
</div> | |
<div id="map"></div> | |
<div id="footer"> | |
<div class="container"> | |
<p>Le programme Competitivite Economique du Maroc (Morocco Economic Competitiveness - MEC) de la Agence Americaine pour le Developpement International (USAID) vise a reduire les freins au commerce et a l'investissement a travers une approche innovante et multimodale</p> | |
</div> | |
</div> | |
</body> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v2/cartodb.js"></script> | |
<script src="http://geosprocket.com/assets/bootstrap/js/bootstrap.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script> | |
// create layer selector | |
function createSelector(layer) { | |
var sql = new cartodb.SQL({ user: 'dai' }); | |
var $options = $('#layer_selector li'); | |
$options.click(function(e) { | |
// get the area of the selected layer | |
var $li = $(e.target); | |
var crop = $li.attr('data'); | |
// deselect all and select the clicked one | |
$options.removeClass('selected'); | |
$li.addClass('selected'); | |
// create query based on data from the layer | |
var query = "select * from ag_survey_2011"; | |
if(crop !== 'tout') { | |
query = "select * from ag_survey_2011 where " + crop + " > 0 "; | |
} | |
// change the query in the layer to update the map | |
layer.setQuery(query); | |
}); | |
} | |
function main() { | |
cartodb.createVis('map', 'http://dai.cartodb.com/api/v1/viz/11330/viz.json', { | |
tiles_loader: true, | |
center_lat: 34.88593094075317, | |
center_lon: -2.5022265625, | |
zoom: 10 | |
}) | |
.done(function(vis, layers) { | |
// layer 0 is the base layer, layer 1 is cartodb layer | |
createSelector(layers[1]) | |
}) | |
.error(function(err) { | |
console.log(err); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment