OpenLayers OpenLayers

Changeset 7826

Show
Ignore:
Timestamp:
08/22/08 08:46:17 (5 months ago)
Author:
elemoine
Message:

apply ticket attached to #1543

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/camptocamp/unhcr/lib/OpenLayers.js

    r7824 r7826  
    194194            "OpenLayers/Filter/Logical.js", 
    195195            "OpenLayers/Filter/Comparison.js", 
     196            "OpenLayers/Filter/Spatial.js", 
    196197            "OpenLayers/Format.js", 
    197198            "OpenLayers/Format/XML.js", 
  • sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js

    r7785 r7826  
    140140        var order = ["MultiPolygon", "Polygon", 
    141141                     "MultiLineString", "LineString", 
    142                      "MultiPoint", "Point", "Envelope"]; 
     142            "MultiPoint", "Point", "Envelope","Box"]; 
    143143        var type, nodeList, geometry, parser; 
    144144        for(var i=0; i<order.length; ++i) { 
     
    522522            } 
    523523            return envelope;  
     524        }, 
     525         
     526        box: function(node){ 
     527            var coords = []; 
     528            var coordString; 
     529 
     530            // look for <gml:coordinates> 
     531            if(coords.length == 0) { 
     532                nodeList = this.getElementsByTagNameNS(node, this.gmlns, 
     533                                                       "coordinates"); 
     534                if(nodeList.length > 0) { 
     535                    coordString = nodeList[0].firstChild.nodeValue; 
     536                    coordString = coordString.replace(this.regExes.splitSpace, 
     537                                                      ","); 
     538                    coords = coordString.split(","); 
     539                } 
     540            } 
     541            if(this.xy){ 
     542                var bounds = OpenLayers.Bounds.fromArray(coords); 
     543            } else { 
     544                var bounds = OpenLayers.Bounds.fromArray([coords[1],coords[0],coords[3],coords[2]]); 
     545            } 
     546 
     547            return bounds; 
    524548        } 
    525549    }, 
     
    805829            } 
    806830            return gml; 
     831 
     832         }, 
     833  
     834        /** 
     835         * Method: buildGeometry.bounds 
     836         * Given an OpenLayers bounds, create a GML box. 
     837         * 
     838         * Parameters: 
     839         * geometry - {<OpenLayers.Geometry.Bounds>} A bound. 
     840         *  
     841         * 
     842         * Returns: 
     843         * {DOMElement} A GML box node. 
     844         */ 
     845        bounds: function(geometry) { 
     846            var gml = this.createElementNS(this.gmlns, "gml:Box"); 
     847            gml.appendChild(this.buildCoordinatesNode(geometry)); 
     848            return gml; 
    807849        } 
    808850    }, 
     
    826868        coordinatesNode.setAttribute("cs", ","); 
    827869        coordinatesNode.setAttribute("ts", " "); 
    828          
    829         var points = (geometry.components) ? geometry.components : [geometry]; 
     870 
    830871        var parts = []; 
    831         for(var i=0; i<points.length; i++) { 
    832             parts.push(points[i].x + "," + points[i].y); 
     872 
     873        if(geometry instanceof OpenLayers.Bounds){ 
     874            parts.push(geometry.left + "," + geometry.bottom); 
     875            parts.push(geometry.right + "," + geometry.top); 
     876        } else { 
     877            var points = (geometry.components) ? geometry.components : [geometry]; 
     878            for(var i=0; i<points.length; i++) { 
     879                parts.push(points[i].x + "," + points[i].y);                 
     880            }             
    833881        } 
    834882 
  • sandbox/camptocamp/unhcr/tests/Format/GML.html

    r7785 r7826  
    3737    }    
    3838    function test_Format_GML_write_geoms(t) { 
    39         t.plan(5); 
     39        t.plan(6); 
    4040        var parser = new OpenLayers.Format.GML(); 
    4141         
     
    6969        var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog 
    7070        t.eq(output, multilinestring, "MultiLine geometry round trips correctly."); 
     71 
     72        var bounds = shell_start + serialize_geoms['bounds'] + shell_end; 
     73        data = parser.read(bounds); 
     74        var output = parser.write(data); 
     75        var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog 
     76        t.xml_eq(output, bounds, "Box/bounds round trips correctly."); 
     77 
    7178    }     
    7279    function test_Format_GML_read_point_geom(t) { 
     
    179186        t.eq(data[0].geometry.components.length, 1, "rings length correct"); 
    180187    }     
     188    function test_Format_GML_read_bounds_geom(t) { 
     189        t.plan(5); 
     190         
     191        var bounds = shell_start + geoms['bounds'] + shell_end; 
     192        var parser = new OpenLayers.Format.GML(); 
     193        data = parser.read(bounds); 
     194        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Bounds", "Box GML returns correct classname (Bounds)"); 
     195        t.eq(data[0].geometry.left, 32, "first left coord correct"); 
     196        t.eq(data[0].geometry.bottom, 5, "first bottom coord correct"); 
     197        t.eq(data[0].geometry.right, 70, "second right coord correct"); 
     198        t.eq(data[0].geometry.top, 112, "second top coord correct"); 
     199    }     
    181200    /////////////////////////////////////////////////////////////// 
    182201    // tests the y x order of gml point 
     
    311330        t.eq(output, polygon_xy, "Poly geometry round trips correctly."); 
    312331         
    313         var multipoint_xy = shell_start + serialize_geoms['multipoint'] + shell_end; 
    314         var multipoint = shell_start + serialize_geoms_yx['multipoint'] + shell_end; 
    315         data = parser.read(multipoint); 
    316         var output = parser.write(data); 
    317         var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog 
    318         t.eq(output, multipoint_xy, "MultiPoint geometry round trips correctly."); 
    319          
     332        var bounds_xy = shell_start + serialize_geoms['bounds'] + shell_end; 
     333        var bounds = shell_start + serialize_geoms_yx['bounds'] + shell_end; 
     334        data = parser.read(bounds); 
     335        var output = parser.write(data); 
     336        var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog 
     337        t.eq(output, bounds_xy, "Box/Bounds geometry round trips correctly."); 
     338 
    320339        var multilinestring_xy = shell_start + serialize_geoms['multilinestring'] + shell_end; 
    321340        var multilinestring = shell_start + serialize_geoms_yx['multilinestring'] + shell_end; 
     
    366385        'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', 
    367386        'multipoint': '<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">4,5</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>', 
    368         'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">11,12 14,15</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>' 
     387        'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">11,12 14,15</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>', 
     388        'bounds': '<gml:Box><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5</gml:coordinates></gml:Box>' 
    369389    }; 
    370390    var geoms = { 
     
    375395        'multipoint': '<gml:MultiPoint><gml:Point><gml:coordinates>1,2,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>4,5,6</gml:coordinates></gml:Point></gml:MultiPoint>', 
    376396        'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>1,2,3 4,5,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>11,12,13 14,15,16</gml:coordinates></gml:LineString></gml:MultiLineString>', 
    377         'envelope': '<gml:Envelope><gml:lowerCorner>0 1</gml:lowerCorner><gml:upperCorner>20 21</gml:upperCorner></gml:Envelope>' // , 
     397        'envelope': '<gml:Envelope><gml:lowerCorner>0 1</gml:lowerCorner><gml:upperCorner>20 21</gml:upperCorner></gml:Envelope>' , 
     398        'bounds': '<gml:Box><gml:coordinates decimal="." cs="," ts=" ">32,5 70,112</gml:coordinates></gml:Box>' 
    378399        // 'multipolygon_with_holes': '<gml:MultiPolygon><gml:Polygon><gml:outerBoundaryIs>1,2 4,5 3,6 1,2</gml:outerBoundaryIs><gml:innerBoundaryIs>11,12 14,15 13,16 11,12</gml:innerBoundaryIs></gml:Polygon><gml:Polygon><gml:outerBoundaryIs>101,102 104,105 103,106 101,102</gml:outerBoundaryIs><gml:innerBoundaryIs>111,112 114,115 113,116 111,112</gml:innerBoundaryIs></gml:Polygon></gml:MultiPolygon>' 
    379400    }; 
     
    389410        'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', 
    390411        'multipoint': '<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">5,4</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>', 
     412        'bounds': '<gml:Box><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:Box>', 
    391413        'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">12,11 15,14</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>' 
    392414    }; 
  • sandbox/camptocamp/unhcr/tests/list-tests.html

    r7824 r7826  
    3939    <li>Filter/FeatureId.html</li> 
    4040    <li>Filter/Logical.html</li> 
     41    <li>Filter/Spatial.html</li> 
    4142    <li>Format.html</li> 
    4243    <li>Format/GeoJSON.html</li>