Skip to content

Instantly share code, notes, and snippets.

@activeshadow
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save activeshadow/86f232f4b1ca485dfd91 to your computer and use it in GitHub Desktop.
Save activeshadow/86f232f4b1ca485dfd91 to your computer and use it in GitHub Desktop.
Map w/ Location Markers as SVG Paths
code city country lat lon
ZNZ ZANZIBAR TANZANIA -6.13 39.31
TYO TOKYO JAPAN 35.68 139.76
AKL AUCKLAND NEW ZEALAND -36.85 174.78
BKK BANGKOK THAILAND 13.75 100.48
DEL DELHI INDIA 29.01 77.38
SIN SINGAPORE SINGAPOR 1.36 103.75
BSB BRASILIA BRAZIL -15.67 -47.43
RIO RIO DE JANEIRO BRAZIL -22.90 -43.24
YTO TORONTO CANADA 43.64 -79.40
IPC EASTER ISLAND CHILE -27.11 -109.36
SEA SEATTLE USA 47.61 -122.33
<!DOCTYPE html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<style>
path {
stroke: white;
stroke-width: 0.5px;
}
</style>
</head>
<body>
<script>
var world = d3.select('body')
.append('svg:svg')
.attr('width', '1000px')
.attr('height', '500px');
var projection = d3.geo.mercator()
.center([0,50])
.scale(150)
.rotate([0,0]);
var path = d3.geo.path()
.projection(projection);
var g = world.append('g');
d3.json('world.json', function(error, topology) {
d3.csv('cities.csv', function(error, data) {
var nodes = g.selectAll('g.node')
.data(data)
.enter().append('g').attr('class', 'node')
.attr('transform', function(d) { return 'translate(' + projection([d.lon, d.lat])[0] + ',' + projection([d.lon, d.lat])[1] + ')'; });
nodes.append('path')
.attr('d', 'M16,0C9.382,0,4,5.316,4,12.001c0,7,6.001,14.161,10.376,19.194 C14.392,31.215,15.094,32,15.962,32c0.002,0,0.073,0,0.077,0c0.867,0,1.57-0.785,1.586-0.805 c4.377-5.033,10.377-12.193,10.377-19.194C28.002,5.316,22.619,0,16,0z M16.117,29.883c-0.021,0.02-0.082,0.064-0.135,0.098 c-0.01-0.027-0.084-0.086-0.129-0.133C12.188,25.631,6,18.514,6,12.001C6,6.487,10.487,2,16,2c5.516,0,10.002,4.487,10.002,10.002 C26.002,18.514,19.814,25.631,16.117,29.883z')
.attr('fillrule', 'evenodd')
.attr('cliprule', 'evenodd')
.attr('fill', '#333333');
nodes.append('path')
.attr('d', 'M16.002,17.746c3.309,0,6-2.692,6-6s-2.691-6-6-6 c-3.309,0-6,2.691-6,6S12.693,17.746,16.002,17.746z M16.002,6.746c2.758,0,5,2.242,5,5s-2.242,5-5,5c-2.758,0-5-2.242-5-5 S13.244,6.746,16.002,6.746z')
.attr('fillrule', 'evenodd')
.attr('cliprule', 'evenodd')
.attr('fill', '#333333');
});
g.selectAll('path')
.data(topojson.feature(topology, topology.objects.countries).features)
.enter()
.append('path')
.attr('d', path);
});
var zoom = d3.behavior.zoom().on('zoom', function() {
g.attr('transform', 'translate(' + d3.event.translate.join(',') + ') scale(' + d3.event.scale + ')');
//g.selectAll('path').attr('d', path.projection(projection));
});
world.call(zoom);
</script>
</body>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment