【发布时间】:2017-09-08 19:30:52
【问题描述】:
我正在尝试使用 GeoJSON 数据渲染带有叠加层的地图。我已将数据加载到 QGIS 和 mapshaper 中,并且可以正确渲染;但是,我的 JavaScript 代码没有呈现我所期望的(整个 SVG 被填充,让我认为这是一个缩放问题。)
我相信我计算比例的代码是准确的。
var bounds = path.bounds(us),
scale = .95 / Math.max((bounds[1][0] - bounds[0][0]) / width, (bounds[1][1] - bounds[0][1]) /height),
translation = [(width - scale * (bounds[1][0] + bounds[0][0])) / 2, (height - scale * (bounds[1][1] + bounds[0][1])) / 2];
我已将示例项目上传到 plunker https://plnkr.co/edit/jzXRaOs2xXpZuJraMq3p。
【问题讨论】: