<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content=text/html;charset=iso-8859-1>
<META content="MSHTML 6.00.6002.18332" name=GENERATOR></HEAD>
<BODY id=MailContainerBody
style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-TOP: 15px" leftMargin=0
topMargin=0 CanvasTabStop="true" name="Compose message area">
<DIV><FONT face=Arial size=2>If you want to know if a layer is on the map, then
either check the map:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>By Name -</FONT></DIV>
<DIV><FONT face=Arial
size=2>if(map.findLayersByName(layerName).length){</FONT></DIV>
<DIV><FONT face=Arial size=2> // we found the layer</FONT></DIV>
<DIV><FONT face=Arial size=2>} else {</FONT></DIV>
<DIV><FONT face=Arial size=2> // layer not found</FONT></DIV>
<DIV><FONT face=Arial size=2>}</FONT></DIV>
<DIV><FONT face=Arial size=2>By Layer -</FONT></DIV>
<DIV><FONT face=Arial size=2>if(map.layers.indexOf(layer)>-1){</FONT></DIV>
<DIV><FONT face=Arial size=2> // we found it</FONT></DIV>
<DIV><FONT face=Arial size=2>} else {</FONT></DIV>
<DIV><FONT face=Arial size=2> // layer not in map</FONT></DIV>
<DIV><FONT face=Arial size=2>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>or check the layer store</FONT></DIV>
<DIV><FONT face=Arial size=2>By Name -</FONT></DIV>
<DIV><FONT face=Arial size=2>var index =
mapPanel.layers.findBy(function(rec){</FONT></DIV>
<DIV><FONT face=Arial size=2> return rec.getLayer().name ==
layerName // assumes that layerName has been previously defined</FONT></DIV>
<DIV><FONT face=Arial size=2>})</FONT></DIV>
<DIV><FONT face=Arial size=2>if(index>-1){ //found the layer } else { //no
layer matched }</FONT></DIV>
<DIV><FONT face=Arial size=2>By Layer</FONT></DIV>
<DIV><FONT face=Arial size=2>if(mapPanel.layers.getByLayer(layer)){ //found the
layer } else { //no layer found }</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>If you want to know if a node exists in the tree
with then just cascade down the tree</FONT></DIV>
<DIV><FONT face=Arial size=2>var rootNode =
layerTree.getRootNode();</FONT></DIV>
<DIV><FONT face=Arial size=2>var res = {layerFound:false};</FONT></DIV>
<DIV><FONT face=Arial size=2>// find by layer, useful for gx_layers loaded by a
layerContainer; assume that layer has been previously defined
</FONT></DIV>
<DIV><FONT face=Arial size=2>rootNode.cascade(function(node){</FONT></DIV>
<DIV><FONT face=Arial size=2> if(node.layer && node.layer ==
layer){</FONT></DIV>
<DIV><FONT face=Arial size=2>
this.layerFound = true; </FONT></DIV>
<DIV><FONT face=Arial size=2> return
false;</FONT></DIV>
<DIV style="FONT: 10pt Tahoma">
<DIV><FONT face=Arial> }</FONT></DIV>
<DIV><FONT face=Arial>},res);</FONT></DIV><FONT face=Arial></FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial></FONT> </DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial>//find by text. assume
searchText has already been defined</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT
face=Arial>rootNode.cascade(function(node){</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial> if(node.text
== searchText){</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT
face=Arial> this.layerFound =
true;</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT
face=Arial> return false;</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial>
}</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial>},res);</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial></FONT> </DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial>if(res.layerFound){
//found the node } else { //no matching node found }</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial></FONT> </DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial>Matt Priour</FONT></DIV>
<DIV style="FONT: 10pt Tahoma"><FONT face=Arial>Kestrel Computer
Consulting</FONT></DIV>
<DIV style="FONT: 10pt Tahoma">
<DIV><FONT face=Arial></FONT><FONT face=Arial></FONT><FONT
face=Arial></FONT><BR></DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A
title="mailto:itintern12@gmail.com CTRL + Click to follow link"
href="mailto:itintern12@gmail.com">IT Intern</A> </DIV>
<DIV><B>Sent:</B> Tuesday, January 18, 2011 11:32 AM</DIV>
<DIV><B>To:</B> <A title=robertdbuckley@yahoo.com
href="mailto:robertdbuckley@yahoo.com">Robert Buckley</A> </DIV>
<DIV><B>Cc:</B> <A
title="mailto:users@geoext.org CTRL + Click to follow link"
href="mailto:users@geoext.org">users@geoext.org</A> </DIV>
<DIV><B>Subject:</B> Re: [Users] how to find a layer in
layertree</DIV></DIV></DIV>
<DIV><BR></DIV>hmm this might be a brute-force way of doing this, but I think
writing an event handler for everytime a new layer is added (assuming by button
click) you traverse the entire tree..<BR><BR>for(var c = 0; c <
layerRoot.getOwnerTree().getNodeById(<A
href="http://parent.id">parent.id</A>).childNodes.length;
c++){<BR>
layerRoot.getOwnerTree().getNodeById(<A
href="http://parent.id">parent.id</A>).childNodes[c].eachChild(function(node)
{ <BR>
if (<A
href="http://node.layer.name">node.layer.name</A> ==
map.getLayersByName(layerName)) { <BR>
//then put logic in
here...maybe create a count variable or something
like<BR>
layerExists += 1;<BR>
}//end if <BR> });//end
eachChild<BR> }//end for<BR><BR>Hope this gives you some kind
of lead,<BR><BR>elshae<BR><BR>
<DIV class=gmail_quote>On Tue, Jan 18, 2011 at 12:09 PM, Robert Buckley <SPAN
dir=ltr><<A
href="mailto:robertdbuckley@yahoo.com">robertdbuckley@yahoo.com</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV
style="FONT-SIZE: 8pt; FONT-FAMILY: arial,helvetica,sans-serif">Hi,<BR><BR>I
am trying to write a function which checks to see if a layer is present in the
tree.<BR><BR>if the layer already exists in the tree (or map) is shouldn´t be
loaded...<BR><BR><BR>can anyone help?<BR><BR>
<DIV>var clonename = clone.get("layer").name<BR>
<BR>
if (mapPanel.layers(clonename))
{<BR>
Ext.MessageBox.alert(null, "test");<BR>
}<BR>
else <BR>
{<BR>
mapPanel.layers.add(clone);<BR>
Ext.MessageBox.alert(null,
clonename);<BR>
}<BR><BR>Cheers<BR>Rob<BR></DIV></DIV><BR></DIV><BR>_______________________________________________<BR>Users
mailing list<BR><A href="mailto:Users@geoext.org">Users@geoext.org</A><BR><A
href="http://www.geoext.org/cgi-bin/mailman/listinfo/users"
target=_blank>http://www.geoext.org/cgi-bin/mailman/listinfo/users</A><BR><BR></BLOCKQUOTE></DIV><BR>
<P>
<HR>
<P></P>_______________________________________________<BR>Users mailing
list<BR>Users@geoext.org<BR>http://www.geoext.org/cgi-bin/mailman/listinfo/users<BR></BODY></HTML>