OpenLayers OpenLayers

Changeset 5920

Show
Ignore:
Timestamp:
01/28/08 13:21:59 (1 year ago)
Author:
tschaub
Message:

merge r5904:HEAD from trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/geoview/doc/authors.txt

    r5904 r5920  
    1414Eric Lemoine 
    1515Philip Lindsay 
     16Martijn van Oosterhout 
    1617Corey Puffault 
    1718Gregers Rygg 
  • sandbox/tschaub/geoview/examples/panel.html

    r5362 r5920  
    7070             
    7171             
    72             zb = new OpenLayers.Control.ZoomBox(); 
     72            zb = new OpenLayers.Control.ZoomBox( 
     73                {title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging."}); 
    7374            var panel = new OpenLayers.Control.Panel({defaultControl: zb}); 
    7475            panel.addControls([ 
    75                 new OpenLayers.Control.MouseDefaults(), 
     76                new OpenLayers.Control.MouseDefaults( 
     77                    {title:'You can use the default mouse configuration'}),  
    7678                zb, 
    77                 new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Path), 
    78                 new OpenLayers.Control.ZoomToMaxExtent() 
     79                new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Path, 
     80                    {title:'Draw a feature'}), 
     81                new OpenLayers.Control.ZoomToMaxExtent({title:"Zoom to the max extent"})  
    7982            ]); 
    8083            map.addControl(panel); 
  • sandbox/tschaub/geoview/lib/OpenLayers/Control.js

    r5904 r5920  
    8585     */ 
    8686    displayClass: "", 
     87     
     88    /** 
     89    * Property: title   
     90    * {string}  This property is used for showing a tooltip over the   
     91    * Control.   
     92    */  
     93    title: "", 
    8794 
    8895    /**  
     
    173180            this.div = OpenLayers.Util.createDiv(this.id); 
    174181            this.div.className = this.displayClass; 
     182            if (this.title != "") { 
     183                this.div.title = this.title; 
     184            } 
    175185        } 
    176186        if (px != null) { 
  • sandbox/tschaub/geoview/lib/OpenLayers/Control/MousePosition.js

    r5904 r5920  
    131131        } 
    132132         
     133        var newHtml = this.formatOutput(lonLat); 
     134 
     135        if (newHtml != this.element.innerHTML) { 
     136            this.element.innerHTML = newHtml; 
     137        } 
     138    }, 
     139 
     140    /** 
     141     * Method: formatOutput 
     142     * Override to provide custom display output 
     143     * 
     144     * Parameters: 
     145     * lonLat - {<OpenLayers.LonLat>} Location to display 
     146     */ 
     147    formatOutput: function(lonLat) { 
    133148        var digits = parseInt(this.numdigits); 
    134149        var newHtml = 
     
    138153            lonLat.lat.toFixed(digits) + 
    139154            this.suffix; 
    140  
    141         if (newHtml != this.element.innerHTML) { 
    142             this.element.innerHTML = newHtml; 
    143         } 
    144     }, 
     155        return newHtml; 
     156     }, 
    145157 
    146158    /**  
  • sandbox/tschaub/geoview/lib/OpenLayers/Control/Panel.js

    r5904 r5920  
    173173            var textNode = document.createTextNode(" "); 
    174174            controls[i].panel_div = element; 
     175            if (controls[i].title != "") { 
     176                controls[i].panel_div.title = controls[i].title; 
     177            } 
    175178            OpenLayers.Event.observe(controls[i].panel_div, "click",  
    176179                OpenLayers.Function.bind(this.onClick, this, controls[i])); 
  • sandbox/tschaub/geoview/lib/OpenLayers/Feature/Vector.js

    r5904 r5920  
    280280 *  - hoverPointUnit: "%", 
    281281 *  - pointerEvents: "visiblePainted" 
     282 *  - cursor: "" 
    282283 * 
    283284 * Other style properties that have no default values: 
     
    307308        hoverPointRadius: 1, 
    308309        hoverPointUnit: "%", 
    309         pointerEvents: "visiblePainted" 
     310        pointerEvents: "visiblePainted", 
     311        cursor: "" 
    310312    }, 
    311313    'select': { 
     
    342344        hoverPointRadius: 1, 
    343345        hoverPointUnit: "%", 
    344         pointerEvents: "visiblePainted" 
     346        pointerEvents: "visiblePainted", 
     347        cursor: "" 
    345348    } 
    346349};     
  • sandbox/tschaub/geoview/lib/OpenLayers/Format/WMC.js

    r5905 r5920  
     1/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD 
     2 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the 
     3 * full text of the license. */ 
     4 
    15/** 
    26 * @requires OpenLayers/Format/XML.js 
     
    188192 
    189193}); 
    190 /** 
    191  * @requires OpenLayers/Format/XML.js 
    192  */ 
    193  
    194 /** 
    195  * Class: OpenLayers.Format.WMC 
    196  * Read and write Web Map Context documents. 
    197  * 
    198  * Inherits from: 
    199  *  - <OpenLayers.Format.XML> 
    200  */ 
    201 OpenLayers.Format.WMC = OpenLayers.Class({ 
    202      
    203     /** 
    204      * APIProperty: defaultVersion 
    205      * {String} Version number to assume if none found.  Default is "1.1.0". 
    206      */ 
    207     defaultVersion: "1.1.0", 
    208      
    209     /** 
    210      * APIProperty: version 
    211      * {String} Specify a version string if one is known. 
    212      */ 
    213     version: null, 
    214      
    215     /** 
    216      * Property: parser 
    217      * {Object} Instance of the versioned parser.  Cached for multiple read and 
    218      *     write calls of the same version. 
    219      */ 
    220     parser: null, 
    221  
    222     /** 
    223      * Constructor: OpenLayers.Format.WMC 
    224      * Create a new parser for WMC docs. 
    225      * 
    226      * Parameters: 
    227      * options - {Object} An optional object whose properties will be set on 
    228      *     this instance. 
    229      */ 
    230     initialize: function(options) { 
    231         OpenLayers.Util.extend(this, options); 
    232         this.options = options; 
    233     }, 
    234  
    235     /** 
    236      * APIMethod: read 
    237      * Read WMC data from a string, and return an object with map properties 
    238      *     and a list of layers.  
    239      *  
    240      * Parameters:  
    241      * data - {String} or {DOMElement} data to read/parse. 
    242      * options - {Object} The options object must contain a map property.  If 
    243      *     the map property is a string, it must be the id of a dom element 
    244      *     where the new map will be placed.  If the map property is an 
    245      *     <OpenLayers.Map>, the layers from the context document will be added 
    246      *     to the map. 
    247      * 
    248      * Returns: 
    249      * {<OpenLayers.Map>} A map based on the context. 
    250      */ 
    251     read: function(data, options) { 
    252         if(typeof data == "string") { 
    253             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
    254         } 
    255         var root = data.documentElement; 
    256         var version = this.version; 
    257         if(!version) { 
    258             version = root.getAttribute("version"); 
    259             if(!version) { 
    260                 version = this.defaultVersion; 
    261             } 
    262         } 
    263         if(!this.parser || this.parser.VERSION != version) { 
    264             var format = OpenLayers.Format.WMC[ 
    265                 "v" + version.replace(/\./g, "_") 
    266             ]; 
    267             if(!format) { 
    268                 throw "Can't find a WMS capabilities parser for version " + 
    269                       version; 
    270             } 
    271             this.parser = new format(this.options); 
    272         } 
    273         var context = this.parser.read(data); 
    274         var map; 
    275         if(options.map instanceof OpenLayers.Map) { 
    276             map = this.mergeContextToMap(context, options.map); 
    277         } else { 
    278             map = this.contextToMap(context, options.map); 
    279         } 
    280         return map; 
    281     }, 
    282      
    283     /** 
    284      * Method: contextToMap 
    285      * Create a map given a context object. 
    286      * 
    287      * Parameters: 
    288      * context - {Object} The context object. 
    289      * id - {String | Element} The dom element or element id that will contain 
    290      *     the map. 
    291      * 
    292      * Returns: 
    293      * {<OpenLayers.Map>} A map based on the context object. 
    294      */ 
    295     contextToMap: function(context, id) { 
    296         var map = new OpenLayers.Map(id, { 
    297             maxExtent: context.maxExtent, 
    298             projection: context.projection 
    299         }); 
    300         map.addLayers(context.layers); 
    301         map.setCenter( 
    302             context.bounds.getCenterLonLat(), 
    303             map.getZoomForExtent(context.bounds, true) 
    304         ); 
    305         return map; 
    306     }, 
    307      
    308     /** 
    309      * Method: mergeContextToMap 
    310      * Add layers from a context object to a map. 
    311      * 
    312      * Parameters: 
    313      * context - {Object} The context object. 
    314      * map - {<OpenLayers.Map>} The map. 
    315      * 
    316      * Returns: 
    317      * {<OpenLayers.Map>} The same map with layers added. 
    318      */ 
    319     mergeContextToMap: function(context, map) { 
    320         map.addLayers(context.layers); 
    321         return map; 
    322     }, 
    323  
    324     /** 
    325      * APIMethod: write 
    326      * Write a WMC document given a map. 
    327      * 
    328      * Parameters: 
    329      * obj - {<OpenLayers.Map> | Object} A map or context object. 
    330      * options - {Object} Optional configuration object. 
    331      * 
    332      * Returns: 
    333      * {String} A WMC document string. 
    334      */ 
    335     write: function(obj, options) { 
    336         if(obj.CLASS_NAME == "OpenLayers.Map") { 
    337             obj = this.mapToContext(obj); 
    338         } 
    339         var version = (options && options.version) || 
    340                       this.version || this.defaultVersion; 
    341         if(!this.parser || this.parser.VERSION != version) { 
    342             var format = OpenLayers.Format.WMC[ 
    343                 "v" + version.replace(/\./g, "_") 
    344             ]; 
    345             if(!format) { 
    346                 throw "Can't find a WMS capabilities parser for version " + 
    347                       version; 
    348             } 
    349             this.parser = new format(this.options); 
    350         } 
    351         var wmc = this.parser.write(obj); 
    352         return wmc; 
    353     }, 
    354      
    355     /** 
    356      * Method: mapToContext 
    357      * Create a context object given a map. 
    358      * 
    359      * Parameters: 
    360      * map - {<OpenLayers.Map>} The map. 
    361      * 
    362      * Returns: 
    363      * {Object} A context object. 
    364      */ 
    365     mapToContext: function(map) { 
    366         var context = { 
    367             bounds: map.getExtent(), 
    368             maxExtent: map.maxExtent, 
    369             projection: map.projection, 
    370             layers: map.layers, 
    371             size: map.getSize() 
    372         }; 
    373         return context; 
    374     }, 
    375  
    376     CLASS_NAME: "OpenLayers.Format.WMC"  
    377  
    378 }); 
  • sandbox/tschaub/geoview/lib/OpenLayers/Format/WMC/v1.js

    r5905 r5920  
     1/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD 
     2 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the 
     3 * full text of the license. */ 
     4 
    15/** 
    26 * @requires OpenLayers/Format/XML.js 
     
    759763 
    760764}); 
    761 /** 
    762  * @requires OpenLayers/Format/XML.js 
    763  */ 
    764  
    765 /** 
    766  * Class: OpenLayers.Format.WMC.v1 
    767  * Superclass for WMC version 1 parsers. 
    768  * 
    769  * Inherits from: 
    770  *  - <OpenLayers.Format.XML> 
    771  */ 
    772 OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, { 
    773      
    774     /** 
    775      * Property: namespaces 
    776      * {Object} Mapping of namespace aliases to namespace URIs. 
    777      */ 
    778     namespaces: { 
    779         ol: "http://openlayers.org/context", 
    780         wmc: "http://www.opengis.net/context", 
    781         sld: "http://www.opengis.net/sld", 
    782         xlink: "http://www.w3.org/1999/xlink", 
    783         xsi: "http://www.w3.org/2001/XMLSchema-instance" 
    784     }, 
    785      
    786     /** 
    787      * Property: schemaLocation 
    788      * {String} Schema location for a particular minor version. 
    789      */ 
    790     schemaLocation: "", 
    791  
    792     /** 
    793      * Method: getNamespacePrefix 
    794      * Get the namespace prefix for a given uri from the <namespaces> object. 
    795      * 
    796      * Returns: 
    797      * {String} A namespace prefix or null if none found. 
    798      */ 
    799     getNamespacePrefix: function(uri) { 
    800         var prefix = null; 
    801         if(uri == null) { 
    802             prefix = this.namespaces[this.defaultPrefix]; 
    803         } else { 
    804             for(prefix in this.namespaces) { 
    805                 if(this.namespaces[prefix] == uri) { 
    806                     break; 
    807                 } 
    808             } 
    809         } 
    810         return prefix; 
    811     }, 
    812      
    813     /** 
    814      * Property: defaultPrefix 
    815      */ 
    816     defaultPrefix: "wmc", 
    817  
    818     /** 
    819      * Property: rootPrefix 
    820      * {String} Prefix on the root node that maps to the context namespace URI. 
    821      */ 
    822     rootPrefix: null, 
    823      
    824     /** 
    825      * Property: defaultStyleName 
    826      * {String} Style name used if layer has no style param.  Default is "". 
    827      */ 
    828     defaultStyleName: "", 
    829      
    830     /** 
    831      * Property: defaultStyleTitle 
    832      * {String} Default style title.  Default is "Default". 
    833      */ 
    834     defaultStyleTitle: "Default", 
    835      
    836     /** 
    837      * Constructor: OpenLayers.Format.WMC.v1 
    838      * Instances of this class are not created directly.  Use the 
    839      *     <OpenLayers.Format.WMC> constructor instead. 
    840      * 
    841      * Parameters: 
    842      * options - {Object} An optional object whose properties will be set on 
    843      *     this instance. 
    844      */ 
    845     initialize: function(options) { 
    846         OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); 
    847     }, 
    848  
    849     /** 
    850      * Method: read 
    851      * Read capabilities data from a string, and return a list of layers.  
    852      *  
    853      * Parameters:  
    854      * data - {String} or {DOMElement} data to read/parse. 
    855      * 
    856      * Returns: 
    857      * {Array} List of named layers. 
    858      */ 
    859     read: function(data) { 
    860         if(typeof data == "string") { 
    861             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
    862         } 
    863         var root = data.documentElement; 
    864         this.rootPrefix = root.prefix; 
    865         var context = { 
    866             version: root.getAttribute("version") 
    867         }; 
    868         this.runChildNodes(context, root); 
    869         return context; 
    870     }, 
    871      
    872     /** 
    873      * Method: runChildNodes 
    874      */ 
    875     runChildNodes: function(obj, node) { 
    876         var children = node.childNodes; 
    877         var childNode, processor, prefix, local; 
    878         for(var i=0; i<children.length; ++i) { 
    879             childNode = children[i]; 
    880             if(childNode.nodeType == 1) { 
    881                 prefix = (childNode.prefix == this.rootPrefix) ? 
    882                             this.defaultPrefix : 
    883                             this.getNamespacePrefix(childNode.namespaceURI); 
    884                 local = childNode.nodeName.split(":").pop(); 
    885                 processor = this["read_" + prefix + "_" + local]; 
    886                 if(processor) { 
    887                     processor.apply(this, [obj, childNode]); 
    888                 } 
    889             } 
    890         } 
    891     }, 
    892      
    893     /** 
    894      * Method: read_wmc_General 
    895      */ 
    896     read_wmc_General: function(context, node) { 
    897         this.runChildNodes(context, node); 
    898     }, 
    899      
    900     /** 
    901      * Method: read_wmc_BoundingBox 
    902      */ 
    903     read_wmc_BoundingBox: function(context, node) { 
    904         context.projection = node.getAttribute("SRS"); 
    905         context.bounds = new OpenLayers.Bounds( 
    906             parseFloat(node.getAttribute("minx")), 
    907             parseFloat(node.getAttribute("miny")), 
    908             parseFloat(node.getAttribute("maxx")), 
    909             parseFloat(node.getAttribute("maxy")) 
    910         ); 
    911     }, 
    912      
    913     /** 
    914      * Method: read_wmc_LayerList 
    915      */ 
    916     read_wmc_LayerList: function(context, node) { 
    917         context.layers = []; 
    918         this.runChildNodes(context, node); 
    919     }, 
    920      
    921     /** 
    922      * Method: read_wmc_Layer 
    923      */ 
    924     read_wmc_Layer: function(context, node) { 
    925         var layerInfo = { 
    926             params: {}, 
    927             options: { 
    928                 visibility: (node.getAttribute("hidden") != "1") 
    929             }, 
    930             queryable: (node.getAttribute("queryable") == "1"), 
    931             formats: [], 
    932             styles: [] 
    933         }; 
    934         this.runChildNodes(layerInfo, node); 
    935         // set properties common to multiple objects on layer options/params 
    936         layerInfo.params.layers = layerInfo.name; 
    937         layerInfo.options.maxExtent = layerInfo.maxExtent; 
    938         // create the layer 
    939         var layer = this.getLayerFromInfo(layerInfo); 
    940         context.layers.push(layer); 
    941     }, 
    942      
    943     /** 
    944      * Method: getLayerFromInfo 
    945      * Create a WMS layer from a layerInfo object. 
    946      * 
    947      * Parameters: 
    948      * layerInfo - {Object} An object representing a WMS layer. 
    949      * 
    950      * Returns: 
    951      * {<OpenLayers.Layer.WMS>} A WMS layer. 
    952      */ 
    953     getLayerFromInfo: function(layerInfo) { 
    954         var layer = new OpenLayers.Layer.WMS( 
    955             layerInfo.title, 
    956             layerInfo.href, 
    957             layerInfo.params, 
    958             layerInfo.options 
    959         ); 
    960         return layer; 
    961     }, 
    962      
    963     /** 
    964      * Method: read_wmc_Extension 
    965      */ 
    966     read_wmc_Extension: function(obj, node) { 
    967         this.runChildNodes(obj, node); 
    968     }, 
    969  
    970     /** 
    971      * Method: read_ol_units 
    972      */ 
    973     read_ol_units: function(layerInfo, node) { 
    974         layerInfo.options.units = this.getChildValue(node); 
    975     }, 
    976      
    977     /** 
    978      * Method: read_ol_maxExtent 
    979      */ 
    980     read_ol_maxExtent: function(obj, node) { 
    981         var bounds = new OpenLayers.Bounds( 
    982             node.getAttribute("minx"), node.getAttribute("miny"), 
    983             node.getAttribute("maxx"), node.getAttribute("maxy") 
    984         ); 
    985         obj.maxExtent = bounds; 
    986     }, 
    987      
    988     /** 
    989      * Method: read_ol_transparent 
    990      */ 
    991     read_ol_transparent: function(layerInfo, node) { 
    992         layerInfo.params.transparent = this.getChildValue(node); 
    993     }, 
    994  
    995     /** 
    996      * Method: read_ol_numZoomLevels 
    997      */ 
    998     read_ol_numZoomLevels: function(layerInfo, node) { 
    999         layerInfo.options.numZoomLevels = parseInt(this.getChildValue(node)); 
    1000     }, 
    1001  
    1002     /** 
    1003      * Method: read_ol_opacity 
    1004      */ 
    1005     read_ol_opacity: function(layerInfo, node) { 
    1006         layerInfo.options.opacity = parseFloat(this.getChildValue(node)); 
    1007     }, 
    1008  
    1009     /** 
    1010      * Method: read_ol_singleTile 
    1011      */ 
    1012     read_ol_singleTile: function(layerInfo, node) { 
    1013         layerInfo.options.singleTile = (this.getChildValue(node) == "true"); 
    1014     }, 
    1015  
    1016     /** 
    1017      * Method: read_ol_isBaseLayer 
    1018      */ 
    1019     read_ol_isBaseLayer: function(layerInfo, node) { 
    1020         layerInfo.options.isBaseLayer = (this.getChildValue(node) == "true"); 
    1021     }, 
    1022  
    1023     /** 
    1024      * Method: read_ol_displayInLayerSwitcher 
    1025      */ 
    1026     read_ol_displayInLayerSwitcher: function(layerInfo, node) { 
    1027         layerInfo.options.displayInLayerSwitcher = 
    1028             (this.getChildValue(node) == "true"); 
    1029     }, 
    1030  
    1031     /** 
    1032      * Method: read_wmc_Server 
    1033      */ 
    1034     read_wmc_Server: function(layerInfo, node) { 
    1035         layerInfo.params.version = node.getAttribute("version"); 
    1036         this.runChildNodes(layerInfo, node); 
    1037     }, 
    1038  
    1039     /** 
    1040      * Method: read_wmc_FormatList 
    1041      */ 
    1042     read_wmc_FormatList: function(layerInfo, node) { 
    1043         this.runChildNodes(layerInfo, node); 
    1044     }, 
    1045  
    1046     /** 
    1047      * Method: read_wmc_Format 
    1048      */ 
    1049     read_wmc_Format: function(layerInfo, node) { 
    1050         var format = this.getChildValue(node) 
    1051         layerInfo.formats.push(format); 
    1052         if(node.getAttribute("current") == "1") { 
    1053             layerInfo.params.format = format; 
    1054         } 
    1055     }, 
    1056      
    1057     /** 
    1058      * Method: read_wmc_StyleList 
    1059      */ 
    1060     read_wmc_StyleList: function(layerInfo, node) { 
    1061         this.runChildNodes(layerInfo, node); 
    1062     }, 
    1063  
    1064     /** 
    1065      * Method: read_wmc_Style 
    1066      */ 
    1067     read_wmc_Style: function(layerInfo, node) { 
    1068         var style = {}; 
    1069         this.runChildNodes(style, node); 
    1070         if(node.getAttribute("current") == "1") { 
    1071             layerInfo.params.style = style.name; 
    1072         } 
    1073         layerInfo.styles.push(style); 
    1074     }, 
    1075  
    1076     /** 
    1077      * Method: read_wmc_OnlineResource 
    1078      */ 
    1079     read_wmc_OnlineResource: function(obj, node) { 
    1080         obj.href = this.getAttributeNS( 
    1081             node, this.namespaces.xlink, "href" 
    1082         ); 
    1083     }, 
    1084      
    1085     /** 
    1086      * Method: read_wmc_Name 
    1087      */ 
    1088     read_wmc_Name: function(obj, node) { 
    1089         var name = this.getChildValue(node); 
    1090         if(name) { 
    1091             obj.name = name; 
    1092         } 
    1093     }, 
    1094  
    1095     /** 
    1096      * Method: read_wmc_Title 
    1097      */ 
    1098     read_wmc_Title: function(obj, node) { 
    1099         var title = this.getChildValue(node); 
    1100         if(title) { 
    1101             obj.title = title; 
    1102         } 
    1103     }, 
    1104  
    1105     /** 
    1106      * Method: read_wmc_Abstract 
    1107      */ 
    1108     read_wmc_Abstract: function(obj, node) { 
    1109         var abst = this.getChildValue(node); 
    1110         if(abst) { 
    1111             obj["abstract"] = abst; 
    1112         } 
    1113     }, 
    1114      
    1115     /** 
    1116      * Method: read_wmc_LatLonBoundingBox 
    1117      */ 
    1118     read_wmc_LatLonBoundingBox: function(layer, node) { 
    1119         layer.llbbox = [ 
    1120             parseFloat(node.getAttribute("minx")), 
    1121             parseFloat(node.getAttribute("miny")), 
    1122             parseFloat(node.getAttribute("maxx")), 
    1123             parseFloat(node.getAttribute("maxy")) 
    1124         ]; 
    1125     }, 
    1126  
    1127     /** 
    1128      * Method: read_wmc_LegendURL 
    1129      */ 
    1130     read_wmc_LegendURL: function(style, node) { 
    1131         var legend = { 
    1132             width: node.getAttribute('width'), 
    1133             height: node.getAttribute('height') 
    1134         }; 
    1135         var links = node.getElementsByTagName("OnlineResource"); 
    1136         if(links.length > 0) { 
    1137             this.read_wmc_OnlineResource(legend, links[0]); 
    1138         } 
    1139         style.legend = legend; 
    1140     }, 
    1141      
    1142     /** 
    1143      * Method: write 
    1144      * 
    1145      * Parameters: 
    1146      * context - {Object} An object representing the map context. 
    1147      * options - {Object} Optional object. 
    1148      * 
    1149      * Returns: 
    1150      * {String} A WMC document string. 
    1151      */ 
    1152     write: function(context, options) { 
    1153         var root = this.createElementDefaultNS("ViewContext"); 
    1154         this.setAttributes(root, { 
    1155             version: this.VERSION, 
    1156             id: (options && typeof options.id == "string") ? 
    1157                     options.id : 
    1158                     OpenLayers.Util.createUniqueID("OpenLayers_Context_") 
    1159         }); 
    1160          
    1161         // add schemaLocation attribute 
    1162         this.setAttributeNS( 
    1163             root, this.namespaces.xsi, 
    1164             "xsi:schemaLocation", this.schemaLocation 
    1165         ); 
    1166          
    1167         // required General element 
    1168         root.appendChild(this.write_wmc_General(context)); 
    1169  
    1170         // required LayerList element 
    1171         root.appendChild(this.write_wmc_LayerList(context)); 
    1172  
    1173         return OpenLayers.Format.XML.prototype.write.apply(this, [root]); 
    1174     }, 
    1175      
    1176     /** 
    1177      * Method: createElementDefaultNS 
    1178      * Shorthand for createElementNS with namespace from <defaultPrefix>. 
    1179      *     Can optionally be used to set attributes and a text child value. 
    1180      * 
    1181      * Parameters: 
    1182      * name - {String} The qualified node name. 
    1183      * childValue - {String} Optional value for text child node. 
    1184      * attributes - {Object} Optional object representing attributes. 
    1185      * 
    1186      * Returns: 
    1187      * {Element} An element node. 
    1188      */ 
    1189     createElementDefaultNS: function(name, childValue, attributes) { 
    1190         var node = this.createElementNS( 
    1191             this.namespaces[this.defaultPrefix], 
    1192             name 
    1193         ); 
    1194         if(childValue) { 
    1195             node.appendChild(this.createTextNode(childValue)); 
    1196         } 
    1197         if(attributes) { 
    1198             this.setAttributes(node, attributes); 
    1199         } 
    1200         return node; 
    1201     }, 
    1202      
    1203     /** 
    1204      * Method: setAttributes 
    1205      * Set multiple attributes given key value pairs from an object. 
    1206      * 
    1207      * Parameters: 
    1208      * node - {Element} An element node. 
    1209      * obj - {Object} An object whose properties represent attribute names and 
    1210      *     values represent attribute values. 
    1211      */ 
    1212     setAttributes: function(node, obj) { 
    1213         var value; 
    1214         for(var name in obj) { 
    1215             value = obj[name].toString(); 
    1216             if(value.match(/[A-Z]/)) { 
    1217                 // safari lowercases attributes with setAttribute 
    1218                 this.setAttributeNS(node, null, name, value); 
    1219             } else { 
    1220                 node.setAttribute(name, value); 
    1221             } 
    1222         } 
    1223     }, 
    1224  
    1225     /** 
    1226      * Method: write_wmc_General 
    1227      * Create a General node given an context object. 
    1228      * 
    1229      * Parameters: 
    1230      * context - {Object} Context object. 
    1231      * 
    1232      * Returns: 
    1233      * {Element} A WMC General element node. 
    1234      */ 
    1235     write_wmc_General: function(context) { 
    1236         var node = this.createElementDefaultNS("General"); 
    1237  
    1238         // optional Window element 
    1239         if(context.size) { 
    1240             node.appendChild(this.createElementDefaultNS( 
    1241                 "Window", null, 
    1242                 { 
    1243                     width: context.size.w, 
    1244                     height: context.size.h 
    1245                 } 
    1246             )); 
    1247         } 
    1248          
    1249         // required BoundingBox element 
    1250         var bounds = context.bounds; 
    1251         node.appendChild(this.createElementDefaultNS( 
    1252             "BoundingBox", null, 
    1253             { 
    1254                 minx: bounds.left.toPrecision(10), 
    1255                 miny: bounds.bottom.toPrecision(10), 
    1256                 maxx: bounds.right.toPrecision(10), 
    1257                 maxy: bounds.top.toPrecision(10), 
    1258                 SRS: context.projection 
    1259             } 
    1260         )); 
    1261  
    1262         // required Title element 
    1263         node.appendChild(this.createElementDefaultNS( 
    1264             "Title", context.title 
    1265         )); 
    1266          
    1267         // OpenLayers specific map properties 
    1268         node.appendChild(this.write_ol_MapExtension(context)); 
    1269          
    1270         return node; 
    1271     }, 
    1272      
    1273     /** 
    1274      * Method: write_ol_MapExtension 
    1275      */ 
    1276     write_ol_MapExtension: function(context) { 
    1277         var node = this.createElementDefaultNS("Extension"); 
    1278          
    1279         var bounds = context.maxExtent; 
    1280         if(bounds) { 
    1281             var maxExtent = this.createElementNS( 
    1282                 this.namespaces.ol, "ol:maxExtent" 
    1283             ); 
    1284             this.setAttributes(maxExtent, { 
    1285                 minx: bounds.left.toPrecision(10), 
    1286                 miny: bounds.bottom.toPrecision(10), 
    1287                 maxx: bounds.right.toPrecision(10), 
    1288                 maxy: bounds.top.toPrecision(10) 
    1289             }); 
    1290             node.appendChild(maxExtent); 
    1291         } 
    1292          
    1293         return node; 
    1294     }, 
    1295      
    1296     /** 
    1297      * Method: write_wmc_LayerList 
    1298      * Create a LayerList node given an context object. 
    1299      * 
    1300      * Parameters: 
    1301      * context - {Object} Context object. 
    1302      * 
    1303      * Returns: 
    1304      * {Element} A WMC LayerList element node. 
    1305      */ 
    1306     write_wmc_LayerList: function(context) { 
    1307         var list = this.createElementDefaultNS("LayerList"); 
    1308          
    1309         var layer; 
    1310         for(var i=0; i<context.layers.length; ++i) { 
    1311             layer = context.layers[i]; 
    1312             if(layer instanceof OpenLayers.Layer.WMS) { 
    1313                 list.appendChild(this.write_wmc_Layer(layer)); 
    1314             } 
    1315         } 
    1316          
    1317         return list; 
    1318     }, 
    1319  
    1320     /** 
    1321      * Method: write_wmc_Layer 
    1322      * Create a Layer node given a layer object. 
    1323      * 
    1324      * Parameters: 
    1325      * layer - {<OpenLayers.Layer.WMS>} Layer object. 
    1326      * 
    1327      * Returns: 
    1328      * {Element} A WMC Layer element node. 
    1329      */ 
    1330     write_wmc_Layer: function(layer) { 
    1331         var node = this.createElementDefaultNS( 
    1332             "Layer", null, { 
    1333                 queryable: "1", 
    1334                 hidden: layer.visibility ? "0" : "1" 
    1335             } 
    1336         ); 
    1337          
    1338         // required Server element 
    1339         node.appendChild(this.write_wmc_Server(layer)); 
    1340  
    1341         // required Name element 
    1342         node.appendChild(this.createElementDefaultNS( 
    1343             "Name", layer.params["LAYERS"] 
    1344         )); 
    1345          
    1346         // required Title element 
    1347         node.appendChild(this.createElementDefaultNS( 
    1348             "Title", layer.name 
    1349         )); 
    1350          
    1351         // optional FormatList element 
    1352         node.appendChild(this.write_wmc_FormatList(layer)); 
    1353  
    1354         // optional StyleList element 
    1355         node.appendChild(this.write_wmc_StyleList(layer)); 
    1356          
    1357         // OpenLayers specific properties go in an Extension element 
    1358         node.appendChild(this.write_wmc_LayerExtension(layer)); 
    1359  
    1360         return node; 
    1361     }, 
    1362      
    1363     /** 
    1364      * Method: write_wmc_LayerExtension 
    1365      * Add OpenLayers specific layer parameters to an Extension element. 
    1366      * 
    1367      * Parameters: 
    1368      * layer - {<OpenLayers.Layer.WMS>} A WMS layer. 
    1369      * 
    1370      * Returns: 
    1371      * {Element} A WMC Extension element (for a layer). 
    1372      */ 
    1373     write_wmc_LayerExtension: function(layer) { 
    1374         var node = this.createElementDefaultNS("Extension"); 
    1375          
    1376         var bounds = layer.maxExtent; 
    1377         var maxExtent = this.createElementNS( 
    1378             this.namespaces.ol, "ol:maxExtent" 
    1379         ); 
    1380         this.setAttributes(maxExtent, { 
    1381             minx: bounds.left.toPrecision(10), 
    1382             miny: bounds.bottom.toPrecision(10), 
    1383             maxx: bounds.right.toPrecision(10), 
    1384             maxy: bounds.top.toPrecision(10) 
    1385         }); 
    1386         node.appendChild(maxExtent); 
    1387          
    1388         var param = layer.params["TRANSPARENT"]; 
    1389         if(param) { 
    1390             var trans = this.createElementNS( 
    1391                 this.namespaces.ol, "ol:transparent" 
    1392 </