Using Canvas shadows.
Last active
October 28, 2017 13:31
-
-
Save martgnz/b43851a7804c8e420a5f19a4c1dd3706 to your computer and use it in GitHub Desktop.
Canvas shadows
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> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment