我正在geoAlbersUSA
使用d3-geo
and渲染SVG 地图topojson-client
- 如下所示 - 但是当用户单击路径时,我试图做一些花哨的事情。我想缩放和转换底层路径,在这种情况下是爱达荷州或弗吉尼亚州,以便该州“漂浮”在美国上方,但仍以质心为中心。每次我试图简单地scale
将<path/>
它结束了许多像素的位置元素; 有没有办法计算translate()
对应于您缩放元素的程度?
const states = topojson.feature(us, us.objects.states as GeometryObject) as ExtendedFeatureCollection;
const path = geoPath()
.projection(geoAlbersUsa()
.fitSize([innerWidth as number, innerHeight as number], states)
);
<svg>
{
states.features.map(feature => {
return <path key={`state-path-${feature.id}`} d={path(feature) as string} onClick={() => updateScaleAndTranslate(feature)} />
}
}
</svg>