Skip to content

Instantly share code, notes, and snippets.

@markmarkoh
Forked from markmarkoh/README.md
Last active August 29, 2015 14:02
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 markmarkoh/6368437cb8273b26c1e2 to your computer and use it in GitHub Desktop.
Save markmarkoh/6368437cb8273b26c1e2 to your computer and use it in GitHub Desktop.
Centering bubbles with custom map data
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.
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://rawgithub.com/markmarkoh/datamaps/master/dist/datamaps.none.min.js"></script>
<div id="afghan" style="height: 500px; width: 900px;"></div>
<script>
var map = new Datamap({
element: document.getElementById('afghan'),
geographyConfig: {
dataUrl: 'customAfghanMap.topo.json'
},
scope: 'afghan',
fills: {
defaultFill: '#bada55',
someKey: '#fa0fa0',
someBubbleFill: '#f0a0a0'
},
data: {
'AFG-1758': {fillKey: 'someKey'},
'AFG-1747': {fillKey: 'someKey'}
},
setProjection: function(element) {
var projection = d3.geo.mercator()
.center([66.166667, 34.4444])
.scale(2200)
.translate([element.offsetWidth / 2, element.offsetHeight / 2]);
var path = d3.geo.path().projection(projection);
return {path: path, projection: projection};
},
done: function() {
map.bubbles([
{centered: 'AFG-1741', fillKey: 'someKey', radius: 25},
{centered: 'AFG-1747', fillKey: 'someBubbleFill', radius: 45},
]);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment