Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Last active January 2, 2016 13:49
Show Gist options
  • Select an option

  • Save rhysforyou/8312235 to your computer and use it in GitHub Desktop.

Select an option

Save rhysforyou/8312235 to your computer and use it in GitHub Desktop.
Broken Plotting Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scratch</title>
<style>
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.pin {
fill: red;
}
</style>
</head>
<body>
<section id="graph">
</section>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="./main.js"></script>
<script type="text/javascript">
</script>
</body>
</html>
var places = [
{
name: "Wollongong, Australia",
location: {
latitude: -34.42507,
longitude: 150.89315
}
},
{
name: "Newcastle, Australia",
location: {
latitude: -32.92669,
longitude: 151.77892
}
}
]
var width = 960
var height = 480
var projection = d3.geo.equirectangular()
.scale(153)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geo.path()
.projection(projection)
var graticule = d3.geo.graticule()
var svg = d3.select("#graph").append("svg")
.attr("width", width)
.attr("height", height)
// Map
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path)
d3.json("/rpowelll/raw/8312267/world-50m.json", function(error, world) {
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path)
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b }))
.attr("class", "boundary")
.attr("d", path)
})
// Location points
svg.selectAll(".pin")
.data(places)
.enter().append("circle", ".pin")
.attr("r", 5)
.attr("transform", function(d) {
return "translate(" + projection([
d.location.latitude,
d.location.longitude
]) + ")"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment