veroniMap = {
const width = 500;
const height = 500;
const californiaGeoJSON = topojson.feature(us, us.objects.states).features.filter(d => d.properties.name === 'New York');
const projection = d3.geoAlbers().fitSize([width, height], californiaGeoJSON[0])
function multiPolygonToPoints(multiPolygonFeature, projection) {
let points = [];
if (multiPolygonFeature.type === 'Feature' && multiPolygonFeature.geometry.type === 'MultiPolygon') {
let multiPolygon = multiPolygonFeature.geometry.coordinates;
for (let polygon of multiPolygon) {
for (let linearRing of polygon) {
for (let point of linearRing) {
points.push(point);
}
}
}
}
return points.map(p => projection(p));
}
const clippingPolygon = multiPolygonToPoints(californiaGeoJSON[0], projection);
const svg = d3.create('svg')
.attr('width', width)
.attr('height', height);
const geoPath = d3.geoPath().projection(projection);
var simulation = d3.voronoiMapSimulation(data)
.weight(function(d){ return d.value; })
.clip(clippingPolygon)
.stop();
var state = simulation.state();
while (!state.ended) {
simulation.tick();
state = simulation.state();
}
var polygons = state.polygons;
console.log(polygons)
function polygonPath(polygon) {
return polygon ? "M" + polygon.join("L") + "Z" : null;
}
svg.append("clipPath")
.attr("id", "california-clip")
.append("path")
.datum(californiaGeoJSON[0])
.attr("d", geoPath);
svg.selectAll(".voronoi")
.data(polygons)
.enter().append("path")
.attr("class", "voronoi")
.attr("d", d => polygonPath(d))
.attr("stroke", "white")
.attr("clip-path", `url(#${"california-clip"})`)
.attr("stroke-width", 4)
.attr("fill", d => {
return color(d.site.originalObject.data.originalData.name)
});
return svg.node()
}