<div class="gmail_quote">Yes Spencer,<div><br></div><div>All your controls is part of the main Map Object. </div><div>If you analize that in Firebug you will see this controls, perhaps, at map.controls as an array. Which one of this itens in the array is an Object Control, with a lot of atributes.</div>

<div><br></div><div>What you can do is list through a FOR an check the name, to assign the Control Object to an variable, that you&#39;ll used it in the map.removeControl().</div><div><br></div><div>Let me put a piece of code I have to do something like this:</div>

<div><div>    var drawButton; // I will use this variable to assign my control</div><div>    var mapCnt = map.controls // Just to avoid repetition in the code</div><div>    for (i=0; i&lt;mapCnt.length; i++) { // List all controls there I have</div>

<div>        if (mapCnt[i].displayClass == &#39;olEditorControlDrawPolygon&#39;)  // Check the displayClass there I want.. or other attribute there you recognize.</div><div>             drawButton = mapCnt[i]; // and Assigned the Control Object to my variable...</div>

<div>    } </div></div><div><br></div><div>map.removeControl(drawButton); //using it</div><div><br></div><div>Goog luck,</div><div class="HOEnZb"><div class="h5"><div><img src="http://globalgeo.com.br/assinaturas/fernando.gif"><br>
<br>
<br><br><div class="gmail_quote">2012/3/29 Spencer Renosis <span dir="ltr">&lt;<a href="mailto:renosis@gmail.com" target="_blank">renosis@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Fernando,<div><br></div><div>Thanks for your reply. I am aware of firebug and how to find out which variable I want that way. I am trying to figure out the best way to do this while writing my application. So say I had an option screen I created on the application I am designing, that allows you to turn off certain controls. I could easily add the control, but when I want to remove the control, how do I specify the control I want to remove?</div>


<div><br></div><div>So, user clicks button, button calls map.addControl(new OpenLayers.Control.ScaleLine()); and viola! the user now gets to see the scale line... </div><div><br></div><div>but what happens when the user wants to get rid of the scale line.... he clicks the button to remove it and it calls map.removeControl(????????). </div>


<div><br></div><div>The button obviously wouldn&#39;t know which control I wanted to remove because it could be any index number in the control array....</div><div><br></div><div>This means my only option would be to assign it to some variable outside of any function, making it a global variable. Is this my only option is there some other way to do it?</div>


<div><br></div><div>Thanks,</div><div><br></div><div>Spencer</div><div><div><div><br><div class="gmail_quote">On Thu, Mar 29, 2012 at 1:02 PM, Fernando Norte <span dir="ltr">&lt;<a href="mailto:fernando@globalgeo.com.br" target="_blank">fernando@globalgeo.com.br</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Spencer,<div><br></div><div>As you are a &quot;non programmer&quot; that maybe confused you a little bit. </div><div>


There is two ways to not depend on array index:</div><div>Or you create a global variable, and it&#39;s easy, just declare (var variable_name) outside any function.</div>
<div>Or you can find the specific control you want and put in a variable, global or not. </div><div>As an array, you can check all itens to find which one have the name you want. </div><div>It&#39;s better to find the name you want using Firebug Console. </div>



<div><br></div><div>If you don&#39;t know how to use a Firebug Console, or search an array and compare values, try learn this before start programming. </div><div><br></div><div>Good Luck,</div><div><img><br>

<br>
<br><br><div class="gmail_quote">2012/3/29 Spencer Renosis <span dir="ltr">&lt;<a href="mailto:renosis@gmail.com" target="_blank">renosis@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div>
I am working with the OpenLayers 2.10 Beginner&#39;s Guide by E. Hazzard.<br>
<br>
In chapter 6 he recommends when creating controls, to reference them<br>
by variable. That way when you want to remove a control, you can<br>
specify the variable instead of the array index number, as specifying<br>
the index number can get confusing.<br>
<br>
Quote: &quot;Another downside to using the controls array itself is that<br>
removing a control will affect<br>
the index of all other controls, so there can be a lot of guesswork<br>
involved as to what control<br>
you&#39;re actually removing. So, in short, avoid removing controls this<br>
way if you can.&quot;<br>
<br>
But, when you create a new control and assign it to an easily<br>
referenced variable, the removeControl() method won&#39;t recognize this<br>
variable unless it is a Global Variable. Now, I am not an experienced<br>
programmer by any means, but I am just curious if there is a way to do<br>
this without using a global variable. From what I understand, good<br>
design practice is to use global variable sparingly. Does this not<br>
matter that much? Am I over-thinking it? How would a more experienced<br>
programmer do this?<br>
<br>
Thanks,<br>
</div></div><span><font color="#888888"><span><font color="#888888">--<br>
Spencer Renosis<br></font></span></font></span></blockquote></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></div>