[OpenLayers-Users] How to handle controls

Spencer Renosis renosis at gmail.com
Thu Mar 29 12:05:15 EDT 2012


I am working with the OpenLayers 2.10 Beginner's Guide by E. Hazzard.

In chapter 6 he recommends when creating controls, to reference them
by variable. That way when you want to remove a control, you can
specify the variable instead of the array index number, as specifying
the index number can get confusing.

Quote: "Another downside to using the controls array itself is that
removing a control will affect
the index of all other controls, so there can be a lot of guesswork
involved as to what control
you're actually removing. So, in short, avoid removing controls this
way if you can."

But, when you create a new control and assign it to an easily
referenced variable, the removeControl() method won't recognize this
variable unless it is a Global Variable. Now, I am not an experienced
programmer by any means, but I am just curious if there is a way to do
this without using a global variable. From what I understand, good
design practice is to use global variable sparingly. Does this not
matter that much? Am I over-thinking it? How would a more experienced
programmer do this?

Thanks,
-- 
Spencer Renosis


More information about the Users mailing list