xxxxxxxxxx
<meta charset="utf-8">
<style>
.background {
fill: none;
pointer-events: all;
}
#country {
fill: #aaa;
}
#country-borders {
fill: none;
stroke: #fff;
stroke-width: 1.5px;
stroke-linejoin: round;
stroke-linecap: round;
pointer-events: none;
}
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.mercator()
.scale(100)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var zoom = d3.behavior.zoom()
.translate(projection.translate())
.scale(projection.scale())
.scaleExtent([100, 1000])
.on("zoom", zoomed);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g")
.call(zoom);
var dotSpot = [[20,20], [10,10]];
console.log(projection(dotSpot[0])[0])
g.append("rect")
.attr("class", "background")
.attr("width", width)
.attr("height", height);
d3.json("world.json", function(error, nations) {
console.log(nations)
g.append("g")
.attr("id", "country")
.selectAll("path")
.data(topojson.feature(nations, nations.objects.countries).features)
.enter().append("path")
.attr("d", path);
g.append("path")
.datum(topojson.mesh(nations, nations.objects.countries, function(a, b) { return a !== b; }))
.attr("id", "country-borders")
.attr("d", path);
g.selectAll("circle")
.data(dotSpot).enter()
.append("circle")
.attr("cx", function (d,i) { return projection(d)[0]; })
.attr("cy", function (d,i) { return projection(d)[1]; })
.attr("r", "10px")
.style("fill", "red");
});
function zoomed() {
projection.translate(d3.event.translate).scale(d3.event.scale);
g.selectAll("path").attr("d", path)
g.selectAll("circle")
.attr("cx", function (d,i) { return projection(d)[0]; })
.attr("cy", function (d,i) { return projection(d)[1]; })
.attr("r", "10px")
.style("fill", "red");
}
</script>
Modified http://d3js.org/d3.v3.min.js to a secure url
Modified http://d3js.org/topojson.v1.min.js to a secure url
https://d3js.org/d3.v3.min.js
https://d3js.org/topojson.v1.min.js