我试图根据属性过滤矢量图层功能。 我有4个复选框:type_1,type_2,shape_1和shape_2 请注意,我正在使用Extjs接口。Openlayers - 矢量图层 - 使用样式属性组合隐藏/显示功能
在开始的时候我可以过滤类型的属性设置样式为“none”或“” ......像这样:以上所有
switch (f) {
case 'type_1':
if(checked)
filter('show_type_1');
else filter ('hide_type_1);
case 'type_2':
if(checked)
filter('show_type_2');
else filter ('hide_type_2);
}
function filter(value)
{
switch (value){
case 'hide_type_1':
for (i=0;i<=features.length;i++)
if(features[i].attributes.type == 'first')
features[i].style = 'none';
layer.redraw();
case 'show_type_1':
for (i=0;i<=features.length;i++)
if(features[i].attributes.type == 'first')
features[i].style = '';
layer.redraw();
case 'hide_type_2':
for (i=0;i<=features.length;i++)
if(features[i].attributes.type == 'second')
features[i].style = 'none';
layer.redraw();
case 'show_type_2':
for (i=0;i<=features.length;i++)
if(features[i].attributes.type == 'second')
features[i].style = '';
layer.redraw();
}
}
的伟大工程,如果我取消TYPE_1,所有TYPE_1功能将diappear。 然后,如果我取消选中type_2,则所有type_2功能都会显示出来。 然后如果我再次检查type_1,则会显示所有type_1功能,并且type_2功能将保持隐藏状态。
问题是,当我试图做与形状属性是相同的,通过添加:
case 'shape_1':
if(checked)
filter('show_shape_1');
else filter ('hide_shape_1);
到所述第一功能。
和:
case 'hide_shape_1':
for (i=0;i<=features.length;i++)
if(features[i].attributes.shape == 'first')
features[i].style = 'none';
layer.redraw();
case 'show_shape_1':
for (i=0;i<=features.length;i++)
if(features[i].attributes.shape == 'first')
features[i].style = '';
layer.redraw();
到第二个。
它可以在取消选中shape_1复选框时起作用。所有shape_1功能都隐藏起来。但是如果选中它来显示它们,所有功能都会显示,即使是type_1和type_2,我也不会将它们保持为未选中状态并隐藏!
我不明白为什么发生这种情况。因为如果我处理一个属性(在我的情况下输入),它工作正常,但尝试将类型过滤与另一个要素属性(形状)结合时失败。
我希望我的解释清楚。
这样一个好主意!非常感谢 – Noon