Changeset 7826
- Timestamp:
- 08/22/08 08:46:17 (5 months ago)
- Files:
-
- sandbox/camptocamp/unhcr/lib/OpenLayers.js (modified) (1 diff)
- sandbox/camptocamp/unhcr/lib/OpenLayers/Filter/Spatial.js (added)
- sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js (modified) (4 diffs)
- sandbox/camptocamp/unhcr/tests/Filter/Spatial.html (added)
- sandbox/camptocamp/unhcr/tests/Format/GML.html (modified) (7 diffs)
- sandbox/camptocamp/unhcr/tests/list-tests.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/unhcr/lib/OpenLayers.js
r7824 r7826 194 194 "OpenLayers/Filter/Logical.js", 195 195 "OpenLayers/Filter/Comparison.js", 196 "OpenLayers/Filter/Spatial.js", 196 197 "OpenLayers/Format.js", 197 198 "OpenLayers/Format/XML.js", sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js
r7785 r7826 140 140 var order = ["MultiPolygon", "Polygon", 141 141 "MultiLineString", "LineString", 142 "MultiPoint", "Point", "Envelope"];142 "MultiPoint", "Point", "Envelope","Box"]; 143 143 var type, nodeList, geometry, parser; 144 144 for(var i=0; i<order.length; ++i) { … … 522 522 } 523 523 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; 524 548 } 525 549 }, … … 805 829 } 806 830 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; 807 849 } 808 850 }, … … 826 868 coordinatesNode.setAttribute("cs", ","); 827 869 coordinatesNode.setAttribute("ts", " "); 828 829 var points = (geometry.components) ? geometry.components : [geometry]; 870 830 871 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 } 833 881 } 834 882 sandbox/camptocamp/unhcr/tests/Format/GML.html
r7785 r7826 37 37 } 38 38 function test_Format_GML_write_geoms(t) { 39 t.plan( 5);39 t.plan(6); 40 40 var parser = new OpenLayers.Format.GML(); 41 41 … … 69 69 var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog 70 70 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 71 78 } 72 79 function test_Format_GML_read_point_geom(t) { … … 179 186 t.eq(data[0].geometry.components.length, 1, "rings length correct"); 180 187 } 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 } 181 200 /////////////////////////////////////////////////////////////// 182 201 // tests the y x order of gml point … … 311 330 t.eq(output, polygon_xy, "Poly geometry round trips correctly."); 312 331 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, "MultiPointgeometry 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 320 339 var multilinestring_xy = shell_start + serialize_geoms['multilinestring'] + shell_end; 321 340 var multilinestring = shell_start + serialize_geoms_yx['multilinestring'] + shell_end; … … 366 385 '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>', 367 386 '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>' 369 389 }; 370 390 var geoms = { … … 375 395 '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>', 376 396 '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>' 378 399 // '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>' 379 400 }; … … 389 410 '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>', 390 411 '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>', 391 413 '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>' 392 414 }; sandbox/camptocamp/unhcr/tests/list-tests.html
r7824 r7826 39 39 <li>Filter/FeatureId.html</li> 40 40 <li>Filter/Logical.html</li> 41 <li>Filter/Spatial.html</li> 41 42 <li>Format.html</li> 42 43 <li>Format/GeoJSON.html</li>
