OpenLayers OpenLayers

Changeset 2657

Show
Ignore:
Timestamp:
03/11/07 00:18:40 (2 years ago)
Author:
crschmidt
Message:

Improve KML support: Add support for both 2 and 3 dimensions.
Also add an example demonstrating a linestring from the Google
Earth examples.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/vector-2.4/lib/OpenLayers/Format/KML.js

    r2655 r2657  
    2626        }     
    2727        var featureNodes = OpenLayers.Ajax.getElementsByTagNameNS(data, this.kmlns, "", "Placemark"); 
    28  
    29         // We only support 2D at the moment 
    30         this.dim = 2; 
    3128         
    3229        var features = []; 
     
    6461            if (p.points) { 
    6562                geom = p.points[0]; 
     63                // TBD Bounds only set for one of multiple geometries 
     64                geom.extendBounds(p.bounds); 
     65            } 
     66         
     67        // match LineString  
     68        } else if (OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, 
     69            this.kmlns, "", "LineString").length != 0) { 
     70            var linestring = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, 
     71                this.kmlns, "", "LineString")[0]; 
     72            p = this.parseCoords(linestring); 
     73            if (p.points) { 
     74                geom = new OpenLayers.Geometry.LineString(p.points); 
    6675                // TBD Bounds only set for one of multiple geometries 
    6776                geom.extendBounds(p.bounds); 
     
    115124    parseCoords: function(xmlNode) { 
    116125        var p = []; 
    117             p.points = []; 
     126        p.points = []; 
    118127        // TBD: Need to handle an array of coordNodes not just coordNodes[0] 
    119128         
    120         var coordString = OpenLayers.Util.getXmlNodeValue(xmlNode); 
     129        var coordNodes = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, this.kmlns, "", "coordinates")[0]; 
     130        var coordString = OpenLayers.Util.getXmlNodeValue(coordNodes); 
    121131         
     132        var firstCoord = coordString.split(" "); 
     133         
     134        while (firstCoord[0] == "")  
     135            firstCoord.shift(); 
     136         
     137        var dim = firstCoord[0].split(",").length; 
     138 
    122139        // Extract an array of Numbers from CoordString 
    123140        var nums = (coordString) ? coordString.split(/[, \n\t]+/) : []; 
     141         
    124142         
    125143        // Remove elements caused by leading and trailing white space 
     
    130148            nums.pop(); 
    131149         
    132         for(i = 0; i < nums.length; i = i + this.dim) { 
     150        for(i = 0; i < nums.length; i = i + dim) { 
    133151            x = parseFloat(nums[i]); 
    134152            y = parseFloat(nums[i+1]);