让我们做一个地图 Topojson 没有出现 - 没有错误消息,但什么也没发生
Let's make a map Topojson doesn't appear - no error msgs but nothing happens
我想用D3绘制巴西(州界)的地图,但我失败了。地图是Topojson格式(它在这里),我正在遵循Mike Bostock的教程。我可以在绘制英国时准确地复制教程结果(地图在这里),但是当我尝试绘制巴西时没有任何反应 - JavaScript 控制台中没有错误消息。
这是我的代码:
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 1160;
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(1200 * 5)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
/*
PLOTTING THE UK WORKS
d3.json("uk.json", function(error, uk) {
console.log(uk)
svg.append("path")
.datum(topojson.feature(uk, uk.objects.subunits))
.attr("d", path);
});
*/
/* PLOTTING BRAZIL DOESN'T WORK */
d3.json("br-states.json", function(error, uf) {
console.log(uf)
svg.append("path")
.datum(topojson.feature(uf, uf.objects.states))
.attr("d", path);
});
</script>
</body>
必须根据需要更改以下内容。
// England viewport
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(1200 * 5)
.translate([width / 2, height / 2]);
目前正在放大英格兰地区:)
这样的东西:
// somewhere in South america
var projection = d3.geo.mercator() // albers may fails for Brazil
.center([-40, -30]) // country center
.rotate([4.4, 0]) //???? Check the api and edit for Brazil
.parallels([0, -60]) // ???
.scale(400) // smaller num = smaller Earth
.translate([width / 2, height / 2]); // topojson data is initially centered aroun x:0,y:0. This put back into the viewbox
相关文章:
- 回复'js'仅当请求有错误时(否则使用html)
- 表单已发送,但验证有错误
- 如果文件不存在,fs.watch是否有错误处理程序
- 为什么此EventSource重复触发消息和错误
- 云代码(javascript)失败,原因是:{代码:1,消息:内部错误
- Meteor上有错误的同步问题
- 表单验证:如果有错误,不要't使手风琴动起来
- 如何发送控制台消息和错误以提醒
- 淘汰抛出消息:类型错误:
不是一个函数.什么意思 - 我有错误文档.注册元素未被细化
- 如何转换为特定于 json 的类 c#?我有错误
- 如果当前输入有错误或警告,则禁用所有下一个表单输入字段
- 通过有错误的 Ajax-Request 打印出 HTML 会阻止进一步的 JS 工作
- 脸书应用程序有错误
- XDomainRequest 总是有错误
- HTML5 Canvas游戏有错误,点击时第一个拼图块会变成不同的块
- 有消息频道和没有消息频道的网络消息有什么区别
- Cordova sendJavascript 不适用于 android 进程消息失败:错误:未定义:10
- Page_ClientValidate返回 false,但没有一个验证器有错误
- 有没有一种方法可以在加载页面后检查iframe是否有错误消息