我的地图图层中有一个图例。它为动态添加的每一层添加了一个颜色图例。
我的问题:当我要求将图层隐藏在图层切换器中(我不想在那里看到它)时,即使图层可见,它也不再向我显示图例。
有没有一种方法可以在显示我的图例的同时将其排除在 layerSwitcher 之外?我想绕过 libray 给我带来的问题。如果有一种方法可以在不使用 DisplayInLayerSwitcher: false 的情况下从 OpenLayers 的 LayerSwitcher 中隐藏图层,它会解决我的问题!!!
这是我传奇的代码:
//------ Legend Window ---------------------------------------------------------------------------
/* --> LegendPanel (This GeoExt Panel automatically displays the legend image of the layer if the layer has been added to the map.
* If this paticular layer has been removed from the map, his legend image will also automatically be removed from the GeoExt Panel.)
*/
function createLegendPanel(){
return new Ext.Window({
id: 'legend_panel_extjs',
header: true,
title: '<center>' + extjs_gui_east_panel_title + '</center>',
shadow: false,
closable:false,
collapsible: true,
animCollapse: false,
cls: 'WindowPanelCls',
resizable: false,
//resizeHandles: 'w',
draggable: false,
width:(legendMaxWidth+17),
height:(legendMaxHeight+15),
plain: true,
listeners: {
show: windowPosition,
collapse: windowPosition
},
items: [
new GeoExt.LegendPanel({
id:'extjs_gui_legend_panel_list',
map: map,
region:'west',
layout: 'table',
filter: function(record){
if( !(record.getLayer().isBaseLayer) && !(record.getLayer() instanceof OpenLayers.Layer.Vector) ){
return true;
}
},
defaults: {
showTitle: false,
baseParams: {
format: 'image/png',
lang: lang
}
,style: '{border-style: ridge;}'
}
})
]
});
}
谢谢大家。
PS:来自 GeoExt 网站: LegendPanel 将在其配置的 layerStore 中包含所有图层的图例,除非图层配置为 displayInLayerSwitcher: false,或者图层记录具有值为 true 的 hideInLegend 字段。可以通过在 LegendPanel 上配置过滤器来完成额外的过滤。