d3,v4以前用d3畫地圖的時候,為了讓地圖差不多正好畫在容器的上下左右正中間,不得不慢慢的這樣調:
const projection = d3.geoMercator() .center([108.3340400357, 22.8212837740]) .scale(4900) .translate([400, 330]);
center還好搞,搜一下經緯度就搞定
scale和translate要配合起來一起搞基,搞過的都知道,沒搞過的就去試試
從V4版本開始,終極殺手鐧來了:
const projection = d3.geoMercator().fitSize([width, height], geoJSON);
就是這樣簡單到叫你目瞪口呆,連經緯度也不要了。騷年,快去試試吧!!!