Pregunta

Tengo un topojson que contiene los caminos del estado.Quiero que el usuario pueda flotar sobre un estado y el estado de aparecer en una SVG diferente.Hasta ahora, he intentado extraer la geometría fuera del Topojson (D.Geometry, D.Geometry.Coordinados, etc.) Pero no puedo hacerlo. Tal vez necesito sacar un polígono de eso, pero algunos estados son de tipo "polígono" y algunos de ellos son de tipo "multipolgyon".

¿Alguna idea / sugerencia?

Editar: Aquí está mi código

var svg = d3.select("#india-map")
.append("svg")
.attr("width",width).attr("preserveAspectRatio", "xMidYMid")
.attr("viewBox", "0 0 " + width + " " + height)
.attr("height", height)

var stateSvg = d3.select("#state-map")
.append("svg")
.append("g")
.attr("height", height)
.attr("width", width);


var g = svg.append("g");

var projection = d3.geo.mercator()
  .center([86, 27])
  .scale(1200);

var path = d3.geo.path().projection(projection);

var pc_geojson = topojson.feature(pc, pc.objects.india_pc_2014);
var st_geojson = topojson.feature(state_json, state_json.objects.india_state_2014);

g.selectAll(".pc")
    .data(pc_geojson.features)
    .enter().append("path")
    .attr("class", "pc")
    .attr("d", path)
    .attr("id", function(d){ return d.properties.Constituency;})
    .attr("fill", "orange")
    .on("click", function(d){
        drawCons(d);
    });

function drawCons(d){
 stateSvg.selectAll(".pc2")
   .data(d)
   .enter().append("path")
   .attr("class","pc2")
   .attr("d", path)
}

¿Fue útil?

Solución

.data() espera recibir una matriz de objetos que deben coincidir con la selección.Estás pasando un solo objeto, por lo que no funciona.Puede usar .datum(d) o .data([d]) para que funcione.

Demo rápido y sucio aquí .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top