D3.js 如何将lat、lon数据动态放置到topoJSON地图上
我有WV县的地形图。它正确地显示了人口密度。此地图是从geoJSON数据创建的,然后使用topojson进行转换。这是开发人员创建数据静态显示所采取的所有正常步骤。我现在的问题是,这个地图的用户想要在上面放置数据,而他们只有lat和lon值。如何在先前创建的topoJSON地图上显示lat、lon数据 以下是一些示例数据:D3.js 如何将lat、lon数据动态放置到topoJSON地图上,d3.js,D3.js,我有WV县的地形图。它正确地显示了人口密度。此地图是从geoJSON数据创建的,然后使用topojson进行转换。这是开发人员创建数据静态显示所采取的所有正常步骤。我现在的问题是,这个地图的用户想要在上面放置数据,而他们只有lat和lon值。如何在先前创建的topoJSON地图上显示lat、lon数据 以下是一些示例数据: var sampleData = [ {"name": "Weirton", "coordinates": [-80.589517, 40.418957]},
var sampleData = [
{"name": "Weirton", "coordinates": [-80.589517, 40.418957]},
{"name": "Morgantown", "coordinates": [-79.955897, 39.629526]},
{"name": "Shepherdstown", "coordinates": [-77.804161, 39.430100]}
];
我已尝试在我的(已显示的)地图上显示,如下所示:
var group = svg.append('g');
group.selectAll("cities")
.data(sampleData)
.enter()
.append("cities")
.attr("class", "cities")
.attr("transform", function(d) {return "translate(" + projection(d.coordinates) + ")";});
有可能在静态地图上获得一些纬度和经度数据,或者我犯了一些编程错误吗
更新:我处理了数据,发现使用以下代码:
svg.append("path")
.datum(topojson.feature(wv, dynamicData))
.attr("d", path)
.attr("class", "place")
使用此数据
var dynamicData =
{
"type":"GeometryCollection",
"geometries":[
{"type":"Point","properties":{"NAME":"Weirton"},"id":"Weirton","coordinates":[4172,9359]},
{"type":"Point","properties":{"NAME":"Morgantown"},"id":"Morgantown","coordinates":[5458,7063]},
{"type":"Point","properties":{"NAME":"Shepherdstown"},"id":"Shepherdstown","coordinates":[9826,6483]}]
};
var dynamicData =
{
"type":"GeometryCollection",
"geometries":[
{"type":"Point","properties":{"NAME":"Weirton"},"id":"Weirton","coordinates":[-80.589517, 40.418957]},
{"type":"Point","properties":{"NAME":"Morgantown"},"id":"Morgantown","coordinates":[-79.955897, 39.629526]},
{"type":"Point","properties":{"NAME":"Shepherdstown"},"id":"Shepherdstown","coordinates":[-77.804161, 39.430100]}]
};
但不适用于此数据
var dynamicData =
{
"type":"GeometryCollection",
"geometries":[
{"type":"Point","properties":{"NAME":"Weirton"},"id":"Weirton","coordinates":[4172,9359]},
{"type":"Point","properties":{"NAME":"Morgantown"},"id":"Morgantown","coordinates":[5458,7063]},
{"type":"Point","properties":{"NAME":"Shepherdstown"},"id":"Shepherdstown","coordinates":[9826,6483]}]
};
var dynamicData =
{
"type":"GeometryCollection",
"geometries":[
{"type":"Point","properties":{"NAME":"Weirton"},"id":"Weirton","coordinates":[-80.589517, 40.418957]},
{"type":"Point","properties":{"NAME":"Morgantown"},"id":"Morgantown","coordinates":[-79.955897, 39.629526]},
{"type":"Point","properties":{"NAME":"Shepherdstown"},"id":"Shepherdstown","coordinates":[-77.804161, 39.430100]}]
};
有人能告诉我如何计算新的坐标吗 好的,这段代码将正确显示我的lat/lon数据
svg.selectAll(".geojson").data([sampleData4])
.enter()
.append("path")
.attr("class","geojson")
.attr("d", path)
;
(sampleData4是我在上面的编辑中使用的lat/lon数据(即dynamicATA)。在多次谷歌搜索后,我偶然发现了这一点。我在
http://hashbang.co.nz/blog/2013/2/25/d3_js_geo_fun
我将非常感谢任何人解释为什么它有效,以及为什么我以前的所有工作都无效。我仍然非常有兴趣理解(有一个详细的具体例子)你能创建一个JSFIDLE或Plunkr之类的东西,这样我们就可以确切地看到你在做什么吗?好吧,我的问题是我不能在JSFIDLE上获取我的topoJSON文件。至少我不知道如何做。如果我通过topoJSON运行我的原始lat/lon数据并查看输出,我会得到{“name”:“Weirton”,“坐标”:[41729359]}。topojson是如何计算这些值的?如果我可以对我的动态数据进行相同的计算,我可能可以继续。这些只是不同投影中的坐标。如果您正确设置投影,您可以完全独立地投影用户提供给您的坐标。嗨,我也有同样的问题,但是nk不起作用了。你对如何解决这个问题有什么建议吗?