3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
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>';
10 // creating a new arcxml format creates an object that has a read and write function
12 function test_Format_ArcXML_constructor1(t) {
15 var format = new OpenLayers.Format.ArcXML();
16 t.ok(format instanceof OpenLayers.Format.ArcXML,
17 "new OpenLayers.Format.ArcXML returns object" );
19 t.ok(format.request, null, "no options creates a null request");
21 t.eq(typeof format.read, "function", "format has a read function");
22 t.eq(typeof format.write, "function", "format has a write function");
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.
29 function test_Format_ArcXML_constructor2(t) {
34 envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
36 tileSize: new OpenLayers.Size( 256,256 ),
37 featureCoordSys: '4326',
38 filterCoordSys: '4326'
41 var format = new OpenLayers.Format.ArcXML( options );
42 t.ok(format instanceof OpenLayers.Format.ArcXML,
43 "new OpenLayers.Format.ArcXML returns object" );
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" );
50 t.eq(typeof format.read, "function", "format has a read function");
51 t.eq(typeof format.write, "function", "format has a write function");
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
58 function test_Format_ArcXML_constructor3(t) {
65 var format = new OpenLayers.Format.ArcXML( options );
66 t.ok(format instanceof OpenLayers.Format.ArcXML,
67 "new OpenLayers.Format.ArcXML returns object" );
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" );
74 t.eq(typeof format.read, "function", "format has a read function");
75 t.eq(typeof format.write, "function", "format has a write function");
79 // read in a known good axl image response
81 function test_Format_ArcXML_read1(t) {
83 var f = new OpenLayers.Format.ArcXML();
84 var response = f.read(axl_image_response);
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");
93 // read in a known good axl feature response
95 function test_Format_ArcXML_read2(t) {
97 var f = new OpenLayers.Format.ArcXML();
98 var response = f.read(axl_feature_response);
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" );
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" );
123 // cause an error by parsing bad axl
125 function test_Format_ArcXML_parseerror(t) {
127 var f = new OpenLayers.Format.ArcXML();
130 f.read( '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><NO END TAG>' );
131 t.fail("parsing failed to fail")
133 t.ok( true, "Exception message indicates parsing error." );
138 // create an arcxml image request, and verify that it matches a known image request
140 function test_format_ArcXML_write1(t) {
143 envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
145 tileSize: new OpenLayers.Size( 256,256 ),
146 featureCoordSys: '4326',
147 filterCoordSys: '4326'
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);
154 // create an arcxml image request that specifies layer visibilities, and
155 // verify that it matches a known image request
157 function test_format_ArcXML_write2(t) {
160 envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
165 tileSize: new OpenLayers.Size( 256,256 ),
166 featureCoordSys: '4326',
167 filterCoordSys: '4326'
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 );
174 // create an arcxml image request that performs a query for thematic mapping,
175 // and verify that it matches a known image request
177 function test_format_ArcXML_write3(t) {
180 envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
185 where: "COMPANY='AVENCIA'"
188 tileSize: new OpenLayers.Size( 256,256 ),
189 featureCoordSys: '4326',
190 filterCoordSys: '4326'
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 );
197 // create an arcxml image request that performs a spatial query for thematic mapping,
198 // and verify that it matches a known image request
200 function test_format_ArcXML_write4(t) {
203 envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
209 where: "COMPANY='AVENCIA'"
212 tileSize: new OpenLayers.Size( 256,256 ),
213 featureCoordSys: '4326',
214 filterCoordSys: '4326'
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 );
221 // create an arcxml image request that performs a thematic map request, and
222 // verify that it matches a known image request.
224 function test_format_ArcXML_write5(t) {
227 envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
233 where: "COMPANY='AVENCIA'"
237 lookupfield: 'lookup',
242 type: 'simplepolygon',
249 type: 'simplepolygon',
250 fillcolor: '255,255,255'
255 tileSize: new OpenLayers.Size( 256,256 ),
256 featureCoordSys: '4326',
257 filterCoordSys: '4326'
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 );
264 // helper function to write some axl, and compare it against a truth axl string
266 function axl_write(t, options, truth) {
269 var f = new OpenLayers.Format.ArcXML( options );
270 var arcxml = f.write();
271 t.eq( arcxml, truth, "ArcXML request is correct.");