Ticket #1297: 1297-r5851-A1.patch
| File 1297-r5851-A1.patch, 9.9 kB (added by ahocevar, 1 year ago) |
|---|
-
examples/tasmania/sld-tasmania.xml
old new 51 51 </sld:Stroke> 52 52 </sld:PolygonSymbolizer> 53 53 </sld:Rule> 54 <sld:Rule> 55 <sld:Name>testRuleNameElse</sld:Name> 56 <sld:Title>title</sld:Title> 57 <sld:Abstract>Abstract</sld:Abstract> 58 <ogc:ElseFilter/> 59 </sld:Rule> 54 60 </sld:FeatureTypeStyle> 55 61 </sld:UserStyle> 56 62 … … 113 119 </sld:Stroke> 114 120 </sld:PolygonSymbolizer> 115 121 </sld:Rule> 116 122 <sld:Rule> 123 <sld:Name>testRuleNameHoverElse</sld:Name> 124 <sld:Title>title</sld:Title> 125 <sld:Abstract>Abstract</sld:Abstract> 126 <ogc:ElseFilter/> 127 </sld:Rule> 117 128 </sld:FeatureTypeStyle> 118 129 </sld:UserStyle> 119 130 -
lib/OpenLayers/Format/SLD.js
old new 176 176 ); 177 177 178 178 if (ruleNodes.length > 0) { 179 var rules = userStyle.rules; 180 var ruleName; 179 var rule, ruleName; 181 180 for (var i=0; i<ruleNodes.length; i++) { 182 181 ruleName = this.parseProperty(ruleNodes[i], this.sldns, "Name"); 183 rules.push(this.parseRule(ruleNodes[i], ruleName)); 182 var rule = (this.parseRule(ruleNodes[i], ruleName)); 183 if (rule instanceof OpenLayers.Rule) { 184 // ElseFilter - insert at beginning 185 userStyle.rules = [rule].concat(userStyle.rules); 186 } else { 187 userStyle.rules.push(rule); 188 } 184 189 } 185 190 } 186 191 … … 206 211 if (filter && filter.length > 0) { 207 212 var rule = this.parseFilter(filter[0]); 208 213 } else { 209 // rule applies to all features 214 // rule applies to all features (ElseFilter) 210 215 var rule = new OpenLayers.Rule(); 211 216 } 212 217 rule.name = name; … … 218 223 xmlNode, this.sldns, "MinScaleDenominator" 219 224 ); 220 225 if (minScale && minScale.length > 0) { 221 rule.minScale = parseFloat(this.getChildValue(minScale[0])); 226 rule.minScaleDenominator = 227 parseFloat(this.getChildValue(minScale[0])); 222 228 } 223 229 224 230 // MaxScaleDenominator … … 226 232 xmlNode, this.sldns, "MaxScaleDenominator" 227 233 ); 228 234 if (maxScale && maxScale.length > 0) { 229 rule.maxScale = parseFloat(this.getChildValue(maxScale[0])); 235 rule.maxScaleDenominator = 236 parseFloat(this.getChildValue(maxScale[0])); 230 237 } 231 238 232 239 // STYLES -
lib/OpenLayers/Rule.js
old new 28 28 symbolizer: null, 29 29 30 30 /** 31 * APIProperty: minScale 31 * APIProperty: minScaleDenominator 32 32 * {Number} or {String} minimum scale at which to draw the feature. 33 33 * In the case of a String, this can be a combination of text and 34 34 * propertyNames in the form "literal ${propertyName}" … … 33 33 * In the case of a String, this can be a combination of text and 34 34 * propertyNames in the form "literal ${propertyName}" 35 35 */ 36 minScale : null,36 minScaleDenominator: null, 37 37 38 38 /** 39 * APIProperty: maxScale 39 * APIProperty: maxScaleDenominator 40 40 * {Number} or {String} maximum scale at which to draw the feature. 41 41 * In the case of a String, this can be a combination of text and 42 42 * propertyNames in the form "literal ${propertyName}" … … 41 41 * In the case of a String, this can be a combination of text and 42 42 * propertyNames in the form "literal ${propertyName}" 43 43 */ 44 maxScale : null,44 maxScaleDenominator: null, 45 45 46 46 /** 47 47 * Constructor: OpenLayers.Rule -
lib/OpenLayers/Style.js
old new 113 113 } 114 114 var style = OpenLayers.Util.extend({}, baseStyle); 115 115 116 var draw = t rue;116 var draw = this.rules.length == 0 ? true : false; 117 117 118 var rule; 118 119 for (var i=0; i<this.rules.length; i++) { 120 rule = this.rules[i]; 119 121 // does the rule apply? 120 var applies = this.rules[i].evaluate(feature); 122 var applies = rule.evaluate(feature); 123 124 if (rule.minScaleDenominator || rule.maxScaleDenominator) { 125 var scale = feature.layer.map.getScale(); 126 } 127 128 // check if within minScale/maxScale bounds 129 if (rule.minScaleDenominator) { 130 applies = scale >= OpenLayers.Style.createLiteral( 131 rule.minScaleDenominator, feature); 132 } 133 if (applies && rule.maxScaleDenominator) { 134 applies = scale < OpenLayers.Style.createLiteral( 135 rule.maxScaleDenominator, feature); 136 } 137 121 138 if (applies) { 122 // check if within minScale/maxScale bounds 123 var scale = feature.layer.map.getScale(); 124 if (this.rules[i].minScale) { 125 draw = scale > OpenLayers.Style.createLiteral( 126 this.rules[i].minScale, feature); 127 } 128 if (draw && this.rules[i].maxScale) { 129 draw = scale < OpenLayers.Style.createLiteral( 130 this.rules[i].maxScale, feature); 131 } 132 139 draw = true; 140 133 141 // determine which symbolizer (Point, Line, Polygon) to use 134 142 var symbolizerPrefix = feature.geometry ? 135 143 this.getSymbolizerPrefix(feature.geometry) : … … 135 143 this.getSymbolizerPrefix(feature.geometry) : 136 144 OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; 137 145 138 // nowmerge the style with the current style146 // merge the style with the current style 139 147 var symbolizer = this.rules[i].symbolizer[symbolizerPrefix]; 140 148 OpenLayers.Util.extend(style, symbolizer); 141 149 } -
tests/test_Style.html
old new 15 15 } 16 16 17 17 function test_Style_create(t) { 18 t.plan( 5);18 t.plan(10); 19 19 20 20 var map = new OpenLayers.Map("map"); 21 21 … … 27 27 28 28 var style = new OpenLayers.Style(baseStyle); 29 29 30 var rule = new OpenLayers.Rule.FeatureId({30 var rule1 = new OpenLayers.Rule.FeatureId({ 31 31 fids: ["1"], 32 32 symbolizer: {"Point": {fillColor: "green"}}, 33 maxScale: 2000000}); 34 style.addRules([rule]); 33 maxScaleDenominator: 500000}); 34 var rule2 = new OpenLayers.Rule.FeatureId({ 35 fids: ["1"], 36 symbolizer: {"Point": {fillColor: "yellow"}}, 37 minScaleDenominator: 500000, 38 maxScaleDenominator: 1000000}); 39 var rule3 = new OpenLayers.Rule.FeatureId({ 40 fids: ["1"], 41 symbolizer: {"Point": {fillColor: "red"}}, 42 minScaleDenominator: 1000000, 43 maxScaleDenominator: 2500000}); 44 style.addRules([rule1, rule2, rule3]); 35 45 36 46 var feature = new OpenLayers.Feature.Vector( 37 47 new OpenLayers.Geometry.Point(3,5), … … 45 55 map.addLayer(layer); 46 56 map.setBaseLayer(layer); 47 57 48 map.setCenter(new OpenLayers.LonLat(3,5), 8);49 // at this scale, the feature should be visible58 map.setCenter(new OpenLayers.LonLat(3,5), 10); 59 // at this scale, the feature should be green 50 60 var createdStyle = style.createStyle(feature); 51 61 t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly."); 52 62 t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 63 t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly."); 64 65 map.setCenter(new OpenLayers.LonLat(3,5), 9); 66 // at this scale, the feature should be red 67 createdStyle = style.createStyle(feature); 68 t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 69 t.eq(createdStyle.fillColor, "yellow", "Point symbolizer from rule applied correctly."); 70 71 map.setCenter(new OpenLayers.LonLat(3,5), 8); 72 // at this scale, the feature should be yellow 73 createdStyle = style.createStyle(feature); 74 t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 75 t.eq(createdStyle.fillColor, "red", "Point symbolizer from rule applied correctly."); 53 76 54 77 map.setCenter(new OpenLayers.LonLat(3,5), 7); 55 78 // at this scale, the feature should be invisible … … 55 78 // at this scale, the feature should be invisible 56 79 createdStyle = style.createStyle(feature); 57 80 t.eq(createdStyle.display, "none", "Feature is invisible at scale "+map.getScale()); 58 t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule for fid=\"1\"applied correctly.");81 t.eq(createdStyle.fillColor, baseStyle.fillColor, "Point symbolizer from base style applied correctly."); 59 82 60 83 feature.fid = "2"; 61 84 // now the rule should not apply
