Done with Spam.js.
Last active
October 28, 2017 15:24
-
-
Save martgnz/23a2c10ceb7690fa5fe63f65fcb4d690 to your computer and use it in GitHub Desktop.
Trips
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
license: mit | |
border: none |
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> | |
<meta charset="utf-8" /> | |
<body> | |
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="https://d3js.org/topojson.v1.min.js"></script> | |
<script src="https://unpkg.com/rbush@1.4.3/rbush.js"></script> | |
<script src="https://unpkg.com/d3-geo-projection@0.2.16/d3.geo.projection.min.js"></script> | |
<script src="https://unpkg.com/spamjs@1.1.0/spam.min.js"></script> | |
<script type='text/javascript'> | |
var graticule = d3.geo.graticule(); | |
d3.csv("places.csv", function(error, places) { | |
d3.json("https://unpkg.com/world-atlas@1.1.4/world/50m.json", function( | |
error, | |
d | |
) { | |
topojson.presimplify(d); | |
var map = new StaticCanvasMap({ | |
element: "body", | |
width: 960, | |
projection: d3.geo.winkel3(), | |
data: [ | |
{ | |
features: topojson.feature(d, d.objects["countries"]), | |
static: { | |
prepaint: function(parameters, d) { | |
parameters.context.beginPath(); | |
parameters.path(graticule.outline()); | |
parameters.context.lineWidth = 2; | |
parameters.context.strokeStyle = "rgb(30,30,30)"; | |
parameters.context.stroke(); | |
parameters.context.fillStyle = "rgba(51, 103, 153, 0.6)"; | |
parameters.context.fill(); | |
parameters.context.beginPath(); | |
parameters.path(graticule()); | |
parameters.context.lineWidth = 0.5; | |
parameters.context.strokeStyle = "rgb(230,230,230)"; | |
parameters.context.stroke(); | |
}, | |
paintfeature: function(parameters, d) { | |
parameters.context.lineWidth = 0.5 / parameters.scale; | |
parameters.context.strokeStyle = "rgb(30,30,30)"; | |
parameters.context.stroke(); | |
parameters.context.fillStyle = "rgb(255, 255, 255)"; | |
parameters.context.fill(); | |
}, | |
postpaint: function(parameters, d) { | |
places.forEach(function(d) { | |
var projectedPoint = parameters.map | |
.settings() | |
.projection([+d.long, +d.lat]); | |
parameters.context.beginPath(); | |
parameters.context.arc( | |
projectedPoint[0], | |
projectedPoint[1] / parameters.scale, | |
3 / parameters.scale, | |
0, | |
2 * Math.PI, | |
true | |
); | |
parameters.context.fillStyle = "rgb(225, 38, 47)"; | |
parameters.context.fill(); | |
}); | |
} | |
} | |
} | |
] | |
}); | |
map.init(); | |
}); | |
}); | |
</script> |
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
city | lat | long | |
---|---|---|---|
New York | 40.681883 | -73.998636 | |
DC | 38.900460 | -77.037245 | |
Madrid | 40.415132 | -3.705981 | |
Riga | 56.949308 | 24.098943 | |
London | 51.508653 | -0.144203 | |
Berlin | 52.514733 | 13.408626 | |
Paris | 48.857031 | 2.349271 | |
Barcelona | 41.388330 | 2.177261 | |
Oslo | 59.914440 | 10.749404 | |
Santiago | -33.446121 | -70.655963 | |
Rome | 41.900787 | 12.487237 | |
Porto | 41.159279 | -8.624259 | |
Granada | 37.442677 | -3.410704 | |
Bilbao | 43.264693 | -2.936998 | |
Stockholm | 59.327818 | 18.065817 | |
Bergen | 60.388649 | 5.319285 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment