Ticket #1297: 1297-r5900-A2.patch
| File 1297-r5900-A2.patch, 15.4 kB (added by ahocevar, 1 year ago) |
|---|
-
examples/georss-flickr.html
old new 28 28 29 29 // create a property style that reads the externalGraphic url from 30 30 // the thumbail attribute of the rss item 31 style = new OpenLayers.Style({ 32 externalGraphic: "${thumbnail}", 33 pointRadius: 20}); 31 style = new OpenLayers.Style({externalGraphic: "${thumbnail}"}); 34 32 35 33 // create a rule with a point symbolizer that will make the thumbnail 36 34 // larger if the title of the rss item conatins "powder" … … 41 39 symbolizer: {"Point": {pointRadius: 30}}}); 42 40 rule.value2regex("*"); 43 41 44 style.addRules([rule]); 42 // If the above rule does not apply, use a smaller pointRadius. 43 var elseRule = new OpenLayers.Rule({ 44 symbolizer: {"Point": {pointRadius: 20}}}); 45 46 style.addRules([rule, elseRule]); 45 47 46 48 markerLayer = new OpenLayers.Layer.Vector("", {style: style}); 47 49 map.addLayer(markerLayer); -
examples/sld.html
old new 65 65 OpenLayers.Feature.Vector.style["select"]; 66 66 hover = new OpenLayers.Control.SelectFeature(gmlLayers[2], { 67 67 selectStyle: waterStyle["Hover Styler"], 68 hover: true, 69 select: select 68 hover: true 70 69 }); 71 70 map.addControl(hover); 72 71 hover.activate(); … … 72 71 hover.activate(); 73 72 } 74 73 75 // replaces OpenLayers.Control.Select.select76 var select = function(feature) {77 // store layer style78 var style = feature.layer.style;79 // set temporary layer style for hover rendering80 feature.layer.style = hover.selectStyle;81 OpenLayers.Control.SelectFeature.prototype.select.apply(hover, arguments);82 // restore layer style83 feature.layer.style = style;84 }85 86 74 // set a new style when the radio button changes 87 75 function setStyle(styleName) { 88 76 // change the style of the features of the WaterBodies layer -
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 106 106 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 107 107 } 108 108 109 options = options || {}; 109 110 OpenLayers.Util.applyDefaults(options, { 110 111 withNamedLayer: false, 111 112 overrideDefaultStyleKey: true … … 206 207 if (filter && filter.length > 0) { 207 208 var rule = this.parseFilter(filter[0]); 208 209 } else { 209 // rule applies to all features 210 // rule applies to all features (ElseFilter) 210 211 var rule = new OpenLayers.Rule(); 211 212 } 212 213 rule.name = name; … … 218 219 xmlNode, this.sldns, "MinScaleDenominator" 219 220 ); 220 221 if (minScale && minScale.length > 0) { 221 rule.minScale = parseFloat(this.getChildValue(minScale[0])); 222 rule.minScaleDenominator = 223 parseFloat(this.getChildValue(minScale[0])); 222 224 } 223 225 224 226 // MaxScaleDenominator … … 226 228 xmlNode, this.sldns, "MaxScaleDenominator" 227 229 ); 228 230 if (maxScale && maxScale.length > 0) { 229 rule.maxScale = parseFloat(this.getChildValue(maxScale[0])); 231 rule.maxScaleDenominator = 232 parseFloat(this.getChildValue(maxScale[0])); 230 233 } 231 234 232 235 // 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,45 44 maxScaleDenominator: null, 45 46 46 /** 47 47 * Constructor: OpenLayers.Rule 48 48 * Creates a Rule. … … 88 88 }, 89 89 90 90 CLASS_NAME: "OpenLayers.Rule" 91 91 -
lib/OpenLayers/Style.js
old new 101 101 * style. 102 102 * 103 103 * Parameters: 104 * feature - {<OpenLayers.Feature>} feature to evaluate rules for 105 * baseStyle - {Object} hash of styles feature styles to extend 104 * feature - {<OpenLayers.Feature>} feature to evaluate rules for 105 * options - {Object} additional options that modify the returned result 106 * of this method. 107 * - <extend> {Boolean} if set to false, output will be an 108 * array of styles (one for every rule that 109 * applies) instead of one style that gets 110 * extended with every rule that applies. 111 * Default is true. 106 112 * 107 113 * Returns: 108 114 * {<OpenLayers.Feature.Vector.style>} hash of feature styles … … 107 113 * Returns: 108 114 * {<OpenLayers.Feature.Vector.style>} hash of feature styles 109 115 */ 110 createStyle: function(feature, baseStyle) { 111 if (!baseStyle) { 112 baseStyle = this.defaultStyle; 113 } 114 var style = OpenLayers.Util.extend({}, baseStyle); 116 createStyle: function(feature, options) { 117 options = options || {}; 118 OpenLayers.Util.applyDefaults(options, { 119 extend: true 120 }); 121 122 var style = OpenLayers.Util.extend({}, this.defaultStyle); 115 123 116 var draw = true; 124 var rules = this.rules; 125 var draw = rules.length == 0 ? true : false; 117 126 118 for (var i=0; i<this.rules.length; i++) { 127 var styles = []; 128 var rule; 129 for (var i=0; i<rules.length; i++) { 130 rule = rules[i]; 119 131 // does the rule apply? 120 var applies = this.rules[i].evaluate(feature); 132 var applies = rule.evaluate(feature); 133 134 if (rule.minScaleDenominator || rule.maxScaleDenominator) { 135 var scale = feature.layer.map.getScale(); 136 } 137 138 // check if within minScale/maxScale bounds 139 if (rule.minScaleDenominator) { 140 applies = scale >= OpenLayers.Style.createLiteral( 141 rule.minScaleDenominator, feature); 142 } 143 if (applies && rule.maxScaleDenominator) { 144 applies = scale < OpenLayers.Style.createLiteral( 145 rule.maxScaleDenominator, feature); 146 } 147 148 if (draw && rule.CLASS_NAME == "OpenLayers.Rule") { 149 // apply plain rules only if no other applied (ElseFilter) 150 applies = false; 151 } 152 121 153 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 154 draw = true; 155 133 156 // determine which symbolizer (Point, Line, Polygon) to use 134 157 var symbolizerPrefix = feature.geometry ? 135 158 this.getSymbolizerPrefix(feature.geometry) : … … 135 158 this.getSymbolizerPrefix(feature.geometry) : 136 159 OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; 137 160 138 // nowmerge the style with the current style161 // merge the style with the current style 139 162 var symbolizer = this.rules[i].symbolizer[symbolizerPrefix]; 140 OpenLayers.Util.extend(style, symbolizer); 163 if (options.extend == false) { 164 style = OpenLayers.Util.extend({}, this.defaultStyle); 165 OpenLayers.Util.extend(style, symbolizer); 166 styles.push(style); 167 } else { 168 OpenLayers.Util.extend(style, symbolizer); 169 } 141 170 } 142 171 } 143 172 144 style.display = draw ? "" : "none";145 146 173 // calculate literals for all styles in the propertyStyles cache 174 if (options.extend == true) { 175 this.createLiterals(style, feature); 176 style.display = draw ? "" : "none"; 177 } 178 179 return options.extend == false ? styles : style; 180 }, 181 182 /** 183 * Method: createLiterals 184 * creates literals for all style properties that have an entry in 185 * <this.propertyStyles>. 186 * 187 * Parameters: 188 * style - {Object} style to create literals for. Will be modified 189 * inline. 190 * feature - {<OpenLayers.Feature.Vector>} feature to take properties from 191 * 192 * Returns; 193 * {Object} the modified style 194 */ 195 createLiterals: function(style, feature) { 147 196 for (var i in this.propertyStyles) { 148 197 style[i] = OpenLayers.Style.createLiteral(style[i], feature); 149 198 } 150 151 199 return style; 152 200 }, 153 201 -
tests/test_Style.html
old new 15 15 } 16 16 17 17 function test_Style_create(t) { 18 t.plan( 5);18 t.plan(11); 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 visible 58 map.setCenter(new OpenLayers.LonLat(3,5), 10); 59 60 var createdStyles = style.createStyle(feature, {extend: false}); 61 t.eq(createdStyles[0].fillColor, "green", "Returned styles array is correct if extend option set to false"); 62 63 // at this scale, the feature should be green 50 64 var createdStyle = style.createStyle(feature); 51 65 t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly."); 52 66 t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 67 t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly."); 68 69 map.setCenter(new OpenLayers.LonLat(3,5), 9); 70 // at this scale, the feature should be red 71 createdStyle = style.createStyle(feature); 72 t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 73 t.eq(createdStyle.fillColor, "yellow", "Point symbolizer from rule applied correctly."); 74 75 map.setCenter(new OpenLayers.LonLat(3,5), 8); 76 // at this scale, the feature should be yellow 77 createdStyle = style.createStyle(feature); 78 t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 79 t.eq(createdStyle.fillColor, "red", "Point symbolizer from rule applied correctly."); 53 80 54 81 map.setCenter(new OpenLayers.LonLat(3,5), 7); 55 82 // at this scale, the feature should be invisible … … 55 82 // at this scale, the feature should be invisible 56 83 createdStyle = style.createStyle(feature); 57 84 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.");85 t.eq(createdStyle.fillColor, baseStyle.fillColor, "Point symbolizer from base style applied correctly."); 59 86 60 87 feature.fid = "2"; 61 88 // now the rule should not apply … … 62 89 63 90 createdStyle = style.createStyle(feature); 64 91 t.eq(createdStyle.fillColor, baseStyle.fillColor, "Correct style for rule that does not apply to fid=\"2\"."); 65 66 92 } 67 93 68 94 function test_Style_destroy(t) {
