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