OpenLayers OpenLayers

Ticket #1546: gml.patch

File gml.patch, 4.9 kB (added by tschaub, 4 months ago)

add geometryTypes (non-api) property

  • tests/Format/GML.html

    old new  
    325325        t.eq(output, multilinestring_xy, "MultiLine geometry round trips correctly."); 
    326326    } 
    327327     
     328    function test_geometryTypes(t) { 
     329        t.plan(8); 
     330        var parser = new OpenLayers.Format.GML(); 
     331         
     332        t.ok(parser.geometryTypes === null, "geometryTypes is null by default"); 
     333         
     334        // test reading with null geometryTypes 
     335        var data = parser.read(test_content[1]); 
     336        t.eq(data.length, 2, "2 features read with null geometryTypes."); 
     337         
     338        // test reading with ["Point"] geometryTypes 
     339        parser.geometryTypes = ["Point"]; 
     340        data = parser.read(test_content[1]); 
     341        t.eq(data.length, 1, "1 feature read with ['Point'] geometryTypes."); 
     342        t.ok(data[0].geometry instanceof OpenLayers.Geometry.Point, 
     343             "only point geom read with ['Point'] geometryTypes."); 
     344         
     345        // test reading with ["Polygon"] geometryTypes 
     346        parser.geometryTypes = ["Polygon"]; 
     347        data = parser.read(test_content[1]); 
     348        t.eq(data.length, 1, "1 feature read with ['Polygon'] geometryTypes."); 
     349        t.ok(data[0].geometry instanceof OpenLayers.Geometry.Polygon, 
     350             "only point geom read with ['Polygon'] geometryTypes."); 
    328351 
     352        // test reading with ["Point", "Polygon"] geometryTypes 
     353        parser.geometryTypes = ["Point", "Polygon"]; 
     354        data = parser.read(test_content[1]); 
     355        t.eq(data.length, 2, "2 feature read with ['Point', 'Polygon'] geometryTypes."); 
     356         
     357        // test reading with ["foo"] geometryTypes 
     358        parser.geometryTypes = ["foo"]; 
     359        data = parser.read(test_content[1]); 
     360        alert('f'); 
     361        t.eq(data.length, 0, "0 features read with ['foo'] geometryTypes."); 
     362 
     363    } 
     364 
    329365    var test_content = ['<?xml version="1.0" encoding="utf-8" ?>\n<ogr:FeatureCollection\n     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n     xsi:schemaLocation="http://ogr.maptools.org/ testoutput.xsd"\n     xmlns:ogr="http://ogr.maptools.org/"\n     xmlns:gml="http://www.opengis.net/gml">\n  <gml:boundedBy>\n    <gml:Box>\n      <gml:coord><gml:X>-1254041.389711702</gml:X><gml:Y>250906.9515983529</gml:Y></gml:coord>\n      <gml:coord><gml:X>-634517.1199908922</gml:X><gml:Y>762236.2940800377</gml:Y></gml:coord>\n    </gml:Box>\n  </gml:boundedBy>                    \n  <gml:featureMember>\n    <ogr:states fid="F0">\n      <ogr:geometryProperty><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>\n      <ogr:NAME>WY</ogr:NAME>\n    <ogr:LONGNAME><![CDATA[Wyoming]]></ogr:LONGNAME>\n    </ogr:states>\n  </gml:featureMember>\n</ogr:FeatureCollection>\n', 
    330366 '<wfs:FeatureCollection' +  
    331367 '   xmlns:fs="http://example.com/featureserver"' +  
  • lib/OpenLayers/Format/GML.js

    old new  
    5454     * {String} Name of geometry element.  Defaults to "geometry". 
    5555     */ 
    5656    geometryName: "geometry", 
     57 
     58    /** 
     59     * Property: geometryTypes 
     60     * {Array(String)} Allowed types of geometry element.  Defaults to null. 
     61     *     If non-null, the geometryTypes value must be an array that includes 
     62     *     one or more of the following strings: "MultiPolygon", "Polygon", 
     63     *     "MultiLineString", "LineString", "MultiPoint", "Point", "Envelope". 
     64     *     If non-null, all geometries in the GML document will be assumed to 
     65     *     one of the types in this list. 
     66     */ 
     67    geometryTypes: null, 
    5768     
    5869    /**  
    5970     * APIProperty: collectionName 
     
    136147     * node - {DOMElement} A GML feature node.  
    137148     */ 
    138149    parseFeature: function(node) { 
    139         // only accept on geometry per feature - look for highest "order" 
    140         var order = ["MultiPolygon", "Polygon", 
     150        var order; 
     151        if (this.geometryTypes) { 
     152            order = this.geometryTypes; 
     153        } else { 
     154            // only accept on geometry per feature - look for highest "order" 
     155            order = ["MultiPolygon", "Polygon", 
    141156                     "MultiLineString", "LineString", 
    142157                     "MultiPoint", "Point", "Envelope"]; 
     158        } 
    143159        var type, nodeList, geometry, parser; 
    144160        for(var i=0; i<order.length; ++i) { 
    145161            type = order[i];