File: v1.html

package info (click to toggle)
openlayers 2.13.1%2Bds2-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 67,252 kB
  • sloc: javascript: 61,721; xml: 7,435; python: 907; sh: 44; makefile: 19
file content (404 lines) | stat: -rw-r--r-- 14,597 bytes parent folder | download | duplicates (6)
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<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_PropertyIsNull(t) {

        t.plan(3);

        var format, test_xml, xml, filter, node;

        format = new OpenLayers.Format.Filter.v1();

        test_xml =
            '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
                '<ogc:PropertyIsNull>' +
                    '<ogc:PropertyName>prop</ogc:PropertyName>' +
                '</ogc:PropertyIsNull>' +
            '</ogc:Filter>';

        // Test reading a PropertyIsNull filter from an XML doc
        xml = new OpenLayers.Format.XML();
        filter = format.read(xml.read(test_xml).documentElement);
        t.eq(filter.type, OpenLayers.Filter.Comparison.IS_NULL,
             "[0] read correct type");
        t.eq(filter.property, 'prop',
             "[0] record correct property name");

        // Test writing a PropertyIsNull filter out to XML
        filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.IS_NULL,
            property: "prop"
        });
        node = format.write(filter);
        t.xml_eq(node, test_xml, "filter correctly written");

    }

    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 test_between_literal(t) {
        t.plan(3);

        var filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.BETWEEN,
            property: "foo",
            lowerBoundary: 1.0,
            upperBoundary: 2.0
        });
        var format = new OpenLayers.Format.Filter.v1_0_0();
        
        var exp = format.read(readXML("BetweenLiteral"));

        // confirm that reading works as expected
        t.eq(exp.property, "foo", "property");
        t.eq(exp.lowerBoundary, 1.0, "lowerBoundary");
        t.eq(exp.upperBoundary, 2.0, "upperBoundary");
    }


    function test_date_writing(t) {
        t.plan(1);

        // ISO 8601: 2010-11-27T18:19:15.123Z
        var start = new Date(Date.UTC(2010, 10, 27, 18, 19, 15, 123));

        // ISO 8601: 2011-12-27T18:19:15.123Z
        var end = new Date(Date.UTC(2011, 11, 27, 18, 19, 15, 123));

        var filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.BETWEEN,
            property: "when",
            lowerBoundary: start,
            upperBoundary: end
        });

        var format = new OpenLayers.Format.Filter.v1_0_0();

        var got = format.write(filter);
        var exp = readXML("BetweenDates");
        t.xml_eq(got, exp, "comparison filter with dates");
    }


    function test_custom_date_writing(t) {
        t.plan(1);

        // ISO 8601: 2010-11-27T18:19:15.123Z
        var start = new Date(Date.UTC(2010, 10, 27, 18, 19, 15, 123));

        // ISO 8601: 2011-12-27T18:19:15.123Z
        var end = new Date(Date.UTC(2011, 11, 27, 18, 19, 15, 123));

        var filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.BETWEEN,
            property: "when",
            lowerBoundary: start,
            upperBoundary: end
        });

        var format = new OpenLayers.Format.Filter({
            encodeLiteral: function(value) {
                // return just the date and not the time portion
                return OpenLayers.Date.toISOString(value).split("T").shift();
            }
        });

        var got = format.write(filter);
        var exp = readXML("CustomBetweenDates");
        t.xml_eq(got, exp, "comparison filter with dates");
    }


    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>
<div id="BetweenLiteral"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:PropertyIsBetween>
        <ogc:PropertyName>foo</ogc:PropertyName>
        <ogc:LowerBoundary>
            <ogc:Literal>1.0</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
            <ogc:Literal>2.0</ogc:Literal>
        </ogc:UpperBoundary>
    </ogc:PropertyIsBetween>
</ogc:Filter>
--></div>
<div id="BetweenDates"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:PropertyIsBetween>
        <ogc:PropertyName>when</ogc:PropertyName>
        <ogc:LowerBoundary>
            <ogc:Literal>2010-11-27T18:19:15.123Z</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
            <ogc:Literal>2011-12-27T18:19:15.123Z</ogc:Literal>
        </ogc:UpperBoundary>
    </ogc:PropertyIsBetween>
</ogc:Filter>
--></div>
<div id="CustomBetweenDates"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:PropertyIsBetween>
        <ogc:PropertyName>when</ogc:PropertyName>
        <ogc:LowerBoundary>
            <ogc:Literal>2010-11-27</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
            <ogc:Literal>2011-12-27</ogc:Literal>
        </ogc:UpperBoundary>
    </ogc:PropertyIsBetween>
</ogc:Filter>
--></div>

</body> 
</html>