【发布时间】:2016-04-06 14:43:03
【问题描述】:
我一直在研究 d3 JavaScript 库,我试图想出一个可以在我的 html 上的 svg 标签上呈现的地图。这是我目前所拥有的:
<!DOCTYPE html>
<html>
<head>
<title>D3 Map</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/vendor/jquery.min.js"></script>
<script src="js/d3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js"></script>
</head>
<body>
<svg width="1000" height="1300">
</svg>
<script>
var width = 960,
height = 500;
var projection = d3.geo.mercator()
.center([0, 5 ])
.scale(900)
.rotate([-180,0]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var path = d3.geo.path()
.projection(projection);
var g = svg.append("g");
// load and display the World
d3.json("kenya.geojson", function(error, data) {
g.selectAll("path")
.data(topojson.object(topology, topology.objects.countries)
.geometries)
.enter()
.append("path")
.attr("d", path)
});
</script>
</body>
</html>
我的 web 检查器只得到一个空白页面,告诉我 Uncaught ReferenceError: topology is not defined 现在这里是我需要澄清的地方: 我是否使用了正确的数据文件(json 数据文件)来为我提供特定国家的图纸?或者到目前为止我的代码中缺少什么? 同样关于异常,鉴于我正在使用 Python HTTP 服务器工作,可能会捕获什么异常?欢迎任何反馈
【问题讨论】:
标签: javascript d3.js svg geojson topojson