Skip to content

Instantly share code, notes, and snippets.

@5un
Last active April 11, 2018 18:44
Show Gist options
  • Save 5un/a8461f00ccba2a9ef1779d8dd4303675 to your computer and use it in GitHub Desktop.
Save 5un/a8461f00ccba2a9ef1779d8dd4303675 to your computer and use it in GitHub Desktop.
ischool-geo-viz-template
license: mit

Template

Here you will find an empty HTML template for the workshop. We'll be adding javascript code to the section between the opening and closing <script></script> tags in the index.html file.

Let's get started!

Built with blockbuilder.org

forked from clhenrick's block: ischool-geo-viz-template

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>iSchool GeoVisualization Workshop</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="//d3js.org/d3.v3.min.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.35.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.35.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
// javascript code goes here
var dataURL = "https://raw.githubusercontent.com/clhenrick/geovisualization_workshop_ischool/master/data/nyc_crashes.geojson";
var accessToken = 'pk.eyJ1IjoiZW5qYWxvdCIsImEiOiIzOTJmMjBiZmI2NGQ2ZjAzODhiMzhiOGI2MTI1YTk4YSJ9.sIOXXU3TPp5dLg_L3cUxhQ';
mapboxgl.accessToken = accessToken;
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/dark-v9",
center: [-74, 40.7],
zoom: 10
});
map.addControl(new mapboxgl.NavigationControl());
map.on("load", function() {
d3.json(dataURL, (error, data) => {
if (error) throw error;
//console.log(data);
const features = data.features;
map.addSource("crashes", {
type: 'geojson',
data: dataURL,
cluster: true,
clusterRadius: 10,
clusterMaxZoom: 12
});
map.addLayer({
id: "crashes",
type: "circle",
source: "crashes",
layout: {},
paint: {
"circle-color": {
property: "crash_type",
type: "categorical",
stops: [
["no_injury_fatality", "#fecc5c"],
["injury", "#fd8d3c"],
["fatality", "#f03b20"],
["injury_and_fatality", "#bd0026"]
]
},
"circle-opacity": 0.8,
"circle-radius": {
base: 1.75,
stops: [
[12, 2],
[22, 180]
]
}
}
});
});
d3.json(hexBinURL, (error, data) => {
// if (error) throw error;
// console.log(data);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment