【发布时间】:2018-05-29 00:20:01
【问题描述】:
我想在我使用图像的地图上绘制名为 tree.csv 的 csv 文件中的经度和纬度的地图。 我的 csv 文件包含很多行,所以我将在这里放一些行
经纬度
37.7295482207565 122.392689419827
37.8030467266869 122.425063628702 …… 这是我的代码
d3.csv("/trees.csv", function(data) {
dataset=data.map(function(d) { return [+d["Longitude"],+d["Latitude"] ];});
console.log(data)
var width = 750,
height = width;
// Set up projection that map is using
var projection = d3.geo.mercator()
.center([-122.433701, 37.767683])
.scale(225000)
.translate([width / 2, height / 2]);
var path=d3.geo.path().projection(projection);
var svgContainer=d3.select("body").append("svg")
.attr("width",width)
.attr("height",height);
svgContainer.append("image")
.attr("width", width)
.attr("height", height)
.attr("xlink:href", "/Ilu.svg");
var trees=svgContainer.selectAll("circles")
.data(data).enter()
.append("circles")
var treesAttributes=trees
.attr("cx",function(d) { return projection(d["Longitude"])[0];})
.attr("cy",function(d) { return projection(d["Latitude"])[1];})
.attr("r","100px")
.style("fill","red");
我可以看到我的地图,但在我的地图上看不到任何点。当我检查网络时。我看到 cx 是南数,而 cy 是同一个数。我想也许我的数组还没有被读取。但我不确定这些问题。我被卡住了。你们能解决我的问题吗?谢谢
【问题讨论】:
-
可能删除子集
[0]和[1]? -
@RyanMorton 感谢您的回答。协调器 cx 和 cy 与现在图中的数字不同,但它们与其他线路的数字仍然相同,并且地图上仍然没有点
-
忽略前面的评论。数据是什么样的?您将 lat 或 long 发送到投影函数似乎很奇怪。两个坐标不应该一起去投影以正确评估 cx 和 cy 吗?
标签: javascript csv d3.js plot