d3.js Map (<svg>) Auto Fit into Parent Container and Resize with Window

前端 未结 5 2224
时光取名叫无心
时光取名叫无心 2020-12-23 16:54

UPDATE: I have posted and accepted a fully working solution in the answers section. Any code in this section is to be used as reference for comparison to your own NO

5条回答
  •  无人及你
    2020-12-23 17:38

    In d3 v4, we could do this

    const projection = d3.geo.equirectangular().fitSize([width, height], geojson);
    const path = d3.geo.path().projection(projection);
    

    fitSize is equivalent to

    fitExtent([[0, 0], [width, height]], geojson)
    

    fill free to add padding

提交回复
热议问题