{
const width = 640;
const height = 400;
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const geometry = topojson.feature(
topoMegedSimplified,
topoMegedSimplified.objects["hokkaido"]
);
return geometry;
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("fill", (d) => {
if (d.properties.name === "札幌市") {
return "red";
} else {
return "teal";
}
})
.attr("stroke", "black")
.attr("stroke-width", "0.5px");
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();
}