Changeset 5615
- Timestamp:
- 01/01/08 13:09:16 (8 months ago)
- Files:
-
- sandbox/tschaub/wmc/examples/wmc.html (modified) (1 diff)
- sandbox/tschaub/wmc/lib/OpenLayers.js (modified) (1 diff)
- sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC.js (modified) (2 diffs)
- sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1.js (added)
- sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1_0_0.js (modified) (2 diffs)
- sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1_1_0.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/tschaub/wmc/examples/wmc.html
r5565 r5615 42 42 43 43 } 44 var output = document.getElementById('output');45 44 46 45 </script> sandbox/tschaub/wmc/lib/OpenLayers.js
r5565 r5615 183 183 "OpenLayers/Format/GeoJSON.js", 184 184 "OpenLayers/Format/WMC.js", 185 "OpenLayers/Format/WMC/v1.js", 185 186 "OpenLayers/Format/WMC/v1_0_0.js", 186 187 "OpenLayers/Format/WMC/v1_1_0.js", sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC.js
r5565 r5615 21 21 */ 22 22 version: null, 23 24 /** 25 * Property: parser 26 * {Object} Instance of the versioned parser. Cached for multiple read and 27 * write calls of the same version. 28 */ 29 parser: null, 23 30 24 31 /** … … 58 65 } 59 66 } 60 var format = OpenLayers.Format.WMC[ 61 "v" + version.replace(/\./g, "_") 62 ]; 63 if(!format) { 64 throw "Can't find a WMS capabilities parser for version " + version; 67 if(!this.parser || this.parser.VERSION != version) { 68 var format = OpenLayers.Format.WMC[ 69 "v" + version.replace(/\./g, "_") 70 ]; 71 if(!format) { 72 throw "Can't find a WMS capabilities parser for version " + 73 version; 74 } 75 this.parser = new format(this.options); 65 76 } 66 var parser = new format(this.options); 67 var context = parser.read(data); 77 var context = this.parser.read(data); 68 78 return context; 69 79 }, 70 80 81 /** 82 * Method: contextToMap 83 * Create a map given a context object. 84 * 85 * Parameters: 86 * context - {Object} The context object. 87 * id - {String | Element} The dom element or element id that will contain 88 * the map. 89 * options - {Object} 90 * 91 * Returns: 92 * {<OpenLayers.Map>} A map based on the context object. 93 */ 94 contextToMap: function(context, id, options) { 95 }, 96 97 /** 98 * APIMethod: write 99 * Write a WMC document given a map. 100 * 101 * Parameters: 102 * obj - {<OpenLayers.Map> | Object} A map or context object. 103 * 104 * Returns: 105 * {String} A WMC document string. 106 */ 107 write: function(obj) { 108 if(obj.CLASS_NAME == "OpenLayers.Map") { 109 obj = this.mapToContext(obj); 110 } 111 var version = this.version || this.defaultVersion; 112 if(!this.parser || this.parser.VERSION != version) { 113 var format = OpenLayers.Format.WMC[ 114 "v" + version.replace(/\./g, "_") 115 ]; 116 if(!format) { 117 throw "Can't find a WMS capabilities parser for version " + 118 version; 119 } 120 this.parser = new format(this.options); 121 } 122 var wmc = this.parser.write(obj); 123 return wmc; 124 }, 125 126 /** 127 * Method: mapToContext 128 * Create a context object given a map. 129 * 130 * Parameters: 131 * map - {<OpenLayers.Map>} The map. 132 * 133 * Returns: 134 * {Object} A context object. 135 */ 136 mapToContext: function(map) { 137 var context = {}; 138 }, 139 71 140 CLASS_NAME: "OpenLayers.Format.WMC" 72 141 sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1_0_0.js
r5565 r5615 6 6 * 7 7 * Inherits from: 8 * - <OpenLayers.Format.WMC >8 * - <OpenLayers.Format.WMC.v1> 9 9 */ 10 10 OpenLayers.Format.WMC.v1_0_0 = OpenLayers.Class( 11 OpenLayers.Format.WMC , {11 OpenLayers.Format.WMC.v1, { 12 12 13 13 /** 14 * Constant: VERSION 15 * {String} 1.0.0 16 */ 17 VERSION: "1.0.0", 18 19 /** 14 20 * Constructor: OpenLayers.Format.WMC.v1_0_0 15 * Create a new parser for WMC version 1.0. 21 * Instances of this class are not created directly. Use the 22 * <OpenLayers.Format.WMC> constructor instead. 16 23 * 17 24 * Parameters: … … 20 27 */ 21 28 initialize: function(options) { 22 OpenLayers.Format.WMC. prototype.initialize.apply(29 OpenLayers.Format.WMC.v1.prototype.initialize.apply( 23 30 this, [options] 24 31 ); 25 32 }, 26 33 27 /**28 * APIMethod: read29 * Read capabilities data from a string, and return a list of layers.30 *31 * Parameters:32 * data - {String} or {DOMElement} data to read/parse.33 *34 * Returns:35 * {Array} List of named layers.36 */37 read: function(data) {38 if(typeof data == "string") {39 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);40 }41 var root = data.documentElement;42 var context = {43 version: root.getAttribute("version")44 };45 this.runChildNodes(context, root);46 return context;47 },48 49 /**50 * Method: runChildNodes51 */52 runChildNodes: function(obj, node) {53 var children = node.childNodes;54 var childNode, processor;55 for(var i=0; i<children.length; ++i) {56 childNode = children[i];57 if(childNode.nodeType == 1) {58 processor = this["read" + childNode.nodeName];59 if(processor) {60 processor.apply(this, [obj, childNode]);61 }62 }63 }64 },65 66 /**67 * Method: readGeneral68 */69 readGeneral: function(context, node) {70 this.runChildNodes(context, node);71 },72 73 /**74 * Method: readBoundingBox75 */76 readBoundingBox: function(context, node) {77 context.srs = node.getAttribute("SRS");78 context.bounds = new OpenLayers.Bounds(79 parseFloat(node.getAttribute("minx")),80 parseFloat(node.getAttribute("miny")),81 parseFloat(node.getAttribute("maxx")),82 parseFloat(node.getAttribute("maxy"))83 );84 },85 86 /**87 * Method: readLayerList88 */89 readLayerList: function(context, node) {90 context.layers = [];91 this.runChildNodes(context, node);92 },93 94 /**95 * Method: readLayer96 */97 readLayer: function(context, node) {98 var layerInfo = {99 visibility: (node.getAttribute("hidden") != "1"),100 queryable: (node.getAttribute("queryable") == "1"),101 formats: [],102 styles: []103 };104 this.runChildNodes(layerInfo, node);105 var layer = new OpenLayers.Layer.WMS(106 layerInfo.title,107 layerInfo.href,108 {109 layers: layerInfo.name,110 styles: (layerInfo.currentStyle) ? layerInfo.currentStyle.name : "",111 format: layerInfo.currentFormat,112 version: layerInfo.version113 114 }115 );116 context.layers.push(layer);117 },118 119 /**120 * Method: readServer121 */122 readServer: function(layerInfo, node) {123 layerInfo.version = node.getAttribute("version");124 this.runChildNodes(layerInfo, node);125 },126 127 /**128 * Method: readFormatList129 */130 readFormatList: function(layerInfo, node) {131 this.runChildNodes(layerInfo, node);132 },133 134 /**135 * Method: readFormat136 */137 readFormat: function(layerInfo, node) {138 var format = this.getChildValue(node)139 layerInfo.formats.push(format);140 if(node.getAttribute("current") == "1") {141 layerInfo.currentFormat = format;142 }143 },144 145 /**146 * Method: readStyleList147 */148 readStyleList: function(layerInfo, node) {149 this.runChildNodes(layerInfo, node);150 },151 152 /**153 * Method: readStyle154 */155 readStyle: function(layerInfo, node) {156 var style = {};157 this.runChildNodes(style, node);158 if(node.getAttribute("current") == "1") {159 layerInfo.currentStyle = style;160 }161 layerInfo.styles.push(style);162 },163 164 /**165 * Method: readOnlineResource166 */167 readOnlineResource: function(obj, node) {168 obj.href = this.getAttributeNS(169 node, "http://www.w3.org/1999/xlink", "href"170 );171 },172 173 /**174 * Method: readName175 */176 readName: function(obj, node) {177 var name = this.getChildValue(node);178 if(name) {179 obj.name = name;180 }181 },182 183 /**184 * Method: readTitle185 */186 readTitle: function(obj, node) {187 var title = this.getChildValue(node);188 if(title) {189 obj.title = title;190 }191 },192 193 /**194 * Method: readAbstract195 */196 readAbstract: function(obj, node) {197 var abst = this.getChildValue(node);198 if(abst) {199 obj["abstract"] = abst;200 }201 },202 203 /**204 * Method: readLatLonBoundingBox205 */206 readLatLonBoundingBox: function(layer, node) {207 layer.llbbox = [208 parseFloat(node.getAttribute("minx")),209 parseFloat(node.getAttribute("miny")),210 parseFloat(node.getAttribute("maxx")),211 parseFloat(node.getAttribute("maxy"))212 ];213 },214 215 /**216 * Method: readLegendURL217 */218 readLegendURL: function(style, node) {219 var legend = {220 width: node.getAttribute('width'),221 height: node.getAttribute('height')222 };223 var links = node.getElementsByTagName("OnlineResource");224 if(links.length > 0) {225 this.readOnlineResource(legend, links[0]);226 }227 style.legend = legend;228 },229 230 231 34 CLASS_NAME: "OpenLayers.Format.WMC.v1_0_0" 232 35 sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1_1_0.js
r5565 r5615 4 4 * Class: OpenLayers.Format.WMC.v1_1_0 5 5 * Read and write WMC version 1.1.0. 6 * 7 * Differences between 1.1.0 and 1.0.0: 8 * - 1.1.0 Layers have optional sld:MinScaleDenominator and 9 * sld:MaxScaleDenominator 6 10 * 7 11 * Inherits from: 8 * - <OpenLayers.Format.WMC >12 * - <OpenLayers.Format.WMC.v1> 9 13 */ 10 14 OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class( 11 OpenLayers.Format.WMC.v1 _0_0, {15 OpenLayers.Format.WMC.v1, { 12 16 13 17 /** 18 * Constant: VERSION 19 * {String} 1.1.0 20 */ 21 VERSION: "1.1.0", 22 23 /** 14 24 * Constructor: OpenLayers.Format.WMC.v1_1_0 15 * Create a new parser for WMS capabilities version 1.1.0. 25 * Instances of this class are not created directly. Use the 26 * <OpenLayers.Format.WMC> constructor instead. 16 27 * 17 28 * Parameters: … … 20 31 */ 21 32 initialize: function(options) { 22 OpenLayers.Format.WMC.v1 _0_0.prototype.initialize.apply(33 OpenLayers.Format.WMC.v1.prototype.initialize.apply( 23 34 this, [options] 24 35 );
