OpenLayers OpenLayers

Changeset 4114

Show
Ignore:
Timestamp:
08/30/07 01:59:29 (1 year ago)
Author:
elemoine
Message:

add new vector style property "graphicOpacity"
enabling mixing non-opaque vector geometries with opaque external graphics on the same vector layer
(closes #873)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/vector-features.html

    r3729 r4114  
    1818                    "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 
    1919            map.addLayer(layer); 
     20 
     21            /* 
     22             * Layer style 
     23             */ 
     24            // we want opaque external graphics and non-opaque internal graphics 
     25            var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 
     26            layer_style.fillOpacity = 0.2; 
     27            layer_style.graphicOpacity = 1; 
    2028             
    21             var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 
     29            /* 
     30             * Blue style 
     31             */ 
     32            var style_blue = OpenLayers.Util.extend({}, layer_style); 
    2233            style_blue.strokeColor = "blue";  
    2334            style_blue.fillColor = "blue";  
    2435            style_blue.externalGraphic = "../img/marker.png"; 
    25              
    2636            // each of the three lines below means the same, if only one of 
    2737            // them is active: the image will have a size of 24px, and the 
     
    3141            //style_blue.graphicHeight = 24; 
    3242             
    33             style_blue.fillOpacity = 1; 
     43            /* 
     44             * Green style 
     45             */ 
    3446            var style_green = { 
    3547                strokeColor: "#00FF00", 
     
    3951                pointerEvents: "visiblePainted" 
    4052            }; 
     53 
     54            /* 
     55             * Mark style 
     56             */ 
    4157            var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 
    42              
    4358            // if graphicWidth and graphicHeight are both set, the aspect ratio 
    4459            // of the image will be ignored 
    4560            style_mark.graphicWidth = 24; 
    4661            style_mark.graphicHeight = 20; 
    47              
    4862            style_mark.externalGraphic = "../img/marker.png"; 
    4963             
    50             var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry"); 
     64            var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {style: layer_style}); 
    5165             
    5266            // create a point feature 
  • trunk/openlayers/lib/OpenLayers/Feature/Vector.js

    r4110 r4114  
    257257 *  - hoverPointUnit: "%", 
    258258 *  - pointerEvents: "visiblePainted" 
     259 * 
     260 * Other style properties that have no default values: 
     261 * 
     262 *  - externalGraphic, 
     263 *  - graphicWidth, 
     264 *  - graphicHeight, 
     265 *  - graphicOpacity 
    259266 */  
    260267OpenLayers.Feature.Vector.style = { 
  • trunk/openlayers/lib/OpenLayers/Renderer/SVG.js

    r4110 r4114  
    207207                width = width ? width : style.pointRadius*2; 
    208208                height = height ? height : style.pointRadius*2; 
     209                var opacity = style.graphicOpacity || style.fillOpacity; 
    209210                 
    210211                node.setAttributeNS(null, "x", x-(.5*width).toFixed()); 
     
    214215                node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic); 
    215216                node.setAttributeNS(null, "transform", "scale(1,-1)"); 
    216                 node.setAttributeNS(null, "style", "opacity: "+style.fillOpacity); 
     217                node.setAttributeNS(null, "style", "opacity: "+opacity); 
    217218            } else { 
    218219                node.setAttributeNS(null, "r", style.pointRadius); 
  • trunk/openlayers/lib/OpenLayers/Renderer/VML.js

    r4110 r4114  
    211211                node.appendChild(fill); 
    212212            } 
    213             if (style.fillOpacity) { 
     213            // if graphicOpacity is set use it in priority for external graphic 
     214            if (node._geometryClass == "OpenLayers.Geometry.Point" && 
     215                style.externalGraphic && 
     216                style.graphicOpacity) { 
     217                fill.setAttribute("opacity", style.graphicOpacity); 
     218            } else if (style.fillOpacity) { 
    214219                fill.setAttribute("opacity", style.fillOpacity); 
    215220            } 
  • trunk/openlayers/tests/Layer/test_Vector.html

    r4059 r4114  
    158158 
    159159    function test_Layer_Vector_externalGraphic(t) { 
    160            t.plan(8); 
    161            // base layer is needed for getResolution() to return a value, 
    162            // otherwise VML test will fail because style.left and style.top 
    163            // cannot be set 
    164            var baseLayer = new OpenLayers.Layer.WMS("Base Layer", 
    165                    "http://octo.metacarta.com/cgi-bin/mapserv", 
    166                    { map: '/mapdata/vmap_wms.map',  
    167                    layers: 'basic',  
    168                    format: 'image/png'}); 
     160        t.plan(9); 
     161        // base layer is needed for getResolution() to return a value, 
     162        // otherwise VML test will fail because style.left and style.top 
     163        // cannot be set 
     164        var baseLayer = new OpenLayers.Layer.WMS("Base Layer", 
     165                "http://octo.metacarta.com/cgi-bin/mapserv", 
     166                { map: '/mapdata/vmap_wms.map',  
     167               layers: 'basic',  
     168               format: 'image/png'}); 
    169169             
    170170        var layer = new OpenLayers.Layer.Vector("Test Layer"); 
     
    192192                graphicHeight: 16 
    193193        }); 
     194        var customStyle5 = new Object({ 
     195                externalGraphic: 'test.png', 
     196                graphicWidth: 24, 
     197                graphicOpacity: 1 
     198        }); 
    194199                
    195200        var root = layer.renderer.root; 
     
    223228                t.eq(root.firstChild.getAttributeNS(null, 'height'), 
    224229                            customStyle4.graphicHeight.toString(), 
    225                             "given graphicHeight and graphicWidth, both are set: height") 
     230                            "given graphicHeight and graphicWidth, both are set: height"); 
    226231                t.eq(root.firstChild.getAttributeNS(null, 'width'), 
    227232                            customStyle4.graphicWidth.toString(), 
    228                             "given graphicHeight and graphicWidth, both are set: width") 
     233                            "given graphicHeight and graphicWidth, both are set: width"); 
     234                feature.style = customStyle5; 
     235                layer.drawFeature(feature); 
     236                t.eq(root.firstChild.getAttributeNS(null, 'style'), 
     237                            'opacity: '+customStyle5.graphicOpacity.toString()+';', 
     238                            "graphicOpacity correctly set"); 
    229239        } 
    230240        if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.VML') { 
     
    257267                t.eq(root.firstChild.style.height, 
    258268                            customStyle4.graphicHeight.toString()+'px', 
    259                             "given graphicHeight and graphicWidth, both are set: height") 
     269                            "given graphicHeight and graphicWidth, both are set: height"); 
    260270                t.eq(root.firstChild.style.width, 
    261271                            customStyle4.graphicWidth.toString()+'px', 
    262                             "given graphicHeight and graphicWidth, both are set: width") 
     272                            "given graphicHeight and graphicWidth, both are set: width"); 
     273                feature.style = customStyle5; 
     274                layer.drawFeature(feature); 
     275                var fill = root.firstChild.getElementsByTagName("fill")[0]; 
     276                if (fill == null) fill = root.firstChild.getElementsByTagName("v:fill"); 
     277                var opacity = fill.getAttribute('opacity'); 
     278                t.eq(opacity, 
     279                            customStyle5.graphicOpacity, 
     280                            "graphicOpacity correctly set");  
     281 
    263282        } 
    264283    }