Skip to content

Instantly share code, notes, and snippets.

@woobe
Last active August 29, 2015 14:02
Show Gist options
  • Save woobe/9890c5897b864f9c32f3 to your computer and use it in GitHub Desktop.
Save woobe/9890c5897b864f9c32f3 to your computer and use it in GitHub Desktop.
[rCrimemap]: All Crimes in January 2014 on Open Street Map
## Load Library
library(rCrimemap) # devtools::install_github("woobe/rCrimemap")
## Create Crime Heatmap with Nokia map base
r1 <- rcmap_quick(period = "2014-01",
map_size = c(960, 500),
provider = "OpenStreetMap.BlackAndWhite",
zoom = 6)
## Save the Heatmap as a self-contained HTML
r1$save("index.html", cdn = TRUE)
This file has been truncated, but you can view the full file.
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css'>
<link rel='stylesheet' href='http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js'>
<script src='http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js' type='text/javascript'></script>
<script src='https://rawgithub.com/leaflet-extras/leaflet-providers/gh-pages/leaflet-providers.js' type='text/javascript'></script>
<script src='http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js' type='text/javascript'></script>
<script src='http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js' type='text/javascript'></script>
<style>
.rChart {
display: block;
margin-left: auto;
margin-right: auto;
width: 960px;
height: 500px;
}
</style>
</head>
<body >
<div id = 'chart36881169160d' class = 'rChart leaflet'></div>
<script>
var spec = {
"dom": "chart36881169160d",
"width": 960,
"height": 500,
"urlTemplate": "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
"layerOpts": {
"attribution": "Map data<a href=\"http://openstreetmap.org\">OpenStreetMap</a>\n contributors, Imagery<a href=\"http://mapbox.com\">MapBox</a>"
},
"center": [ 52.681602, -1.831672 ],
"zoom": 6,
"provider": "OpenStreetMap.BlackAndWhite",
"id": "chart36881169160d"
}
var map = L.map(spec.dom, spec.mapOpts)
map.setView(spec.center, spec.zoom);
if (spec.provider){
L.tileLayer.provider(spec.provider).addTo(map)
} else {
L.tileLayer(spec.urlTemplate, spec.layerOpts).addTo(map)
}
if (spec.circle2){
for (var c in spec.circle2){
var circle = L.circle(c.center, c.radius, c.opts)
.addTo(map);
}
}
</script>
<script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment