OpenLayers OpenLayers

Ticket #1172: Renderer.diff

File Renderer.diff, 10.0 kB (added by ahocevar, 1 year ago)

This is the bugfix. This patch is to be applied after testing with the patched vector-features.html example, to see the before/after effect. The postDraw hack for the fillColor flaw in IE is only needed if fillcolor is "none", so we only check for that

  • lib/OpenLayers/Renderer/Elements.js

    old new  
    8484    /**  
    8585     * Method: getNodeType 
    8686     * This function is in charge of asking the specific renderer which type 
    87      *     of node to create for the given geometry. All geometries in an  
    88      *     Elements-based renderer consist of one node and some attributes. W
    89      *     have the nodeFactory() function which creates a node for us, but it 
    90      *     takes a 'type' as input, and that is precisely what this function  
    91      *     tells us.   
     87     *     of node to create for the given geometry and style. All geometries 
     88     *     in an Elements-based renderer consist of one node and som
     89     *     attributes. We have the nodeFactory() function which creates a node 
     90     *     for us, but it takes a 'type' as input, and that is precisely what 
     91     *     this function tells us.   
    9292     *   
    9393     * Parameters: 
    9494     * geometry - {<OpenLayers.Geometry>} 
     95     * style - {Object} 
    9596     *  
    9697     * Returns: 
    9798     * {String} The corresponding node type for the specified geometry 
     
    9697     * Returns: 
    9798     * {String} The corresponding node type for the specified geometry 
    9899     */ 
    99     getNodeType: function(geometry) { }, 
     100    getNodeType: function(geometry, style) { }, 
    100101 
    101102    /**  
    102103     * Method: drawGeometry  
     
    122123        }; 
    123124 
    124125        //first we create the basic node and add it to the root 
    125         var nodeType = this.getNodeType(geometry); 
     126        var nodeType = this.getNodeType(geometry, style); 
    126127        var node = this.nodeFactory(geometry.id, nodeType); 
    127128        node._featureId = featureId; 
    128129        node._geometryClass = geometry.CLASS_NAME; 
     
    131132        //now actually draw the node, and style it 
    132133        node = this.drawGeometryNode(node, geometry); 
    133134        this.root.appendChild(node); 
     135        this.postDraw(node); 
    134136    }, 
    135137 
    136138    /** 
     
    184186    }, 
    185187     
    186188    /** 
     189     * Method: postDraw 
     190     * Things that have do be done after the geometry node is appended 
     191     * to its parent node. To be overridden by subclasses. 
     192     *  
     193     * Parameters: 
     194     * node - {DOMElement} 
     195     */ 
     196    postDraw: function(node) {}, 
     197     
     198    /** 
    187199     * Method: drawPoint 
    188200     * Virtual function for drawing Point Geometry.  
    189201     * Should be implemented by subclasses. 
  • lib/OpenLayers/Renderer/SVG.js

    old new  
    147147     *  
    148148     * Parameters: 
    149149     * geometry - {<OpenLayers.Geometry>} 
     150     * style - {Object} 
    150151     *  
    151152     * Returns: 
    152153     * {String} The corresponding node type for the specified geometry 
     
    151152     * Returns: 
    152153     * {String} The corresponding node type for the specified geometry 
    153154     */ 
    154     getNodeType: function(geometry) { 
     155    getNodeType: function(geometry, style) { 
    155156        var nodeType = null; 
    156157        switch (geometry.CLASS_NAME) { 
    157158            case "OpenLayers.Geometry.Point": 
    158                 nodeType = "circle"; 
     159                nodeType = style.externalGraphic ? "image" : "circle"; 
    159160                break; 
    160161            case "OpenLayers.Geometry.Rectangle": 
    161162                nodeType = "rect"; 
     
    196197        options = options || node._options; 
    197198        if (node._geometryClass == "OpenLayers.Geometry.Point") { 
    198199            if (style.externalGraphic) { 
    199                 // remove old node 
    200                 var id = node.getAttributeNS(null, "id"); 
    201200                var x = parseFloat(node.getAttributeNS(null, "cx")); 
    202201                var y = parseFloat(node.getAttributeNS(null, "cy")); 
    203                 var _featureId = node._featureId; 
    204                 var _geometryClass = node._geometryClass; 
    205                 var _style = node._style; 
    206202                 
    207                 // create new image node 
    208                 node = this.createNode("image", id); 
    209                 node._featureId = _featureId; 
    210                 node._geometryClass = _geometryClass; 
    211                 node._style = _style; 
    212  
    213                 // now style the new node 
    214203                if (style.graphicWidth && style.graphicHeight) { 
    215204                  node.setAttributeNS(null, "preserveAspectRatio", "none"); 
    216205                } 
     
    222211                    style.graphicXOffset : -(0.5 * width); 
    223212                var yOffset = (style.graphicYOffset != undefined) ? 
    224213                    style.graphicYOffset : -(0.5 * height); 
     214 
    225215                var opacity = style.graphicOpacity || style.fillOpacity; 
    226216                 
    227217                node.setAttributeNS(null, "x", (x + xOffset).toFixed()); 
  • lib/OpenLayers/Renderer/VML.js

    old new  
    105105 
    106106    /** 
    107107     * Method: getNodeType 
    108      * Get the noode type for a geometry 
     108     * Get the noode type for a geometry and style 
    109109     * 
    110110     * Parameters: 
    111111     * geometry - {<OpenLayers.Geometry>} 
     112     * style - {Object} 
    112113     * 
    113114     * Returns: 
    114115     * {String} The corresponding node type for the specified geometry 
     
    113114     * Returns: 
    114115     * {String} The corresponding node type for the specified geometry 
    115116     */ 
    116     getNodeType: function(geometry) { 
     117    getNodeType: function(geometry, style) { 
    117118        var nodeType = null; 
    118119        switch (geometry.CLASS_NAME) { 
    119120            case "OpenLayers.Geometry.Point": 
    120                 nodeType = "v:oval"; 
     121                nodeType = style.externalGraphic ? "v:rect" : "v:oval"; 
    121122                break; 
    122123            case "OpenLayers.Geometry.Rectangle": 
    123124                nodeType = "v:rect"; 
     
    153154         
    154155        if (node._geometryClass == "OpenLayers.Geometry.Point") { 
    155156            if (style.externalGraphic) { 
    156                 // remove old node 
    157                 var id = node.id; 
    158                 var _featureId = node._featureId; 
    159                 var _geometryClass = node._geometryClass; 
    160                 var _style = node._style; 
    161                  
    162                 // create new image node 
    163                 node = this.createNode("v:rect", id); 
    164                 var fill = this.createNode("v:fill", id+"_image"); 
    165                 node.appendChild(fill); 
    166                 node._featureId = _featureId; 
    167                 node._geometryClass = _geometryClass; 
    168                 node._style = _style; 
    169                  
    170                 fill.src = style.externalGraphic; 
    171                 fill.type = "frame"; 
    172                 node.style.flip = "y"; 
    173                  
    174                 if (!(style.graphicWidth && style.graphicHeight)) { 
    175                   fill.aspect = "atmost"; 
    176                 } 
    177                  
    178                 // now style the new node 
    179157                var width = style.graphicWidth || style.graphicHeight; 
    180158                var height = style.graphicHeight || style.graphicWidth; 
    181159                width = width ? width : style.pointRadius*2; 
     
    192170                node.style.width = width; 
    193171                node.style.height = height;     
    194172                 
    195                 // modify fill style for rect styling below 
     173                // modify style/options for fill and stroke styling below 
    196174                style.fillColor = "none"; 
    197                 style.strokeColor = "none"
     175                options.isStroked = false
    198176                          
    199177            } else { 
    200178                this.drawCircle(node, geometry, style.pointRadius); 
     
    216194        } else { 
    217195            if (!fill) { 
    218196                fill = this.createNode('v:fill', node.id + "_fill"); 
     197 
     198                if (style.fillOpacity) { 
     199                    fill.setAttribute("opacity", style.fillOpacity); 
     200                } 
     201 
     202                if (node._geometryClass == "OpenLayers.Geometry.Point" && 
     203                        style.externalGraphic) { 
     204 
     205                    // override fillOpacity 
     206                    if (style.graphicOpacity) { 
     207                        fill.setAttribute("opacity", style.graphicOpacity); 
     208                    } 
     209                     
     210                    fill.setAttribute("src", style.externalGraphic); 
     211                    fill.setAttribute("type", "frame"); 
     212                    node.style.flip = "y"; 
     213                     
     214                    if (!(style.graphicWidth && style.graphicHeight)) { 
     215                      fill.aspect = "atmost"; 
     216                    } 
     217                } 
    219218                node.appendChild(fill); 
    220219            } 
    221             // if graphicOpacity is set use it in priority for external graphic 
    222             if (node._geometryClass == "OpenLayers.Geometry.Point" && 
    223                 style.externalGraphic && 
    224                 style.graphicOpacity) { 
    225                 fill.setAttribute("opacity", style.graphicOpacity); 
    226             } else if (style.fillOpacity) { 
    227                 fill.setAttribute("opacity", style.fillOpacity); 
    228             } 
    229220        } 
    230221 
    231222 
     
    257248        return node; 
    258249    }, 
    259250 
     251    /** 
     252     * Method: postDraw 
     253     * Some versions of Internet Explorer seem to be unable to set fillcolor 
     254     * and strokecolor to "none" correctly before the fill node is appended to 
     255     * a visible vml node. This method takes care of that and sets fillcolor 
     256     * and strokecolor again if needed. 
     257     *  
     258     * Parameters: 
     259     * node - {DOMElement} 
     260     */ 
     261    postDraw: function(node) { 
     262        var fillColor = node._style.fillColor; 
     263        var strokeColor = node._style.strokeColor; 
     264        if (fillColor == "none" && 
     265                node.getAttribute("fillcolor") != fillColor) { 
     266            node.setAttribute("fillcolor", fillColor); 
     267        } 
     268        if (strokeColor == "none" && 
     269                node.getAttribute("strokecolor") != strokeColor) { 
     270            node.setAttribute("strokecolor", strokeColor) 
     271        } 
     272    }, 
     273 
    260274 
    261275    /** 
    262276     * Method: setNodeDimension