]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Format/Filter/v1.html
initial commit
[syp.git] / openlayers / tests / Format / Filter / v1.html
1 <html> 
2 <head> 
3     <script src="../../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5     
6
7     function test_Intersects(t) {
8         
9         t.plan(4);
10         
11         var str =
12             '<Filter xmlns="http://www.opengis.net/ogc">' +
13                 '<Intersects>' +
14                     '<PropertyName>Geometry</PropertyName>' +
15                     '<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
16                         '<gml:outerBoundaryIs>' +
17                             '<gml:LinearRing>' +
18                                 '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
19                             '</gml:LinearRing>' +
20                         '</gml:outerBoundaryIs>' +
21                     '</gml:Polygon>' +
22                 '</Intersects>' +
23             '</Filter>';
24
25         var format = new OpenLayers.Format.Filter.v1_0_0();
26         var filter = new OpenLayers.Filter.Spatial({
27             type: OpenLayers.Filter.Spatial.INTERSECTS,
28             property: "Geometry",
29             value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
30         });
31         
32         // test writing
33         var node = format.write(filter);
34         t.xml_eq(node, str, "filter correctly written");
35         
36         // test reading
37         var doc = (new OpenLayers.Format.XML).read(str);
38         var got = format.read(doc.firstChild);
39         t.eq(got.type, filter.type, "read correct type");
40         t.eq(got.property, filter.property, "read correct property");
41         t.geom_eq(got.value, filter.value, "read correct value");
42
43     }
44
45     function test_Within(t) {
46         
47         t.plan(4);
48         
49         var str =
50             '<Filter xmlns="http://www.opengis.net/ogc">' +
51                 '<Within>' +
52                     '<PropertyName>Geometry</PropertyName>' +
53                     '<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
54                         '<gml:outerBoundaryIs>' +
55                             '<gml:LinearRing>' +
56                                 '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
57                             '</gml:LinearRing>' +
58                         '</gml:outerBoundaryIs>' +
59                     '</gml:Polygon>' +
60                 '</Within>' +
61             '</Filter>';
62
63         var format = new OpenLayers.Format.Filter.v1_0_0();
64         var filter = new OpenLayers.Filter.Spatial({
65             type: OpenLayers.Filter.Spatial.WITHIN,
66             property: "Geometry",
67             value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
68         });
69         
70         // test writing
71         var node = format.write(filter);
72         t.xml_eq(node, str, "filter correctly written");
73         
74         // test reading
75         var doc = (new OpenLayers.Format.XML).read(str);
76         var got = format.read(doc.firstChild);
77         t.eq(got.type, filter.type, "read correct type");
78         t.eq(got.property, filter.property, "read correct property");
79         t.geom_eq(got.value, filter.value, "read correct value");
80
81     }
82
83     function test_Contains(t) {
84         
85         t.plan(4);
86         
87         var str =
88             '<Filter xmlns="http://www.opengis.net/ogc">' +
89                 '<Contains>' +
90                     '<PropertyName>Geometry</PropertyName>' +
91                     '<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
92                         '<gml:outerBoundaryIs>' +
93                             '<gml:LinearRing>' +
94                                 '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
95                             '</gml:LinearRing>' +
96                         '</gml:outerBoundaryIs>' +
97                     '</gml:Polygon>' +
98                 '</Contains>' +
99             '</Filter>';
100
101         var format = new OpenLayers.Format.Filter.v1_0_0();
102         var filter = new OpenLayers.Filter.Spatial({
103             type: OpenLayers.Filter.Spatial.CONTAINS,
104             property: "Geometry",
105             value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
106         });
107         
108         // test writing
109         var node = format.write(filter);
110         t.xml_eq(node, str, "filter correctly written");
111         
112         // test reading
113         var doc = (new OpenLayers.Format.XML).read(str);
114         var got = format.read(doc.firstChild);
115         t.eq(got.type, filter.type, "read correct type");
116         t.eq(got.property, filter.property, "read correct property");
117         t.geom_eq(got.value, filter.value, "read correct value");
118
119     }
120
121
122     </script> 
123 </head> 
124 <body>
125 </body> 
126 </html>