File: v1.html

package info (click to toggle)
openlayers 2.11%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 60,144 kB
  • ctags: 10,906
  • sloc: xml: 7,435; python: 778; sh: 68; makefile: 30
file content (261 lines) | stat: -rw-r--r-- 9,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<html> 
<head> 
    <script src="../../OLLoader.js"></script>
    <script type="text/javascript">
    
    function test_PropertyIsBetween(t) {

        t.plan(6);

        var test_xml, parser, xml;

        parser = new OpenLayers.Format.Filter.v1();
        xml = new OpenLayers.Format.XML();

        test_xml =
            '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
                '<ogc:PropertyIsBetween>' +
                    '<ogc:PropertyName>number</ogc:PropertyName>' +
                    '<ogc:LowerBoundary>' +
                        '<ogc:Literal>0</ogc:Literal>' +
                    '</ogc:LowerBoundary>' +
                    '<ogc:UpperBoundary>' +
                        '<ogc:Literal>100</ogc:Literal>' +
                    '</ogc:UpperBoundary>' +
                '</ogc:PropertyIsBetween>' +
            '</ogc:Filter>';

        var filter = parser.read(xml.read(test_xml).documentElement);
        t.eq(filter.type, OpenLayers.Filter.Comparison.BETWEEN,
             "[0] read correct type");
        t.eq(filter.lowerBoundary, 0,
             "[0] record correct lower boundary value");
        t.eq(filter.upperBoundary, 100,
             "[0] record correct upper boundary value");

        test_xml =
            '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
                '<ogc:PropertyIsBetween>' +
                    '<ogc:PropertyName>number</ogc:PropertyName>' +
                    '<ogc:LowerBoundary>0</ogc:LowerBoundary>' +
                    '<ogc:UpperBoundary>100</ogc:UpperBoundary>' +
                '</ogc:PropertyIsBetween>' +
            '</ogc:Filter>';

        var filter = parser.read(xml.read(test_xml).documentElement);
        t.eq(filter.type, OpenLayers.Filter.Comparison.BETWEEN,
             "[1] read correct type");
        t.eq(filter.lowerBoundary, 0,
             "[1] record correct lower boundary value");
        t.eq(filter.upperBoundary, 100,
             "[1] record correct upper boundary value");
    }


    function test_Intersects(t) {
        
        t.plan(4);
        
        var str =
            '<Filter xmlns="http://www.opengis.net/ogc">' +
                '<Intersects>' +
                    '<PropertyName>Geometry</PropertyName>' +
                    '<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
                        '<gml:outerBoundaryIs>' +
                            '<gml:LinearRing>' +
                                '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
                            '</gml:LinearRing>' +
                        '</gml:outerBoundaryIs>' +
                    '</gml:Polygon>' +
                '</Intersects>' +
            '</Filter>';

        var format = new OpenLayers.Format.Filter.v1_0_0();
        var filter = new OpenLayers.Filter.Spatial({
            type: OpenLayers.Filter.Spatial.INTERSECTS,
            property: "Geometry",
            value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
        });
        
        // test writing
        var node = format.write(filter);
        t.xml_eq(node, str, "filter correctly written");
        
        // test reading
        var doc = (new OpenLayers.Format.XML).read(str);
        var got = format.read(doc.firstChild);
        t.eq(got.type, filter.type, "read correct type");
        t.eq(got.property, filter.property, "read correct property");
        t.geom_eq(got.value, filter.value, "read correct value");

    }

    function test_Within(t) {
        
        t.plan(4);
        
        var str =
            '<Filter xmlns="http://www.opengis.net/ogc">' +
                '<Within>' +
                    '<PropertyName>Geometry</PropertyName>' +
                    '<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
                        '<gml:outerBoundaryIs>' +
                            '<gml:LinearRing>' +
                                '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
                            '</gml:LinearRing>' +
                        '</gml:outerBoundaryIs>' +
                    '</gml:Polygon>' +
                '</Within>' +
            '</Filter>';

        var format = new OpenLayers.Format.Filter.v1_0_0();
        var filter = new OpenLayers.Filter.Spatial({
            type: OpenLayers.Filter.Spatial.WITHIN,
            property: "Geometry",
            value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
        });
        
        // test writing
        var node = format.write(filter);
        t.xml_eq(node, str, "filter correctly written");
        
        // test reading
        var doc = (new OpenLayers.Format.XML).read(str);
        var got = format.read(doc.firstChild);
        t.eq(got.type, filter.type, "read correct type");
        t.eq(got.property, filter.property, "read correct property");
        t.geom_eq(got.value, filter.value, "read correct value");

    }

    function test_Contains(t) {
        
        t.plan(4);
        
        var str =
            '<Filter xmlns="http://www.opengis.net/ogc">' +
                '<Contains>' +
                    '<PropertyName>Geometry</PropertyName>' +
                    '<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
                        '<gml:outerBoundaryIs>' +
                            '<gml:LinearRing>' +
                                '<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
                            '</gml:LinearRing>' +
                        '</gml:outerBoundaryIs>' +
                    '</gml:Polygon>' +
                '</Contains>' +
            '</Filter>';

        var format = new OpenLayers.Format.Filter.v1_0_0();
        var filter = new OpenLayers.Filter.Spatial({
            type: OpenLayers.Filter.Spatial.CONTAINS,
            property: "Geometry",
            value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
        });
        
        // test writing
        var node = format.write(filter);
        t.xml_eq(node, str, "filter correctly written");
        
        // test reading
        var doc = (new OpenLayers.Format.XML).read(str);
        var got = format.read(doc.firstChild);
        t.eq(got.type, filter.type, "read correct type");
        t.eq(got.property, filter.property, "read correct property");
        t.geom_eq(got.value, filter.value, "read correct value");

    }

    function test_logical_fid(t) {
        // the Filter Encoding spec doesn't allow for FID filters inside logical filters
        // however, to be liberal, we will write them without complaining
        t.plan(3);

        var filter = new OpenLayers.Filter.Logical({
            type: OpenLayers.Filter.Logical.OR,
            filters: [
                new OpenLayers.Filter.Comparison({
                    type: OpenLayers.Filter.Comparison.LIKE,
                    property: "person",
                    value: "me"
                }),
                new OpenLayers.Filter.FeatureId({fids: ["foo.1", "foo.2"]})
            ]
        });
        var format = new OpenLayers.Format.Filter.v1_0_0();
        
        var got = format.write(filter);
        var exp = readXML("LogicalFeatureId");
        t.xml_eq(got, exp, "wrote FID filter in logical OR without complaint");

        filter = new OpenLayers.Filter.Logical({
            type: OpenLayers.Filter.Logical.AND,
            filters: [
                new OpenLayers.Filter.Comparison({
                    type: OpenLayers.Filter.Comparison.LIKE,
                    property: "person",
                    value: "me"
                }),
                new OpenLayers.Filter.FeatureId({fids: ["foo.1", "foo.2"]})
            ]
        });
        got = format.write(filter);
        exp = readXML("LogicalFeatureIdAnd");
        t.xml_eq(got, exp, "wrote FID filter in logical AND without complaint");

        filter = new OpenLayers.Filter.Logical({
            type: OpenLayers.Filter.Logical.NOT,
            filters: [
                new OpenLayers.Filter.FeatureId({fids: ["foo.2"]})
            ]
        });
        got = format.write(filter);
        exp = readXML("LogicalFeatureIdNot");
        t.xml_eq(got, exp, "wrote FID filter in logical NOT without complaint");
    }


    function readXML(id) {
        var xml = document.getElementById(id).firstChild.nodeValue;
        return new OpenLayers.Format.XML().read(xml).documentElement;
    }


    </script> 
</head> 
<body>

<div id="LogicalFeatureId"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:Or>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
            <ogc:PropertyName>person</ogc:PropertyName>
            <ogc:Literal>me</ogc:Literal>
        </ogc:PropertyIsLike>
        <ogc:FeatureId fid="foo.1"/>
        <ogc:FeatureId fid="foo.2"/>
    </ogc:Or>
</ogc:Filter>
--></div>
<div id="LogicalFeatureIdAnd"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:And>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
            <ogc:PropertyName>person</ogc:PropertyName>
            <ogc:Literal>me</ogc:Literal>
        </ogc:PropertyIsLike>
        <ogc:FeatureId fid="foo.1"/>
        <ogc:FeatureId fid="foo.2"/>
    </ogc:And>
</ogc:Filter>
--></div>
<div id="LogicalFeatureIdNot"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:Not>
        <ogc:FeatureId fid="foo.2"/>
    </ogc:Not>
</ogc:Filter>
--></div>

</body> 
</html>