1 if(typeof(GMap2) != "undefined") {
  2 
  3     /**
  4      * Converts an xml Dom to a Dictionary.  Used during 'map.load'
  5      * @param {XML Dom} jqDom
  6      * @returns key-value pair dictionary
  7      * @type {Associative Array}
  8      * @throws jqDom is not an xml dom
  9      */
 10     Dmp.Layer.WMSLayer.domToDict = function(jqDom){
 11     
 12     
 13         if(!jqDom || !(typeof(jqDom.attr) == "function" || typeof(jqDom.getAttribute) != "undefined")) { //create via xml
 14             throw new Error("jqDom must be an xml dom object");
 15         }
 16         
 17 	    
 18         var params = new Object();
 19         var parsedText = "";
 20 	    
 21         parsedText = Dmp.Util.nodeVal($(jqDom), "Connection");
 22 	    if(parsedText && !isNaN(parsedText)) {
 23 		    params["connectionId"] = parsedText;
 24 	    }
 25 	    
 26         parsedText = Dmp.Util.nodeVal($(jqDom), "Opacity");
 27 	    if(parsedText && !isNaN(parsedText)) {
 28 		    params["opacity"] = parseFloat(parsedText);
 29 	    }
 30 		
 31 	    parsedText = Dmp.Util.nodeVal($(jqDom), "Visibility");
 32 	    if(parsedText && typeof(parsedText) == "string") {
 33 		    params["visibility"] = (parsedText.toLowerCase() == "true");
 34 	    }
 35 		
 36 	    parsedText = Dmp.Util.nodeVal($(jqDom), "UseHotspot");
 37 	    if(parsedText && typeof(parsedText) == "string") {
 38 		    params["useHotspot"] = parsedText;
 39 	    }
 40 		
 41 	    parsedText = Dmp.Util.nodeVal($(jqDom), "GroupName");
 42 	    if(parsedText && typeof(parsedText) == "string") {
 43 		    params["groupName"] = parsedText;
 44 	    }
 45 		
 46 	    parsedText = Dmp.Util.nodeVal($(jqDom), "GroupType");
 47 	    if(parsedText && typeof(parsedText) == "string") {
 48 		    params["groupType"] = parsedText;
 49 	    }
 50 		
 51 	    parsedText = Dmp.Util.nodeVal($(jqDom), "Source");
 52 	    if(parsedText && typeof(parsedText) == "string") {
 53 		    params["sourceUrl"] = parsedText;
 54 	    }
 55 		
 56 		return params;
 57 	    
 58     
 59     } //domToDict
 60 
 61     /**
 62      * Load a map composition (layer list) file onto the map
 63      * @params {String} xml
 64      * @throws xml is not a string
 65      */
 66     GMap2.prototype.load = function(xml) {
 67 
 68         var _self = this;
 69         var jqDom = xml;
 70         
 71         if(typeof(xml) == "string") {
 72             jqDom = Dmp.Util.parseXml(xml);
 73         } else {
 74             throw new Error("xml must be a string");
 75         }
 76         
 77         jqDom.find("Layer").each(function(i, element) {
 78         
 79             //dynamically create class.
 80             //ex: window['Dmp']['Layer']['WMSLayer'](...);
 81             var arr = ($(element).attr('Class')).split(".");
 82             var tempWindow = window;
 83             for(var i = 0; i < arr.length - 1; i++) {
 84                 tempWindow = tempWindow[arr[i]];
 85             }
 86             
 87             //TODO: connectionId will be stored in 'element'
 88             
 89             var layer = new tempWindow[arr[arr.length-1]]("Layer_" + Dmp.Util.getGuid(), 'SS', $(element));
 90             _self.addOverlay(layer);
 91         
 92         });
 93 
 94         //TODO: properly set view
 95         var parsedText = null;
 96         parsedText = Dmp.Util.nodeVal(jqDom, "MapView");
 97 	    if(parsedText && typeof(parsedText) == "string") {
 98 		    _self.MapView = parsedText;
 99 	    }
100     } //end load
101 
102 
103     /**
104      * Save a map composition (layer list) file of the map
105      * @returns a serialized xml-formed string
106      * @type {String}
107      */
108     GMap2.prototype.save = function() {
109         
110         var _self = this;
111         var xml = "<Layers>";
112 
113         
114         function addNode(obj, name, str ){
115             if(obj[name]) {
116                 node += "<" + name + ">" + obj[name] + "</" + name + ">";
117             }
118         }
119 
120         //... save map View
121 
122         //LAYERS
123         for(var i in _self.DMPLayers) {
124             var layer = _self.DMPLayers[i];
125             xml += "<Layer";
126 
127             
128             if (layer["sourceUrl"]) { //attr
129                 xml += " Source=" + layer["sourceUrl"];
130             }
131             if (layer["groupName"]) { //attr
132                 xml += " GroupName=" + layer["groupName"];
133             }
134             if (layer["groupType"]) { //attr
135                 xml += " GroupType=" + layer["groupType"];
136             }
137             xml += ">"; //close 'Layer' tag
138             
139             if (layer["opacity"]) {
140                 xml += "<Opacity>" + layer["opacity"] + "</Opacity>";
141             }
142             if (typeof(layer["visibility"]) != "undefined") {
143                 xml += "<Visibility>" + layer["visibility"] + "</Visibility>";
144             }
145             
146             //TODO: hotspots are going to be on the ResourceReference, not the MapLayer
147             if (layer["useHotSpot"]) {
148                 xml += "<UseHotSpot>" + layer["useHotSpot"] + "</UseHotSpot>";
149             }
150             
151             var hasResourceReferences = false;
152             for(var j in layer._resourceReferences) { //does not check prototypes or constructors
153                 hasResourceReferences = true;
154                 break;
155             }
156             
157             //LAYER RESOURCES
158             if(hasResourceReferences) {
159                 xml += "<ResourceReferences>";
160                 //RESOURCES
161                 for(var j in layer._resourceReferences) {
162                     var res = layer._resourceReferences[j];
163                     xml += "<Resource";
164                     if (res["dataResourceName"]) { //attr
165                         xml += " DataResourceName='" + res["dataResourceName"] + "'";
166                     }
167                     if (res["resourceName"]) { //attr
168                         xml += " Name='" + res["resourceName"] + "'";
169                     }
170                     xml += ">";
171                     
172                     if (res["title"]) {
173                         xml += "<Title>" + res["title"] + "</Title>";
174                     }
175                     if (res["abstract"]) {
176                         xml += "<Abstract>" + res["abstract"] + "</Abstract>";
177                     }
178                     if (res["attribution"]) {
179                         xml += "<Attribution>" + res["attribution"] + "</Attribution>";
180                     }
181                     if (typeof(res["visibilityPref"]) != "undefined") {
182                         xml += "<VisibilityPreference" 
183                         
184                         if (res["visibilityTrueCondition"]) {
185                            xml += " VisibilityTrueCond='" + res["visibilityTrueCondition"] + "'";
186                         }
187                         if (res["visibilityFalseCondition"]) {
188                             xml += " VisibilityFalseCond='" + res["visibilityFalseCondition"] + "'";
189                         }
190                         
191                         xml += ">" + res["visibilityPref"] + "</VisibilityPreference>";
192                     }
193 
194                     if (res["attributeLinks"]) {
195                         xml += "<AttributeLinks>" + res["attributeLinks"] + "</AttributeLinks>";
196                     }
197                     if (res["bounds"]) {
198                         xml += "<Bounds>" + res["bounds"] + "</Bounds>";
199                     }
200                     if (res["filter"]) {
201                         xml += "<Filter>" + res["filter"] + "</Filter>";
202                     }
203                     if (res["identifiablePref"]) {
204                         xml += "<IdentifiablePref>" + res["identifiablePref"] + "</IdentifiablePref>";
205                     }
206                     if (res["time"]) {
207                         xml += "<ViewInTime>" + res["time"] + "</ViewInTime>";
208                     }
209                     if (res["zoomRange"] && res["zoomRange"]["max"] && res["zoomRange"]["min"]) {
210                         xml += "<ZoomInLimit>" + Dmp.Util.zoomLevelToScale(res["zoomRange"]["max"]) + "</ZoomInLimit>";
211                         xml += "<ZoomOutLimit>" + Dmp.Util.zoomLevelToScale(res["zoomRange"]["min"]) + "</ZoomOutLimit>";
212                     }
213                     if (res["style"] && res["style"].toXml) {
214                         xml += res["style"].toXml();
215                     }       
216                     for(var k in res.conditionStyles) {
217                         var styleString = res.conditionStyles[k].style.toXml();
218                         styleString = styleString.substring(0, styleString.indexOf(">")) + 
219                             " Condition='" + res.conditionStyles[k].condition + "'" + 
220                             styleString.substring(styleString.indexOf(">"));
221                         xml += styleString;
222                     }
223                 
224                 
225                     xml += "</Resource>";
226                 } //end Resources
227                 
228                 xml += "</ResourceReferences>";
229             } //end ResourceReferences
230             
231             xml += "</Layer>";
232         } //end Layer
233 
234 
235         xml += "</Layers>";
236         return xml;
237         
238     }//end save
239 
240 } //end if