I have multiple OpenLayers maps, each map gets a subset of controls that I use across all maps. In the past I have added controls in the traditional way, for each control.
var control = new OpenLayers.Control.xxx({ options: whatever });
MAP.addControl(control);
I am considering defining an object that would contain most/all of the controls that I might use. That object would be is a .js file would be loaded into each web page. I would then add the controls I need for that page.
the control object, that is in the control.js file
var MY_controls = {
scale: new OpenLayers.Control.Scale(),
mousePosition :new OpenLayers.Control.MousePosition({numDigits:6}),
panZoomBar: new OpenLayers.Control.PanZoomBar(),
ctrl_zoomin: new OpenLayers.Control.ZoomBox({ disable:true }),
ctrl_zoomout: new OpenLayers.Control.ZoomBox({out:true,disable:true})
};
then on each page I would do something like this
array = ['scale','mousePosition','panZoomBar'];
for ( var x=0; x < array.length; ++x ) {
MAP.addControl(MY_controls[array[x]]);
};
Is this good code?