OpenLayers OpenLayers

Changeset 5392

Show
Ignore:
Timestamp:
12/13/07 05:24:51 (1 year ago)
Author:
fredj
Message:

Speed up geometry rendering with VML by replacing string concatenation by array
concatenation and joining. Thanks tschaub for the patch optimization and
review. (Closes #1095)

Files:

Legend:

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

    r5373 r5392  
    461461 
    462462        var resolution = this.getResolution(); 
    463  
    464         var path = "m"; 
    465         for (var i = 0; i < geometry.components.length; i++) { 
    466             var x = (geometry.components[i].x/resolution); 
    467             var y = (geometry.components[i].y/resolution); 
    468             path += " " + x.toFixed() + "," + y.toFixed() + " l "; 
    469         } 
    470         if (closeLine) { 
    471             path += " x"; 
    472         } 
    473         path += " e"; 
    474  
    475         node.path = path; 
     463        var numComponents = geometry.components.length; 
     464        var parts = new Array(numComponents); 
     465 
     466        var comp, x, y; 
     467        for (var i = 0; i < numComponents; i++) { 
     468            comp = geometry.components[i]; 
     469            x = (comp.x/resolution); 
     470            y = (comp.y/resolution); 
     471            parts[i] = " " + x.toFixed() + "," + y.toFixed() + " l "; 
     472        } 
     473        var end = (closeLine) ? " x e" : " e"; 
     474        node.path = "m" + parts.join("") + end; 
    476475    }, 
    477476 
     
    489488        var resolution = this.getResolution(); 
    490489     
    491         var path = ""; 
     490        var path = []; 
     491        var linearRing, i, comp, x, y; 
    492492        for (var j = 0; j < geometry.components.length; j++) { 
    493             var linearRing = geometry.components[j]; 
    494  
    495             path += "m"; 
    496             for (var i = 0; i < linearRing.components.length; i++) { 
    497                 var x = linearRing.components[i].x / resolution; 
    498                 var y = linearRing.components[i].y / resolution; 
    499                 path += " " + x.toFixed() + "," + y.toFixed(); 
     493            linearRing = geometry.components[j]; 
     494 
     495            path.push("m"); 
     496            for (i = 0; i < linearRing.components.length; i++) { 
     497                comp = linearRing.components[i]; 
     498                x = comp.x / resolution; 
     499                y = comp.y / resolution; 
     500                path.push(" " + x.toFixed() + "," + y.toFixed()); 
    500501                if (i==0) { 
    501                     path += " l"
     502                    path.push(" l")
    502503                } 
    503504            } 
    504             path += " x "
    505         } 
    506         path += "e"
    507         node.path = path
     505            path.push(" x ")
     506        } 
     507        path.push("e")
     508        node.path = path.join("")
    508509    }, 
    509510 
     
    538539        var resolution = this.getResolution(); 
    539540     
    540         var path = ""; 
     541        var path = []; 
     542        var comp, x, y; 
    541543        for (var i = 0; i < geometry.components.length; i++) { 
    542             var x = geometry.components[i].x / resolution; 
    543             var y = geometry.components[i].y / resolution; 
     544            comp = geometry.components[i]; 
     545            x = comp.x / resolution; 
     546            y = comp.y / resolution; 
    544547            if ((i%3)==0 && (i/3)==0) { 
    545                 path += "m"
     548                path.push("m")
    546549            } else if ((i%3)==1) { 
    547                 path += " c"
    548             } 
    549             path += " " + x + "," + y
    550         } 
    551         path += " x e"
    552  
    553         node.path = path
     550                path.push(" c")
     551            } 
     552            path.push(" " + x + "," + y)
     553        } 
     554        path.push(" x e")
     555 
     556        node.path = path.join("")
    554557    }, 
    555558