0
我代表印度的每个状态下GeoJSON的文件,作为一个简单的例子,一个声明看起来像这样(与简洁,删除坐标):D3如何从GeoJSON的添加ID到路径
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": {}, "id":"AndhraPradesh", "geometry": { "type": "MultiPolygon", "coordinates": [ ......
我试图让生成的SVG的路径有其GeoJSON的形状的ID,这样我就碰到这样的:
<svg width="600" height="600"><g id="india"><path id="AndhraPradesh" d="..."></path>
像下面并在其上的变化似乎并不工作,我找不到明确将路径与id关联的示例,所以我不确定wh在秘密可能是。
var w = 600;
var h = 600;
var proj = d3.geo.mercator();
var path = d3.geo.path().projection(proj);
var t = proj.translate(); // the projection's default translation
var s = proj.scale() // the projection's default scale
var map = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h)
.call(initialize);
var india = map.append("g")
.attr("id", "india");
d3.json("india_states.geojson", function (json) {
india.selectAll("path")
.data(json.features)
.enter().append("path")
.attr("d", path)
.attr("id", id)
});
任何帮助非常感谢。
谢谢,这是更干净。我刚刚发现'console.log(india [0] [0] .children [i] .__ data __。id)'也允许我访问它,但这样更好。 –