{
const width = 640;
const height = 400;
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append("rect")
.attr("width", width)
.attr("height", height)
.attr("fill", "#005773");
const geometry = topojson.feature(topology, topology.objects["hokkaido"]);
const projection = d3.geoMercator().fitExtent(
[
[0, 0],
[width, height]
],
geometry
);
const path = d3.geoPath().projection(projection);
const g = svg
.append("g")
.selectAll("path")
.data(geometry.features)
.enter()
.append("path")
.attr("d", path)
.attr("stroke", "black")
.attr("stroke-width", "0.5px")
.attr("fill", (d) => {
if (d.properties.name === "札幌市") {
return "red";
} else {
return "white";
}
})
.on("mouseover", function () {
d3.select(this).attr("fill", "yellow");
})
.on("mouseout", function (d) {
d3.select(this).attr("fill", "green");
});
function zoomed(event) {
const { transform } = event;
g.attr("transform", transform);
g.attr("stroke-width", 1 / transform.k);
}
svg.call(d3.zoom().scaleExtent([1, 8]).on("zoom", zoomed));
return svg.node();
}