<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        color:black;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Vorformatiert Zchn";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Sprechblasentext Zchn";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;
        mso-fareast-language:EN-US;}
span.HTMLVorformatiertZchn
        {mso-style-name:"HTML Vorformatiert Zchn";
        mso-style-priority:99;
        mso-style-link:"HTML Vorformatiert";
        font-family:Consolas;
        color:black;
        mso-fareast-language:EN-US;}
span.SprechblasentextZchn
        {mso-style-name:"Sprechblasentext Zchn";
        mso-style-priority:99;
        mso-style-link:Sprechblasentext;
        font-family:"Tahoma","sans-serif";
        color:black;
        mso-fareast-language:EN-US;}
span.E-MailFormatvorlage21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.E-MailFormatvorlage22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.E-MailFormatvorlage23
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.E-MailFormatvorlage24
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.E-MailFormatvorlage25
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.E-MailFormatvorlage26
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.E-MailFormatvorlage27
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=DE-AT link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='color:windowtext'>Hi Alexandre,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:windowtext'>thank you very much for your help. My problem removing the layers was very simple. I marked it with red. When I don’t check if the layer exists, there appear errors (undefined, property or method not supported etc.) I don’t know why.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:windowtext'>This is a part of my code of the Combobox-listeners-select function: (with the combobox the user select a Geoserver (WMSCapabilitiesStore) and the store is added to the LayerTreeBuilder)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:windowtext'>Best regards<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:windowtext'>Lucia<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//remove all layers from the map except of the base layers, but also the markers layer. <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//Markers layer is to be added afterwards in order to keep it topmost<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>for (var i = map.layers.length; i>=0; i--) {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> var layer = map.layers[i];<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> </span><b><span lang=EN-US style='font-family:"Courier New";color:red'>if (layer){</span></b><b><span lang=EN-US style='font-family:"Courier New";color:windowtext'><o:p></o:p></span></b></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> if (!layer.isBaseLayer)</span><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//&&(layer.displayInLayerSwitcher == true)) </span><span lang=EN-US style='font-family:"Courier New";color:windowtext'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> map.removeLayer(layer);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>};<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//the layernodes are removed automatically with the layers, <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//empty group nodes remain, they are to be removed seperately<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//I do not look for empty group nodes in general, but I remove all nodes except of "Base layers" and the node to be added (= tag)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>var childNodes = tree.getRootNode().childNodes;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>for (var i=childNodes.length; i>=0; i--) {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> var child = childNodes[i];<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> if ((child)&&(child.text != "Base layers")&&(child.text != tag)){<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> tree.getRootNode().removeChild(child, true);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>};<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//add layers from selected geoserver (WMSstore is a WMSCapabilitiesStore with url: <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//http://myHost:8080/geoserver/wms?SERVICE=WMS&REQUEST=GetCapabilities&namespace=myWorkspace)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//to do: add polyline and point feature type layers topmost </span><span lang=EN-US style='font-family:"Courier New";color:windowtext'> </span><span lang=EN-US style='font-family:"Courier New";color:#00B050'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>var array = WMSstore.getRange(); <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>for(var i = 0 ; i < array.length ;i++){<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> var record = array[i];<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> var copy = record.copy();<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> copy.data["layer"] = record.getLayer();<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> copy.getLayer().mergeNewParams({<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> format: "image/png",<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> transparent: "true",<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> tiled: "true"<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> });<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> copy.getLayer().visibility = false;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'> // adding only layers with a keyword (=group in LayerTreeBuilder)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'> // e.g. keywords=“Testarea/Subfolder”<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> if(record.get("keywords").length !== 0){<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> var keywords = record.get("keywords")[0];<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> copy.getLayer().options.group = keywords;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> var firstKeyword = keywords.split("/")[0];<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'> //tag = test area to show<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> if (firstKeyword == tag){<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> mapPanel.layers.add(copy); <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:windowtext'>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New";color:#00B050'>//to keep the markers layer topmost<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New";color:windowtext'>map.addLayer(markers);<o:p></o:p></span></p></div></body></html>