2016-11-15 34 views
0

我創建了一個要在地圖上顯示的運算符列表來映射其管道。我想只能隱藏所有未從列表中檢查過的管道。所以如果一個操作符被選中,那麼在地圖上只顯示一個操作符管道。現在它隱藏了一切,因爲selectAll,但我已經嘗試了一些其他選項,似乎沒有任何工作。它要麼全部隱藏,要麼全部隱藏。
JS:需要隱藏svg的所有元素(從列表中選擇的元素除外)javascript

if($("#pipeExclusion").val() == 1){ 
     map.svg.selectAll(".pipe").style("visibility", "hidden"); 
    } else if($("#pipeExclusion").val() == 0){ 
     map.svg.selectAll(".pipe").style("visibility", "visible"); 
    } 

這裏就是我拉在所有的管道

 if(map.filters.showPipes){ 
     map.svg.selectAll(".pipe") 
      .data(topojson.feature(pipeData, pipeData.objects.ngpipes).features).enter().append("path") 
      .attr("class", function(d){return "pipe test p" + pipeOperators.indexOf(d.properties.name);}) 
      .attr("d", map.svgPath); //map.svgPath 
     } 

     for(i=0;i<pipeOperators.length;i++){ 
     if(map.filters.showPipes == 1){ 
      $("#pipeOperatorsList").append("<li><input type='checkbox' class='pipeOperator' value=p" + pipeOperators.indexOf(pipeOperators[i]) + "> " + pipeOperators[i] + "</li>"); 
      } 
     } 

我想一個& &添加進前如果檢查類的地位是運營商在列表中,但它不起作用,因爲當我這樣做時它不會隱藏任何東西。有小費嗎?

+0

哪裏是你的運營商名單?我可以看到html嗎? (*提示:*爲什麼不添加類來指定哪些[隱藏/顯示]?) –

+0

@Jefrén。我編輯了我的問題,並添加了如何將操作員拉入其中。他們都具有相同的類名,但在地圖上,每個管道都有自己的類名,例如p0,p1,p2等等。我只是不確定如何讓它看到是否有一個操作符被選中,然後隱藏除了被選中的所有其他流水線。 – lostInTheTetons

+0

謝謝。我能否假設運營商永遠不會默認被檢查? –

回答

1

這裏是我的回答..必須創建一個新的點擊功能

 $(".pipeOperator").click(function(){ 
     if(this.checked == true){ 
      console.log("." + this.value); 
      //$("." + this.value).style("visibility", "visible"); 
      map.svg.selectAll("." + this.value).style("visibility", "visible"); 
     } 
     if(this.checked == false){ 
      console.log("." + this.value); 
      //$("." + this.value).style("visibility", "hidden"); 
      map.svg.selectAll("." + this.value).style("visibility", "hidden"); 
     } 
    });