OpenLayers OpenLayers

Ticket #1297: 1297-r5851-A0.patch

File 1297-r5851-A0.patch, 3.7 kB (added by ahocevar, 11 months ago)

This patch makes the minScale check inclusive and changes the behavior how rules are applied wrt min/maxScale. The diff of the test also shows that the SE spec was completely misinterpreted previously. Problem 2) is not yet addressed with this patch.

  • lib/OpenLayers/Style.js

    old new  
    113113        } 
    114114        var style = OpenLayers.Util.extend({}, baseStyle); 
    115115         
    116         var draw = true; 
     116        var draw = false; 
    117117 
     118        var rule; 
    118119        for (var i=0; i<this.rules.length; i++) { 
     120            rule = this.rules[i]; 
    119121            // does the rule apply?         
    120             var applies = this.rules[i].evaluate(feature); 
     122            var applies = rule.evaluate(feature); 
     123             
     124            if (rule.minScale || rule.maxScale) { 
     125                var scale = feature.layer.map.getScale(); 
     126            } 
     127             
     128            // check if within minScale/maxScale bounds 
     129            if (rule.minScale) { 
     130                applies = scale >= OpenLayers.Style.createLiteral( 
     131                        rule.minScale, feature); 
     132            } 
     133            if (applies && rule.maxScale) { 
     134                applies = scale < OpenLayers.Style.createLiteral( 
     135                        rule.maxScale, feature); 
     136            } 
     137 
    121138            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 
    133141                // determine which symbolizer (Point, Line, Polygon) to use 
    134142                var symbolizerPrefix = feature.geometry ? 
    135143                        this.getSymbolizerPrefix(feature.geometry) : 
     
    135143                        this.getSymbolizerPrefix(feature.geometry) : 
    136144                        OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; 
    137145 
    138                 // now merge the style with the current style 
     146                // merge the style with the current style 
    139147                var symbolizer = this.rules[i].symbolizer[symbolizerPrefix]; 
    140148                OpenLayers.Util.extend(style, symbolizer); 
    141149            } 
  • tests/test_Style.html

    old new  
    1515    } 
    1616     
    1717    function test_Style_create(t) { 
    18         t.plan(5); 
     18        t.plan(6); 
    1919         
    2020        var map = new OpenLayers.Map("map"); 
    2121         
     
    5050        var createdStyle = style.createStyle(feature); 
    5151        t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly."); 
    5252        t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); 
     53        t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly."); 
    5354 
    5455        map.setCenter(new OpenLayers.LonLat(3,5), 7); 
    5556        // at this scale, the feature should be invisible 
     
    5556        // at this scale, the feature should be invisible 
    5657        createdStyle = style.createStyle(feature); 
    5758        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."); 
     59        t.eq(createdStyle.fillColor, baseStyle.fillColor, "Point symbolizer from base style applied correctly."); 
    5960         
    6061        feature.fid = "2"; 
    6162        // now the rule should not apply