Changeset 5434
- Timestamp:
- 12/15/07 16:42:11 (1 year ago)
- Files:
-
- sandbox/ahocevar/styles/examples/sld.html (modified) (1 diff)
- sandbox/ahocevar/styles/lib/OpenLayers/Format/SLD.js (modified) (5 diffs)
- sandbox/ahocevar/styles/tests/Format/test_SLD.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/ahocevar/styles/examples/sld.html
r5432 r5434 27 27 map.zoomToExtent(new OpenLayers.Bounds(143,-39,150,-45)); 28 28 29 sld = new OpenLayers.Format.SLD() ;30 sld.read(req.responseText);29 sld = new OpenLayers.Format.SLD().read(req.responseText, 30 {withNamedLayer: true}); 31 31 32 styles = sld .content.namedLayer;32 styles = sld[1]; 33 33 34 34 waterStyle = styles["WaterBodies"]; sandbox/ahocevar/styles/lib/OpenLayers/Format/SLD.js
r5309 r5434 53 53 54 54 /** 55 * APIProperty: content 56 * {Object} containing 57 * - namedLayer - {Object} hash of userStyles, keyed by sld:NamedLayer/Name, 58 * each again keyed by sld:UserStyle/Name. Each entry of namedLayer 59 * is a style map for a layer, with the userStyle names as style keys. 60 * - userStyles - {Array(<OpenLayers.Style>)} 61 */ 62 content: { 63 namedLayer: null, 64 userStyles: null 65 }, 66 55 */ 56 withNamedLayer: false, 57 67 58 /** 68 59 * APIProperty: overrideDefaultStyleKey 69 60 * {Boolean} if true, userStyles with sld:IsDefault==1 will be stored with 70 61 * key "default" instead of the sld:UserStyle/Name in the style map. 62 * Default is true. 71 63 */ 72 64 overrideDefaultStyleKey: true, … … 90 82 * 91 83 * Parameters: 92 * data - {String} or {XMLNode} data to read/parse. 84 * data - {String} or {XMLNode} data to read/parse. 85 * options - {Object} Hash of withNamedLayer, overrideDefaultStyleKey: 86 * - withNamedLayer - {Boolean} if true, output of read() will be 87 * [styles, namedLayer] 88 * - styles - {Array(<OpenLayers.Style>)} 89 * - namedLayer - {Object} hash of userStyles, keyed by 90 * sld:NamedLayer/Name, each again keyed by 91 * sld:UserStyle/Name. Each entry of namedLayer is a 92 * StyleMap for a layer, with the userStyle names as style 93 * keys. 94 * Default is false. 95 * - overrideDefaultStyleKey - {Boolean} if true, userStyles with 96 * sld:IsDefault==1 will be stored with key "default" instead of 97 * the sld:UserStyle/Name in the style map. Default is true. 93 98 * 94 99 * Returns: 95 * {Array(<OpenLayers.Style>)} 96 */ 97 read: function(data ) {100 * {Array(<OpenLayers.Style>)} unless withNamedLayer option is true. 101 */ 102 read: function(data, options) { 98 103 if (typeof data == "string") { 99 104 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 100 105 } 106 107 options = OpenLayers.Util.extend({ 108 withNamedLayer: false, 109 overrideDefaultStyleKey: true}, options) 101 110 102 111 var userStyles = this.getElementsByTagNameNS(data, this.sldns, … … 106 115 } 107 116 108 this.content.namedLayer = {};117 var namedLayer = {}; 109 118 var styles = []; 110 119 … … 113 122 var style = this.parseUserStyle(userStyles[i], styleName); 114 123 115 if ( this.overrideDefaultStyleKey && style.isDefault == true) {124 if (options.overrideDefaultStyleKey && style.isDefault == true) { 116 125 styleName = "default"; 117 126 } 118 127 119 var namedLayer = this.content.namedLayer;120 128 if (!namedLayer[style.layerName]) { 121 129 namedLayer[style.layerName] = {}; … … 125 133 } 126 134 127 this.content.userStyles = styles; 128 129 return styles; 135 return options.withNamedLayer ? [styles, namedLayer] : styles; 130 136 }, 131 137 sandbox/ahocevar/styles/tests/Format/test_SLD.html
r5311 r5434 19 19 function test_Format_SLD_read(t) { 20 20 t.plan(5); 21 var format = new OpenLayers.Format.SLD();22 var styles = format.read(this.test_content);21 var styles = new OpenLayers.Format.SLD().read(this.test_content, 22 {withNamedLayer: true}); 23 23 24 var testLayer = format.content.namedLayer.TestLayer;24 var testLayer = styles[1].TestLayer; 25 25 26 26 t.ok(testLayer.foo != undefined, "SLD correctly reads a UserStyle named \"foo\""); … … 28 28 t.eq(testLayer.foo.rules[0].name, "bar", "The first rule's name is \"bar\""); 29 29 t.eq(testLayer.foo.rules[0].symbolizer.Polygon.fillColor, "blue", "The fillColor for the Polygon symbolizer is correct"); 30 t.eq(testLayer.foo.name, styles[0] .name, "The content hash of the Format contains the correct rules.");30 t.eq(testLayer.foo.name, styles[0][0].name, "The content hash of the Format contains the correct rules."); 31 31 } 32 32
