[OpenLayers-Users] referencing controls by name

Graham Davis gdavis at refractions.net
Thu Feb 8 19:11:11 EST 2007


I had a similar problem and needed to access specific controls (I 
couldn't gurantee to know what order they were in the map controls 
array).  I achieved this by creating the controls and assigning them to 
global JS variables.  Something like this:

// global vars
var layer_control;

function init() {
  
  <do map creation and init here>
 
  // add controls
  layer_control = new OpenLayers.Control.LayerSwitcher();
  map.addControl(layer_control);
  ...
}

Then anywhere in your JS code you can call layer_control as your control 
object.

Graham.

Roger Kunkel wrote:

> Hi folks,
>
> I'm creating some custom controls and I want to have communication 
> between these controls.
> I know that map.controls is an array of controls, but how do I 
> reference a particular one by name or type?
>
> Thanks 
>
>
> Roger Kunkel
> CERES Program
> Dept. of Land AIr & Water Resources
> UC Davis
> rakunkel at ucdavis.edu <mailto:rakunkel at ucdavis.edu>
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Users mailing list
>Users at openlayers.org
>http://openlayers.org/mailman/listinfo/users
>  
>


-- 
Graham Davis
Refractions Research Inc.
gdavis at refractions.net




More information about the Users mailing list