]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Format/ArcXML.html
err_lonlat_invalid exceptions not thrown correctly
[syp.git] / openlayers / tests / Format / ArcXML.html
1 <html> 
2 <head> 
3     <script src="../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5
6     var axl_image_response = '<?xml version="1.0" encoding="UTF-8"?><ARCXML version="1.1"><RESPONSE><IMAGE><ENVELOPE minx="-2471.42857142857" miny="0" maxx="105671.428571429" maxy="75700" /><OUTPUT url="http://localhost/output/364826560.png" /></IMAGE></RESPONSE></ARCXML>';
7     var axl_feature_response = '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><RESPONSE><FEATURES><FEATURE><FIELDS><FIELD name="UNIQUE_ID" value="514504b5-0458-461d-b540-8e18a454f619" /><FIELD name="LABEL" value="LIBRARY" /><FIELD name="Y_COORD" value="39.57" /><FIELD name="X_COORD" value="-104.24" /><FIELD name="#SHAPE#" value="[Geometry]" /><FIELD name="OBJECTID" value="1" /><FIELD name="shape.area" value="0" /><FIELD name="shape.len" value="0" /></FIELDS></FEATURE><FEATURE><FIELDS><FIELD name="UNIQUE_ID" value="514504b5-0458-461d-b540-8e81a454f619" /><FIELD name="LABEL" value="LIBRARY2" /><FIELD name="Y_COORD" value="39.75" /><FIELD name="X_COORD" value="-104.42" /><FIELD name="#SHAPE#" value="[Geometry]" /><FIELD name="OBJECTID" value="2" /><FIELD name="shape.area" value="0" /><FIELD name="shape.len" value="0" /></FIELDS></FEATURE><FEATURECOUNT count="2" hasmore="false" /><ENVELOPE minx="-678853.220047791" miny="1810.22081371862" maxx="-678853.220047791" maxy="1810.22081371862"/></FEATURES></RESPONSE></ARCXML>';
8
9     //
10     // creating a new arcxml format creates an object that has a read and write function
11     //
12     function test_Format_ArcXML_constructor1(t) {
13         t.plan(4); 
14          
15         var format = new OpenLayers.Format.ArcXML(); 
16         t.ok(format instanceof OpenLayers.Format.ArcXML, 
17              "new OpenLayers.Format.ArcXML returns object" ); 
18
19         t.ok(format.request, null, "no options creates a null request");
20
21         t.eq(typeof format.read, "function", "format has a read function"); 
22         t.eq(typeof format.write, "function", "format has a write function"); 
23     }
24
25     //
26     // creating a new arcxml format with a set of options for an image request
27     // creates a request child object, and a get_image grandchild.
28     //
29     function test_Format_ArcXML_constructor2(t) { 
30         t.plan(6); 
31         
32         var options = {
33           requesttype:'image',
34           envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
35           layers: [],
36           tileSize: new OpenLayers.Size( 256,256 ),
37           featureCoordSys: '4326',
38           filterCoordSys: '4326'
39         };
40         
41         var format = new OpenLayers.Format.ArcXML( options );
42         t.ok(format instanceof OpenLayers.Format.ArcXML, 
43              "new OpenLayers.Format.ArcXML returns object" ); 
44                  
45         t.ok(format.request instanceof OpenLayers.Format.ArcXML.Request, 
46             "constructor with 'image' requesttype generates a request");
47         t.ok( format.request.get_image !== null, "get_image property exists" );
48         t.ok( format.request.get_feature === null, "get_feature property does not exists" );        
49
50         t.eq(typeof format.read, "function", "format has a read function"); 
51         t.eq(typeof format.write, "function", "format has a write function"); 
52     }
53
54     //
55     // creating a new arcxml format with a set of options for a feature request
56     // creates a request child object, and a get_feature grandchild
57     //
58     function test_Format_ArcXML_constructor3(t) { 
59         t.plan(6); 
60          
61         var options = {
62           requesttype:'feature'
63         };
64         
65         var format = new OpenLayers.Format.ArcXML( options ); 
66         t.ok(format instanceof OpenLayers.Format.ArcXML, 
67              "new OpenLayers.Format.ArcXML returns object" ); 
68                  
69         t.ok(format.request instanceof OpenLayers.Format.ArcXML.Request, 
70             "constructor with 'feature' requesttype generates a request");
71         t.ok( format.request.get_feature !== null, "get_feature property exists" );
72         t.ok( format.request.get_image === null, "get_image property does not exists" );        
73
74         t.eq(typeof format.read, "function", "format has a read function"); 
75         t.eq(typeof format.write, "function", "format has a write function"); 
76     }
77
78     //
79     // read in a known good axl image response
80     //
81     function test_Format_ArcXML_read1(t) {
82         t.plan(4);
83         var f = new OpenLayers.Format.ArcXML();
84         var response = f.read(axl_image_response);
85         
86         t.ok(response !== null, "get_image response object is not null" );
87         t.ok(response.image !== null, "get_image image tag is not null");
88         t.ok(response.image.envelope !== null, "get_image image envelope tag is not null");
89         t.ok(response.image.output !== null, "get_image image output tag is not null");
90     }
91
92     //
93     // read in a known good axl feature response
94     //
95     function test_Format_ArcXML_read2(t) {
96         t.plan(10);
97         var f = new OpenLayers.Format.ArcXML();
98         var response = f.read(axl_feature_response);
99         
100         t.ok(response !== null, "get_feature response object is not null" );
101         t.ok(response.features !== null, "get_feature features tag is not null");
102         t.ok(response.features.envelope !== null, "get_feature envelope tag is not null");
103         t.eq(response.features.featurecount, "2", "feature count is 2" );
104         
105         // test the second feature parsed
106         // <FIELD name="UNIQUE_ID" value="514504b5-0458-461d-b540-8e81a454f619" />
107         // <FIELD name="LABEL" value="LIBRARY2" />
108         // <FIELD name="Y_COORD" value="39.75" />
109         // <FIELD name="X_COORD" value="-104.42" />
110         // <FIELD name="#SHAPE#" value="[Geometry]" />
111         // <FIELD name="OBJECTID" value="2" />
112         // <FIELD name="shape.area" value="0" />
113         // <FIELD name="shape.len" value="0" />
114         t.eq( response.features.feature[1].attributes['UNIQUE_ID'], "514504b5-0458-461d-b540-8e81a454f619", "field 1 for feature 2 is correct" );
115         t.eq( response.features.feature[1].attributes['LABEL'], "LIBRARY2", "field 2 for feature 2 is correct" );
116         t.eq( response.features.feature[1].attributes['Y_COORD'], "39.75", "field 3 for feature 2 is correct" );
117         t.eq( response.features.feature[1].attributes['X_COORD'], "-104.42", "field 4 for feature 2 is correct" );
118         t.eq( response.features.feature[1].attributes['#SHAPE#'], "[Geometry]", "field 5 for feature 2 is correct" );
119         t.eq( response.features.feature[1].attributes['OBJECTID'], "2", "field 6 for feature 2 is correct" );
120     }
121
122     //
123     // cause an error by parsing bad axl
124     //
125     function test_Format_ArcXML_parseerror(t) {
126         t.plan(1);
127         var f = new OpenLayers.Format.ArcXML();
128         
129         try {
130             f.read( '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><NO END TAG>' );
131             t.fail("parsing failed to fail")
132         } catch (ex) {
133             t.ok( true, "Exception message indicates parsing error." );
134         }
135     }
136
137     //
138     // create an arcxml image request, and verify that it matches a known image request
139     //
140     function test_format_ArcXML_write1(t) {
141         var options = {
142             requesttype:'image',
143             envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
144             layers: [],
145             tileSize: new OpenLayers.Size( 256,256 ),
146             featureCoordSys: '4326',
147             filterCoordSys: '4326'
148         };
149         var truth = '<ARCXML version="1.1"><REQUEST><GET_IMAGE><PROPERTIES><FEATURECOORDSYS id="4326"/><FILTERCOORDSYS id="4326"/><ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90"/><IMAGESIZE height="256" width="256"/></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>';
150         axl_write(t,options,truth);
151     }
152
153     //
154     // create an arcxml image request that specifies layer visibilities, and
155     // verify that it matches a known image request
156     //
157     function test_format_ArcXML_write2(t) {
158         var options = {
159             requesttype:'image',
160             envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
161             layers: [{
162                 id: "0",
163                 visible: "true"
164             }],
165             tileSize: new OpenLayers.Size( 256,256 ),
166             featureCoordSys: '4326',
167             filterCoordSys: '4326'
168         };
169         var truth = '<ARCXML version="1.1"><REQUEST><GET_IMAGE><PROPERTIES><FEATURECOORDSYS id="4326"/><FILTERCOORDSYS id="4326"/><ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90"/><IMAGESIZE height="256" width="256"/><LAYERLIST><LAYERDEF id="0" visible="true"/></LAYERLIST></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>';
170         axl_write(t, options, truth );
171     }
172
173     //
174     // create an arcxml image request that performs a query for thematic mapping,
175     // and verify that it matches a known image request
176     //
177     function test_format_ArcXML_write3(t) {
178         var options = {
179             requesttype:'image',
180             envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
181             layers: [{
182                 id: "0",
183                 visible: "true",
184                 query: {
185                     where: "COMPANY='AVENCIA'"
186                 }
187             }],
188             tileSize: new OpenLayers.Size( 256,256 ),
189             featureCoordSys: '4326',
190             filterCoordSys: '4326'
191         };
192         var truth = '<ARCXML version="1.1"><REQUEST><GET_IMAGE><PROPERTIES><FEATURECOORDSYS id="4326"/><FILTERCOORDSYS id="4326"/><ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90"/><IMAGESIZE height="256" width="256"/><LAYERLIST><LAYERDEF id="0" visible="true"><QUERY where="COMPANY=\'AVENCIA\'"/></LAYERDEF></LAYERLIST></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>';
193         axl_write(t, options, truth );
194     }
195
196     //
197     // create an arcxml image request that performs a spatial query for thematic mapping,
198     // and verify that it matches a known image request
199     //
200     function test_format_ArcXML_write4(t) {
201         var options = {
202             requesttype:'image',
203             envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
204             layers: [{
205                 id: "0",
206                 visible: "true",
207                 query: {
208                     spatialfilter: true,
209                     where: "COMPANY='AVENCIA'"
210                 }
211             }],
212             tileSize: new OpenLayers.Size( 256,256 ),
213             featureCoordSys: '4326',
214             filterCoordSys: '4326'
215         };
216         var truth = '<ARCXML version="1.1"><REQUEST><GET_IMAGE><PROPERTIES><FEATURECOORDSYS id="4326"/><FILTERCOORDSYS id="4326"/><ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90"/><IMAGESIZE height="256" width="256"/><LAYERLIST><LAYERDEF id="0" visible="true"><SPATIALQUERY where="COMPANY=\'AVENCIA\'"/></LAYERDEF></LAYERLIST></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>';
217         axl_write(t, options, truth );
218     }
219
220     //
221     // create an arcxml image request that performs a thematic map request, and
222     // verify that it matches a known image request.
223     //
224     function test_format_ArcXML_write5(t) {
225         var options = {
226             requesttype:'image',
227             envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
228             layers: [{
229                 id: "0",
230                 visible: "true",
231                 query: {
232                     spatialfilter: true,
233                     where: "COMPANY='AVENCIA'"
234                 },
235                 renderer: {
236                     type: 'valuemap',
237                     lookupfield: 'lookup',
238                     ranges: [{
239                         lower: 0,
240                         upper: 10,
241                         symbol: {
242                             type: 'simplepolygon',
243                             fillcolor: '0,0,0'
244                         }
245                     },{
246                         lower: 10,
247                         upper: 20,
248                         symbol: {
249                             type: 'simplepolygon',
250                             fillcolor: '255,255,255'
251                         }
252                     }]
253                 }
254             }],
255             tileSize: new OpenLayers.Size( 256,256 ),
256             featureCoordSys: '4326',
257             filterCoordSys: '4326'
258         };
259         var truth = '<ARCXML version="1.1"><REQUEST><GET_IMAGE><PROPERTIES><FEATURECOORDSYS id="4326"/><FILTERCOORDSYS id="4326"/><ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90"/><IMAGESIZE height="256" width="256"/><LAYERLIST><LAYERDEF id="0" visible="true"><SPATIALQUERY where="COMPANY=\'AVENCIA\'"/><VALUEMAPRENDERER lookupfield="lookup"><RANGE lower="0" upper="10"><SIMPLEPOLYGONSYMBOL fillcolor="0,0,0"/></RANGE><RANGE lower="10" upper="20"><SIMPLEPOLYGONSYMBOL fillcolor="255,255,255"/></RANGE></VALUEMAPRENDERER></LAYERDEF></LAYERLIST></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>';
260         axl_write(t, options, truth );
261     }
262
263     //
264     // helper function to write some axl, and compare it against a truth axl string
265     //
266     function axl_write(t, options, truth) {
267         t.plan(1);
268         
269         var f = new OpenLayers.Format.ArcXML( options );
270         var arcxml = f.write();
271         t.eq( arcxml, truth, "ArcXML request is correct.");
272     }
273     </script> 
274 </head> 
275 <body> 
276 </body> 
277 </html>