1 /**
  2  * Constructor for googleLayers widget which controls the display options of the plugin.
  3  * @constructor
  4  * @param {GEPlugin} plugin Reference to the google earth plugin instance.
  5  * @param {HTMLFormElement} options The form that controls options. See <a href="http://code.google.com/apis/earth/documentation/reference/interface_g_e_options.html">GEOptions</a>
  6  * @param {HTMLFormElement} layers The form that controls which layers are displayed. See <a href="http://code.google.com/apis/earth/documentation/layers.html#layers">layer reference</a>
  7  */
  8 madrona.map.googleLayers = function(ge, options_form, layers_form){
  9     this.layers = $(layers_form);
 10     this.options = $(options_form);
 11     this.ge = ge;
 12     var self = this;
 13     $(this.layers).find('input').click(function(){
 14         self.updateLayers();
 15     });
 16     
 17     $(this.options).find('input').click(function(){
 18         self.updateOptions();
 19     });
 20     
 21     this.updateLayers();
 22     this.updateOptions();
 23 }
 24 
 25 /**
 26  * Looks at the layers form and updates the map to match form values
 27  */
 28 madrona.map.googleLayers.prototype.updateLayers = function(){
 29     var self = this;
 30     this.layers.find('input').each(function(){
 31         self.ge.getLayerRoot().enableLayerById(self.ge[$(this).attr('name')], $(this).attr('checked'));
 32     });
 33 };
 34 
 35 /**
 36  * Looks at the options form and updates the map to match form values. The 
 37  * name of the input element should match the setXVisibility function on 
 38  * ge.getOptions();.
 39  * for example:
 40  *
 41  *      <input name="setGridVisibility" />
 42  */
 43 madrona.map.googleLayers.prototype.updateOptions = function(){
 44     var self = this;
 45     var options = self.ge.getOptions();
 46     this.options.find('input').each(function(){
 47         var $input = $(this);
 48         var name = $input.attr('name');
 49         if(name != 'nav' && name != 'sun'){
 50             options[name](this.checked);
 51         }
 52     });
 53     
 54     if(this.options.find('input[name="nav"]').length){
 55         if (this.options.find('input[name="nav"]:checked').length) {
 56             self.ge.getNavigationControl().setVisibility(self.ge.VISIBILITY_SHOW);
 57         }else{
 58             self.ge.getNavigationControl().setVisibility(self.ge.VISIBILITY_HIDE);
 59         }
 60     }
 61     
 62     if(this.options.find('input[name="sun"]').length){
 63         if(this.options.find('input[name="sun"]:checked').length){
 64             self.ge.getSun().setVisibility(true);
 65         }else{
 66             self.ge.getSun().setVisibility(false);
 67         }
 68     }
 69 };
 70 
 71 /**
 72  * Unbinds all event listeners.
 73  */ 
 74 madrona.map.googleLayers.prototype.destroy = function(){
 75     $(this.layers).find('input').unbind('click');
 76     $(this.options).find('input').unbind('click');
 77 }