OpenLayers OpenLayers

Changeset 2960

Show
Ignore:
Timestamp:
04/01/07 20:15:59 (2 years ago)
Author:
crschmidt
Message:

Fix SVG renderer. Stephen Woodbridge reported problems with this, and it was
also reported on the users mailing list. The problem appears to be that Firefox
has poor support for circles of very small radius -- below about .0002. Since
units were in geographic units, this just didn't work so well. So:

  • Change coordinate space to be pixel based.
  • Make all x/y operations divided by resolution
  • add getComponentsString, getShortString helpers
  • Redraw nodes totally on every 'reprojectNode' call
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Renderer/SVG.js

    r2818 r2960  
    5151        OpenLayers.Renderer.Elements.prototype.setExtent.apply(this,  
    5252                                                               arguments); 
    53         var extentString = extent.left + " " + -extent.top + " " +  
    54                              extent.getWidth() + " " + extent.getHeight(); 
     53         
     54        var resolution = this.getResolution(); 
     55         
     56        var extentString = extent.left / resolution + " " + -extent.top / resolution + " " +  
     57                             extent.getWidth() / resolution + " " + extent.getHeight() / resolution; 
    5558        this.rendererRoot.setAttributeNS(null, "viewBox", extentString); 
    5659    }, 
     
    109112     */ 
    110113    reprojectNode: function(node) { 
    111         //just reset style (stroke width and point radius), since coord  
    112         // system has not changed 
    113         this.setStyle(node);   
     114        this.drawGeometryNode(node);   
    114115    }, 
    115116     
     
    131132 
    132133        if (node.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { 
    133             var newRadius = style.pointRadius * this.getResolution(); 
    134             node.setAttributeNS(null, "r", newRadius); 
     134            node.setAttributeNS(null, "r", style.pointRadius); 
    135135        } 
    136136         
     
    145145            node.setAttributeNS(null, "stroke", style.strokeColor); 
    146146            node.setAttributeNS(null, "stroke-opacity", style.strokeOpacity); 
    147             var newStrokeWidth = style.strokeWidth * this.getResolution();  
    148             node.setAttributeNS(null, "stroke-width", newStrokeWidth); 
     147            node.setAttributeNS(null, "stroke-width", style.strokeWidth); 
    149148        } else { 
    150149            node.setAttributeNS(null, "stroke", "none"); 
     
    232231     */ 
    233232    drawCircle: function(node, geometry, radius) { 
    234         node.setAttributeNS(null, "cx", geometry.x); 
    235         node.setAttributeNS(null, "cy", geometry.y); 
     233        var resolution = this.getResolution(); 
     234        node.setAttributeNS(null, "cx", geometry.x / resolution); 
     235        node.setAttributeNS(null, "cy", geometry.y / resolution); 
    236236        node.setAttributeNS(null, "r", radius); 
    237237    }, 
     
    242242     */ 
    243243    drawLineString: function(node, geometry) { 
    244         node.setAttributeNS(null, "points", geometry.getComponentsString());   
     244        node.setAttributeNS(null, "points", this.getComponentsString(geometry.components));   
    245245    }, 
    246246     
     
    250250     */ 
    251251    drawLinearRing: function(node, geometry) { 
    252         node.setAttributeNS(null, "points", geometry.getComponentsString()); 
     252        node.setAttributeNS(null, "points", this.getComponentsString(geometry.components)); 
    253253    }, 
    254254     
     
    263263            d += " M"; 
    264264            for (var i = 0; i < linearRing.components.length; i++) { 
    265                 d += " " + linearRing.components[i].toShortString(); 
     265                d += " " + this.getShortString(linearRing.components[i]); 
    266266            } 
    267267        } 
     
    277277     */ 
    278278    drawRectangle: function(node, geometry) { 
    279         node.setAttributeNS(null, "x", geometry.x); 
    280         node.setAttributeNS(null, "y", geometry.y); 
     279        node.setAttributeNS(null, "x", geometry.x / resolution); 
     280        node.setAttributeNS(null, "y", geometry.y / resolution); 
    281281        node.setAttributeNS(null, "width", geometry.width); 
    282282        node.setAttributeNS(null, "height", geometry.height); 
     
    292292        for (var i = 0; i < geometry.components.length; i++) { 
    293293            if ((i%3) == 0 && (i/3) == 0) { 
    294                 d = "M " + geometry.components[i].toShortString(); 
     294                d = "M " + this.getShortString(geometry.components[i]); 
    295295            } else if ((i%3) == 1) { 
    296                 d += " C " + geometry.components[i].toShortString(); 
     296                d += " C " + this.getShortString(geometry.components[i]); 
    297297            } else { 
    298                 d += " " + geometry.components[i].toShortString(); 
     298                d += " " + this.getShortString(geometry.components[i]); 
    299299            } 
    300300        } 
     
    312312        for (var i = 0; i < geometry.components.length; i++) { 
    313313            if ((i%3) == 0 && (i/3) == 0) { 
    314                 d = "M " + geometry.components[i].toShortString(); 
     314                d = "M " + this.getShortString(geometry.components[i]); 
    315315            } else if ((i%3) == 1) { 
    316                 d += " C " + geometry.components[i].toShortString(); 
     316                d += " C " + this.getShortString(geometry.components[i]); 
    317317            } else { 
    318                 d += " " + geometry.components[i].toShortString(); 
     318                d += " " + this.getShortString(geometry.components[i]); 
    319319            } 
    320320        } 
     
    323323    }, 
    324324 
     325    /**  
     326     * @param {Array} components array of points 
     327     */ 
     328    getComponentsString: function(components) { 
     329        var strings = []; 
     330        for(var i = 0; i < components.length; i++) { 
     331            strings.push(this.getShortString(components[i])); 
     332        } 
     333        return strings.join(","); 
     334    }, 
     335 
     336     
     337    /**  
     338     * @param {OpenLayers.Geometry.Point} point 
     339     */ 
     340    getShortString: function(point) { 
     341        var resolution = this.getResolution(); 
     342        return point.x / resolution + "," + point.y / resolution;   
     343         
     344    }, 
     345     
    325346    /** @final @type String */ 
    326347    CLASS_NAME: "OpenLayers.Renderer.SVG"