Skip to content

Instantly share code, notes, and snippets.

@adriankonopko
Last active February 21, 2020 12:58
Show Gist options
  • Save adriankonopko/6b5b99dd171b382c260b3f836515c93b to your computer and use it in GitHub Desktop.
Save adriankonopko/6b5b99dd171b382c260b3f836515c93b to your computer and use it in GitHub Desktop.
Map d3
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-geo-projection.v2.min.js"></script>
<script src="https://unpkg.com/topojson-client@3"></script>
<script src="https://d3js.org/d3-geo-projection.v2.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
var width = 960,
height = 500;
var svg = d3.select("body").append("svg")
.attr("id", "map")
.attr("class", "world-map")
.call(
d3.zoom().on("zoom", function() {
svg.attr("transform", d3.event.transform)
}))
.style("width", "100%")
.style("height", "100%")
.append("g")
.attr("class", "countries")
.attr("transform", "translate(50,200) scale(1)");
var projection = d3.geoMercator();
var path = d3.geoPath().projection(projection);
var url = "https://blockbuilder.org/adriankonopko/6b5b99dd171b382c260b3f836515c93b/worldmap.json";
d3.json(url, function(error, world) {
if (error)
throw error;
console.log(world);
/*svg.selectAll("path").data(
topojson.feature(world, world).features)
.enter()
.append("path")
.attr("class", "country")
.style("cursor", "pointer")
.attr("d", path)
.style("fill", "#bccad8")
.style("stroke","#bccad8")
.on('mouseover',function(d) {
d3.select(this)
.style("opacity", 1)
.style("stroke","white")
.style("stroke-width", 3);
}).on('mouseout',function(d) {
d3.select(this)
.style("opacity", 1)
.style("stroke","#bccad8");
});
var aa = [-122.490402, 37.786453];
svg.selectAll("img")
.data(topojson.feature(world, world.objects.countries).features).enter()
.append("image")
.attr('xlink:href', 'http://ttsdigitizationdev:30000/tts-cibot-service/angular/assets/images/icons/Sales.png')
.attr('width', 14)
.attr('height', 14)
.attr("transform", "translate(231.4374069230861,180.5421896454291)");
*/
});
</script>
</body>
Display the source blob
Display the rendered blob
Raw
Loading
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