]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Format/Filter/v1_0_0.html
fixes notices
[syp.git] / openlayers / tests / Format / Filter / v1_0_0.html
1 <html> 
2 <head> 
3     <script src="../../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5     
6     var test_xml =
7         '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
8             '<ogc:Or>' +
9                 '<ogc:PropertyIsBetween>' +
10                     '<ogc:PropertyName>number</ogc:PropertyName>' +
11                     '<ogc:LowerBoundary>' +
12                         '<ogc:Literal>1064866676</ogc:Literal>' +
13                     '</ogc:LowerBoundary>' +
14                     '<ogc:UpperBoundary>' +
15                         '<ogc:Literal>1065512599</ogc:Literal>' +
16                     '</ogc:UpperBoundary>' +
17                 '</ogc:PropertyIsBetween>' +
18                 '<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">' +
19                     '<ogc:PropertyName>cat</ogc:PropertyName>' +
20                     '<ogc:Literal>*dog.food!*good</ogc:Literal>' +
21                 '</ogc:PropertyIsLike>' +
22                 '<ogc:Not>' +
23                     '<ogc:PropertyIsLessThanOrEqualTo>' +
24                         '<ogc:PropertyName>FOO</ogc:PropertyName>' +
25                         '<ogc:Literal>5000</ogc:Literal>' +
26                     '</ogc:PropertyIsLessThanOrEqualTo>' +
27                 '</ogc:Not>' +
28             '</ogc:Or>' +
29         '</ogc:Filter>';
30
31     function test_read(t) {
32         t.plan(3);
33
34         var parser = new OpenLayers.Format.Filter.v1_0_0();
35         var xml = new OpenLayers.Format.XML();
36         var filter = parser.read(xml.read(test_xml).documentElement);
37
38         t.ok(filter instanceof OpenLayers.Filter.Logical, "instance of correct class");
39         t.eq(filter.type, OpenLayers.Filter.Logical.OR, "correct type");
40         t.eq(filter.filters.length, 3, "correct number of child filters");
41     }
42     
43     function test_write(t) {
44         t.plan(1);
45
46         // read first - testing that write produces the ogc:Filter element above
47         var parser = new OpenLayers.Format.Filter.v1_0_0();
48         var xml = new OpenLayers.Format.XML();
49         var filter = parser.read(xml.read(test_xml).documentElement);
50         
51         var node = parser.write(filter);
52         t.xml_eq(node, test_xml, "filter correctly written");
53         
54     }
55     
56     function test_BBOX(t) {
57         t.plan(1);
58         var filter = new OpenLayers.Filter.Spatial({
59             type: OpenLayers.Filter.Spatial.BBOX,
60             property: "the_geom",
61             value: new OpenLayers.Bounds(-180, -90, 180, 90),
62             projection: "EPSG:4326"
63         });
64         
65         var out =
66             '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
67                 '<ogc:BBOX>' +
68                     '<ogc:PropertyName>the_geom</ogc:PropertyName>' +
69                     '<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">' +
70                         '<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>' +
71                     '</gml:Box>' +
72                 '</ogc:BBOX>' +
73             '</ogc:Filter>';
74         
75         var parser = new OpenLayers.Format.Filter.v1_0_0();
76         var node = parser.write(filter);
77         
78         t.xml_eq(node, out, "bbox correctly written");
79     }
80
81     function test_DWithin(t) {
82         
83         t.plan(6);
84         
85         var str =
86             '<Filter xmlns="http://www.opengis.net/ogc">' +
87                 '<DWithin>' +
88                     '<PropertyName>Geometry</PropertyName>' +
89                     '<gml:Point xmlns:gml="http://www.opengis.net/gml">' +
90                         '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552</gml:coordinates>' +
91                     '</gml:Point>' +
92                     '<Distance units="m">1000</Distance>' +
93                 '</DWithin>' +
94             '</Filter>';
95
96         var format = new OpenLayers.Format.Filter.v1_0_0();
97         var filter = new OpenLayers.Filter.Spatial({
98             type: OpenLayers.Filter.Spatial.DWITHIN,
99             property: "Geometry",
100             value: new OpenLayers.Geometry.Point(2488789,289552),
101             distance: 1000,
102             distanceUnits: "m"
103         });
104         
105         // test writing
106         var node = format.write(filter);
107         t.xml_eq(node, str, "filter correctly written");
108         
109         // test reading
110         var doc = (new OpenLayers.Format.XML).read(str);
111         var got = format.read(doc.firstChild);
112         t.eq(got.type, filter.type, "read correct type");
113         t.eq(got.property, filter.property, "read correct property");
114         t.geom_eq(got.value, filter.value, "read correct value");
115         t.eq(got.distance, filter.distance, "read correct distance");
116         t.eq(got.distanceUnits, filter.distanceUnits, "read correct distance units");
117
118     }
119
120     function test_Intersects(t) {
121         
122         t.plan(4);
123         
124         var str =
125             '<Filter xmlns="http://www.opengis.net/ogc">' +
126                 '<Intersects>' +
127                     '<PropertyName>Geometry</PropertyName>' +
128                     '<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">' +
129                         '<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>' +
130                     '</gml:Box>' +
131                 '</Intersects>' +
132             '</Filter>';
133
134         var format = new OpenLayers.Format.Filter.v1_0_0();
135         var filter = new OpenLayers.Filter.Spatial({
136             type: OpenLayers.Filter.Spatial.INTERSECTS,
137             property: "Geometry",
138             value: new OpenLayers.Bounds(-180, -90, 180, 90),
139             projection: "EPSG:4326"
140         });
141         
142         // test writing
143         var node = format.write(filter);
144         t.xml_eq(node, str, "filter correctly written");
145         
146         // test reading
147         var doc = (new OpenLayers.Format.XML).read(str);
148         var got = format.read(doc.firstChild);
149         t.eq(got.type, filter.type, "read correct type");
150         t.eq(got.property, filter.property, "read correct property");
151         t.eq(got.value.toArray(), filter.value.toArray(), "read correct value");
152
153     }
154
155
156     </script> 
157 </head> 
158 <body>
159 </body> 
160 </html>