World in Kavrayskiy VII projection with SVG Filters applied.
Last active
September 19, 2017 17:16
-
-
Save toja/4770c1dd976451b9559ad25399caa7ba to your computer and use it in GitHub Desktop.
World - SVG filter
This file contains hidden or 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: gpl-3.0 | |
| height: 500 | |
| border: no |
This file contains hidden or 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"> | |
| <style> | |
| .stroke { | |
| fill: none; | |
| stroke: #ccc; | |
| stroke-width: .5px; | |
| } | |
| .fill { | |
| fill: #f2f4f6; | |
| } | |
| .graticule { | |
| fill: none; | |
| stroke: #ccc; | |
| stroke-width: .5px; | |
| stroke-opacity: .4; | |
| } | |
| .land { | |
| fill: #e4e2e0; | |
| } | |
| .boundary { | |
| fill: none; | |
| stroke: #c6c4c2; | |
| stroke-width: 0.5px; | |
| } | |
| </style> | |
| <body> | |
| <script src="//d3js.org/d3.v4.min.js"></script> | |
| <script src="//d3js.org/d3-geo-projection.v1.min.js"></script> | |
| <script src="//d3js.org/topojson.v2.min.js"></script> | |
| <script> | |
| var width = 960, | |
| height = 500; | |
| var proj = d3.geoKavrayskiy7() | |
| .precision(.1); | |
| var path = d3.geoPath() | |
| .projection(proj); | |
| var graticule = d3.geoGraticule(); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| var defs = svg.append("defs"); | |
| var oglow = defs.append("filter") | |
| .attr("id","oglow"); | |
| oglow.append("feColorMatrix") | |
| .attr("in","SourceGraphic") | |
| .attr("type", "matrix") | |
| .attr("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0") | |
| .attr("result","mask"); | |
| oglow.append("feMorphology") | |
| .attr("in","mask") | |
| .attr("radius","1") | |
| .attr("operator","dilate") | |
| .attr("result","mask"); | |
| oglow.append("feColorMatrix") | |
| .attr("in","mask") | |
| .attr("type", "matrix") | |
| .attr("values", "0 0 0 0 0.4 0 0 0 0 0.45 0 0 0 0 0.5 0 0 0 1 0") | |
| .attr("result","r0"); | |
| oglow.append("feGaussianBlur") | |
| .attr("in","r0") | |
| .attr("stdDeviation","3") | |
| .attr("result","r1"); | |
| oglow.append("feComposite") | |
| .attr("operator","out") | |
| .attr("in","r1") | |
| .attr("in2","mask") | |
| .attr("result","comp"); | |
| var frMerge = oglow.append("feMerge"); | |
| frMerge.append("feMergeNode") | |
| .attr("in","SourceGraphic"); | |
| frMerge.append("feMergeNode") | |
| .attr("in","r1"); | |
| defs.append("path") | |
| .datum({type: "Sphere"}) | |
| .attr("id", "sphere") | |
| .attr("d", path); | |
| svg.append("use") | |
| .attr("class", "stroke") | |
| .attr("xlink:href", "#sphere"); | |
| svg.append("use") | |
| .attr("class", "fill") | |
| .attr("xlink:href", "#sphere"); | |
| var features = svg.append("g"); | |
| features.append("path") | |
| .datum(graticule) | |
| .attr("class", "graticule") | |
| .attr("d", path); | |
| d3.json("110m.json", function(error, world) { | |
| if (error) throw error; | |
| features.append("path") | |
| .datum(topojson.feature(world, world.objects.countries)) | |
| .attr("class", "land") | |
| .attr("d", path) | |
| .style("filter","url(#oglow)"); | |
| features.append("path") | |
| .datum(topojson.feature(world, world.objects.countries)) | |
| .attr("class", "land") | |
| .attr("d", path); | |
| features.append("path") | |
| .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; })) | |
| .attr("class", "boundary") | |
| .attr("d", path); | |
| }); | |
| d3.select(self.frameElement).style("height", height + "px"); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment