Last active
August 29, 2015 14:27
-
-
Save namessanti/2200923c37c3fba08e42 to your computer and use it in GitHub Desktop.
Crime in the U.S.A.
This file contains hidden or 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> | |
Crime in The USA | |
</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" type="text/css" /> | |
<link rel="stylesheet" href="http://academy.cartodb.com/css/cdbui.css" type="text/css" /> | |
<link href='http://fonts.googleapis.com/css?family=Merriweather:400,900,700' rel='stylesheet' type='text/css'> | |
<style type="text/css"> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
#sql { | |
position: absolute; | |
top: 10px; | |
right: 292px; | |
} | |
.layer_selector { | |
background: #fff; | |
border-radius: 4px; | |
padding: 0; | |
border: 1px solid #999999; | |
width: 248px; | |
box-shadow: rgba(0, 0, 0, 0.2) 0 0 4px 2px; | |
font: 11px 'Helvetica'; | |
position: absolute; | |
right: 20px; | |
bottom: 150px; | |
} | |
.layer_selector > p { | |
font-weight: bold; | |
color: #666666; | |
padding: 14px 14px 12px 14px; | |
cursor: pointer; | |
border-bottom: 1px solid #999; | |
} | |
.layer_selector ul { | |
padding: 0; | |
margin: 0; | |
list-style-type: none; | |
bottom: 36px; | |
border-radius: 4px; | |
} | |
.layer_selector li { | |
padding: 14px; | |
font-size: 11px; | |
color: #222; | |
cursor: pointer; | |
} | |
.layer_selector li:not(:last-child) { | |
border-bottom: 1px solid #999; | |
} | |
.layer_selector li:hover { | |
background-color: #e5e5e5; | |
cursor: pointer; | |
} | |
.layer_selector li.sql_selected, | |
.layer_selector li.cartocss_selected { | |
background-color: #A6CEE3; | |
} | |
div.cartodb-legend-stack { | |
bottom: 30px; | |
right: 30px; | |
} | |
#textbox { | |
position: absolute; | |
top: 100px; | |
color: rgba(255, 255, 255, .8); | |
text-align: center; | |
font: 400 16px/20px 'Merriweather'; | |
left: 300px; | |
right: 300px; | |
} | |
.title-inner { | |
position: absolute; | |
top: 40px; | |
right: 60px; | |
left: 60px; | |
text-align: center; | |
} | |
.title { | |
position: relative; | |
font:900 40px/1 'Merriweather'; | |
color: #fff; | |
z-index: 2; | |
letter-spacing: -1px; | |
display: inline-block; | |
} | |
.title:after { | |
content:""; | |
position: absolute; | |
width: 50px; | |
height: 1px; | |
background: #fff; | |
top: 50%; | |
left: -70px; | |
} | |
.title:before { | |
content:""; | |
position: absolute; | |
width: 50px; | |
height: 1px; | |
background: #fff; | |
top: 50%; | |
right: -70px; | |
} | |
.leaflet-left .leaflet-control { | |
margin-left: 30px; | |
margin-top: 30px; | |
} | |
@media (max-width: 1200px) { | |
#textbox { | |
left: 80px; | |
right: 80px; | |
} | |
} | |
@media (max-width: 800px) { | |
.layer_selector { | |
right: auto; | |
bottom: 30px; | |
left: 30px; | |
} | |
.leaflet-control-container { | |
display: none !important; | |
} | |
.header { | |
position: absolute; | |
background: #333; | |
padding: 25px; | |
top: 0; | |
right: 0; | |
left: 0; | |
} | |
.title-inner { | |
position: static; | |
} | |
.title { | |
font: 900 20px/1 'Merriweather'; | |
margin-bottom: 10px; | |
} | |
#textbox { | |
position: static; | |
font: 400 12px/18px 'Merriweather'; | |
} | |
.layer_selector ul { | |
height: 0; | |
opacity: 0; | |
} | |
.layer_selector > p { | |
border-bottom: 0; | |
background: url(../Crime_Map/show.png) no-repeat 220px 15px; | |
} | |
.layer_selector.is-active > p { | |
border-bottom: 0; | |
background: url(../Crime_Map/hide.png) no-repeat 220px 15px; | |
} | |
.layer_selector.is-active ul { | |
height: auto; | |
opacity: 1; | |
} | |
.layer_selector.is-active > p { | |
border-bottom: 1px solid #999; | |
} | |
} | |
@media (max-width: 600px) { | |
.layer_selector { | |
right: 30px; | |
bottom: 140px; | |
left: auto; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<div class="header"> | |
<div class="title-inner"> | |
<h1 class="title">CRIMINAL STATES</h1> | |
</div> | |
<div id="textbox"> | |
<p>With Friday the 13th behind us, we are reminded that the world can be a pretty scary place! While Jason will probably not be paying you a vist any time soon, take a moment to click around our <strong>United States Crime Map</strong> and see how the states stack up when it comes to these <strong>real-life horror stories... Yikes!</strong></p> | |
</div> | |
</div> | |
<div id="cartocss" class="layer_selector"> | |
<p id="js-crime-selector">CRIME SELECTOR</p> | |
<ul class="LayerSelector-list"> | |
<li data="0" class="vio">Total Violent Crime | |
</li> | |
<li data="1" class="vio">Aggravated Assault | |
</li> | |
<li data="2">Property Crime | |
</li> | |
<li data="3">Burglary | |
</li> | |
<li data="4">Motor Vehicle Theft | |
</li> | |
<li data="5" class="vio">Murder/Non-Negligibe Homicide | |
</li> | |
<li data="6">Larceny Theft | |
</li> | |
<li data="7">Robbery | |
</li> | |
</ul> | |
</div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js" type="text/javascript"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<!-- Place your code in the script tags below --> | |
<script type="text/javascript"> | |
window.onload = function() { | |
// Instantiate new map object, place it in 'map' element | |
var map_object = new L.Map('map', { | |
center: [34.6541154,-4.4637914], // San Francisco | |
zoom: 4 | |
}); | |
var densityLegend = new cdb.geo.ui.Legend.Density({ | |
title: 'Data From FBI Crime Reporting 2013', | |
left: "Low", right: "High", colors: [ "#FFFFB2", "#FED976", "#FEB24C", "#FD8D3C", "#FC4E2A", "#E31A1C", "#B10026" ] | |
}); | |
$('#map').append(densityLegend.render().el); | |
// Hide the legend for Violent crimes by default | |
$(densityLegend.render().el).hide() | |
var densityLegendNon = new cdb.geo.ui.Legend.Density({ | |
title: 'Data From FBI Crime Reporting 2013', | |
left: "Low", right: "High", colors: [ "#FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#1D91C0", "#225EA8", "#0C2C84" ] | |
}); | |
$('#map').append(densityLegendNon.render().el); | |
// Create layer selector | |
function createSelector(layer,num,violent) { | |
for (var i = 0; i < layer.getSubLayerCount(); i++) { | |
if (i === num) { | |
layer.getSubLayer(i).show(); | |
} else { | |
layer.getSubLayer(i).hide(); | |
} | |
} | |
if (violent){ | |
$(densityLegendNon.render().el).hide() | |
$(densityLegend.render().el).show() | |
} else { | |
$(densityLegend.render().el).hide() | |
$(densityLegendNon.render().el).show() | |
} | |
} | |
// Pull tiles from CartoDB's basemaps | |
L.tileLayer('http://www.colourlovers.com/wallPaper/1200x800/n/2875/COLOURlovers.com-Gothic_Wallpaper.png', { | |
attribution: '© <a href="http://www.colourlovers.com/lover/candycrack/loveNote">CandyCrack</a> contributors' | |
}).addTo(map_object); | |
// for storing sublayer outside of createlayer | |
var sublayers; | |
// Add data layer to your map | |
cartodb.createLayer(map_object,'https://team.cartodb.com/u/santiagoa/api/v2/viz/5a9a49ce-b3a9-11e4-921d-0e9d821ea90d/viz.json') | |
.addTo(map_object) | |
.done(function(layer) { | |
$("li").on('click', function(e) { | |
var num = +$(e.target).attr('data'); | |
createSelector(layer,num,$(e.target).hasClass('vio')); | |
}); | |
}) | |
.error(function(err) { | |
console.log("error: " + err); | |
}); | |
} | |
$( document ).ready(function() { | |
$( "#js-crime-selector" ).click(function() { | |
$( '.layer_selector' ).toggleClass( "is-active" ); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment