OpenLayers OpenLayers

Ticket #1566: addTypeName2feature.patch

File addTypeName2feature.patch, 1.7 kB (added by openlayers, 6 months ago)

patch for adding typeNames to features read in via GML reader

  • tests/Format/GML.html

    old new  
    1414        t.eq(typeof format.read, "function", "format has a read function");  
    1515        t.eq(typeof format.write, "function", "format has a write function");  
    1616    }  
     17    function test_Format_GML_getTypeName(t) {  
     18        t.plan(2); 
     19        var parser = new OpenLayers.Format.GML(); 
     20        data = parser.read(test_content[1]); 
     21        t.eq(data[0].typeName, 'scribble', 'typeName set correctly once'); 
     22        t.eq(data[1].typeName, 'scribble', 'typeName set correctly twice');  
     23    } 
    1724    function test_Format_GML_getFid(t) {  
    1825        t.plan(2); 
    1926        var parser = new OpenLayers.Format.GML(); 
  • lib/OpenLayers/Format/GML.js

    old new  
    170170        var feature = new OpenLayers.Feature.Vector(geometry, attributes); 
    171171        // assign fid - this can come from a "fid" or "id" attribute 
    172172        var childNode = node.firstChild; 
    173         var fid; 
     173        var typeName, fid; 
    174174        while(childNode) { 
    175175            if(childNode.nodeType == 1) { 
     176                typeName = (childNode.prefix) ? childNode.nodeName.split(":")[1] : childNode.nodeName; 
    176177                fid = childNode.getAttribute("fid") || 
    177178                      childNode.getAttribute("id"); 
    178179                if(fid) { 
     
    181182            } 
    182183            childNode = childNode.nextSibling; 
    183184        } 
    184         feature.fid = fid; 
     185        feature.typeName = typeName; 
     186        feature.fid = fid;       
    185187        return feature; 
    186188    }, 
    187189