This map was created using rCharts, Leaflet and Leaflet-geoCSV
Last active
December 17, 2015 04:29
-
-
Save ramnathv/5550612 to your computer and use it in GitHub Desktop.
Leaflet: Crime Map
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> | |
<link rel='stylesheet' href="http://netdna.bootstrapcdn.com/bootswatch/2.3.1/cosmo/bootstrap.min.css"> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" > | |
<link rel='stylesheet' href="http://twitter.github.io/bootstrap/assets/js/google-code-prettify/prettify.css"> | |
<link rel='stylesheet' href='http://leafletjs.com/dist/leaflet.css'> | |
<script src='http://leafletjs.com/dist/leaflet.js' type='text/javascript'></script> | |
<script src='https://rawgithub.com/joker-x/Leaflet.geoCSV/gh-pages/leaflet.geocsv-src.js' type='text/javascript'></script> | |
<style> | |
.rChart { | |
display: block | |
margin: auto auto; | |
width: 800px; | |
height: 400px; | |
} | |
body { | |
margin-top: 60px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class='container'> | |
<div class='row'> | |
<div class='span9'> | |
<div id='chartff36d679f45' class='rChart nvd3Plot leaflet'></div> | |
<br/> | |
<pre><code class='r'>map4 = Leaflet$new() | |
map4$setView(29.6779, -95.4379, 10) | |
map4$tileLayer("http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png") | |
data(crime, package = 'ggmap') | |
dat <- head(crime)[,c('lat', 'lon', 'offense')] | |
names(dat) <- c('lat', 'lng', 'offense') | |
map4$geocsv(dat) | |
map4 | |
</code></pre> | |
</div> | |
</div> | |
</div> | |
<script> | |
var spec = { | |
"dom": "chartff36d679f45", | |
"width": 800, | |
"height": 400, | |
"center": [ | |
29.678, | |
-95.438 | |
], | |
"viewOpts": [ | |
10 | |
], | |
"urlTemplate": "http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png", | |
"layerOpts": { | |
"attribution": "Map data © <a href=\"http://openstreetmap.org\">OpenStreetMap</a>contributors, Imagery © <a href=\"http://mapbox.com\">MapBox</a>" | |
}, | |
"geocsv": { | |
"titles": [ "lat", "lng", "offense" ], | |
"data": "29.6779015;-95.4373883;murder\n29.6917121;-95.2988769;robbery\n29.5992174;-95.455864;aggravated assault\n29.7902425;-95.4033373;aggravated assault\n29.6706341;-95.3779081;aggravated assault\n29.7022336;-95.5483009;burglary" | |
}, | |
"id": "chartff36d679f45" | |
} | |
var map = L.map(spec.dom) | |
.setView(spec.center, spec.viewOpts); | |
L.tileLayer(spec.urlTemplate, spec.layerOpts) | |
.addTo(map); | |
if (spec.geocsv.data.length > 0){ | |
var geo_csv = L.geoCsv(null, { | |
titles: spec.geocsv.titles, | |
fieldSeparator: ';', | |
lineSeparator: '\n', | |
deleteDobleQuotes: true, | |
firstLineTitles: false, | |
onEachFeature: function (feature, layer) { | |
var popup = ''; | |
for (var clave in feature.properties) { | |
var title = geo_csv.getPropertyTitle(clave); | |
popup += '<b>'+title+'</b><br />'+feature.properties[clave]+'<br /><br />'; | |
} | |
layer.bindPopup(popup); | |
} | |
}) | |
geo_csv.addData(spec.geocsv.data) | |
map.addLayer(geo_csv) | |
} | |
/* | |
L.marker([51.5, -0.09]).addTo(map) | |
.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup(); | |
L.marker([51.52, -0.09]).addTo(map) | |
.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup(); | |
L.circle([51.508, -0.11], 500, { | |
color: 'red', | |
fillColor: '#f03', | |
fillOpacity: 0.5 | |
}).addTo(map).bindPopup("I am a circle."); | |
L.polygon([ | |
[51.509, -0.08], | |
[51.503, -0.06], | |
[51.51, -0.047] | |
]).addTo(map).bindPopup("I am a polygon."); | |
var popup = L.popup(); | |
function onMapClick(e) { | |
popup | |
.setLatLng(e.latlng) | |
.setContent("You clicked the map at " + e.latlng.toString()) | |
.openOn(map); | |
} | |
map.on('click', onMapClick); | |
*/ | |
</script> | |
</body> | |
<!-- Google Prettify --> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/188.0.0/prettify.js"></script> | |
<script | |
src='https://google-code-prettify.googlecode.com/svn-history/r232/trunk/src/lang-r.js'> | |
</script> | |
<script> | |
var pres = document.getElementsByTagName("pre"); | |
for (var i=0; i < pres.length; ++i) { | |
pres[i].className = "prettyprint linenums"; | |
} | |
prettyPrint(); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment