function init(data) {
const projection = d3.geoMercator().fitExtent(
[
[0, 0],
[width, height],
],
data
);
var path = d3.geoPath().projection(projection);
var svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
svg
.selectAll("path")
.data(data.features)
.enter()
.append("path")
.on("mouseover", function () {
d3.select(this).style("fill", "#7c3aed");
d3.select(this).style("stroke-width", 2);
})
.on("mouseout", function () {
d3.select(this).style("fill", "white");
d3.select(this).style("stroke-width", 1);
})
.attr("d", path)
.attr("fill", (d) => {
if (d.properties.name.indexOf("广东") > -1) {
return "#0ea5e9";
} else {
return "white";
}
})
.attr("stroke", "black")
.attr("stroke-width", 1)
.append("title")
.text((d) => d.properties.name);
return svg
}