Skip to content

Instantly share code, notes, and snippets.

@martgnz
Last active October 28, 2017 13:31
Show Gist options
  • Save martgnz/b43851a7804c8e420a5f19a4c1dd3706 to your computer and use it in GitHub Desktop.
Save martgnz/b43851a7804c8e420a5f19a4c1dd3706 to your computer and use it in GitHub Desktop.
Canvas shadows
license: mit
border: none

Using Canvas shadows.

<!DOCTYPE html>
<meta charset="utf-8" />
<body>
<style>
body {
margin: 0
}
</style>
<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/spamjs@1.1.0/spam.min.js"></script>
<script type='text/javascript'>
var graticule = d3.geo.graticule();
d3.json("world-50m.json", function(error, d) {
topojson.presimplify(d);
var map = new StaticCanvasMap({
element: "body",
width: 960,
projection: d3.geo.equirectangular(),
data: [
{
features: topojson.feature(d, d.objects["land"]),
static: {
prepaint: function(parameters) {
parameters.context.beginPath();
parameters.path(graticule.outline());
parameters.context.fillStyle = "rgb(5, 5, 5)";
parameters.context.fill();
},
paintfeature: function(parameters, d) {
parameters.context.fillStyle = "rgb(20, 20, 20)";
parameters.context.fill();
parameters.context.lineWidth = 2;
parameters.context.strokeStyle = "rgb(8, 110, 138)";
parameters.context.shadowColor = "rgba(255,255,255, 0.4)";
parameters.context.shadowOffsetX = 0;
parameters.context.shadowOffsetY = 0;
parameters.context.shadowBlur = 20;
parameters.context.stroke();
}
}
},
{
features: topojson.feature(d, d.objects["countries"]),
static: {
paintfeature: function(parameters, d) {
parameters.context.lineWidth = 1;
parameters.context.strokeStyle = "rgba(8, 110, 138, .3)";
parameters.context.stroke();
}
}
}
]
});
map.init();
});
</script>
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