最佳答案
您可以使用 d3.js图书馆。以下代码片段将完成这项工作:
在你的 html 文件中包含 d3.js
<script src="files/d3.v3.min.js"></script>
假设,您的 html 文件中有带有 id 映射的 div:
<div id="map"></div>
以下 js 代码会将 map 添加到您的 div map 。 geoJsonObj 是您的 geojson。
var svg = d3.select("#map").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("g")
.selectAll("path")
.data(geoJsonObj.features)
.enter().append("path")
.attr("d", path);
要查看工作示例,请转到 here .请注意,该示例使用 topojson 作为 .data() 属性的输入。
关于javascript - 使用 Javascript 将 GeoJSON 转换为 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234918/