[英]Need to hide all elements of an svg except for the ones selected from a list javascript
我创建了一个操作员列表,以显示在地图上以映射其管线。 我希望只能隐藏列表中尚未检查的所有管道。 因此,如果选中了一个运算符,则仅在地图上显示该运算符的管线。 现在,由于selectAll,它隐藏了所有内容,但是我尝试了其他一些选项,但似乎没有任何效果。 它要么全部隐藏,要么全部隐藏。
JS:
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>");
}
}
我尝试在顶部添加&&,以检查列表中运算符的类的状态,但是它不起作用,因为这样做时它不会隐藏任何内容。 有小费吗?
这是我的答案..不得不创建一个新的点击功能
$(".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");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.