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
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
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>';
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>';
//
// creating a new arcxml format creates an object that has a read and write function
//
function test_Format_ArcXML_constructor1(t) {
t.plan(4);
var format = new OpenLayers.Format.ArcXML();
t.ok(format instanceof OpenLayers.Format.ArcXML,
"new OpenLayers.Format.ArcXML returns object" );
t.ok(format.request, null, "no options creates a null request");
t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function");
}
//
// creating a new arcxml format with a set of options for an image request
// creates a request child object, and a get_image grandchild.
//
function test_Format_ArcXML_constructor2(t) {
t.plan(6);
var options = {
requesttype:'image',
envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
layers: [],
tileSize: new OpenLayers.Size( 256,256 ),
featureCoordSys: '4326',
filterCoordSys: '4326'
};
var format = new OpenLayers.Format.ArcXML( options );
t.ok(format instanceof OpenLayers.Format.ArcXML,
"new OpenLayers.Format.ArcXML returns object" );
t.ok(format.request instanceof OpenLayers.Format.ArcXML.Request,
"constructor with 'image' requesttype generates a request");
t.ok( format.request.get_image !== null, "get_image property exists" );
t.ok( format.request.get_feature === null, "get_feature property does not exists" );
t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function");
}
//
// creating a new arcxml format with a set of options for a feature request
// creates a request child object, and a get_feature grandchild
//
function test_Format_ArcXML_constructor3(t) {
t.plan(6);
var options = {
requesttype:'feature'
};
var format = new OpenLayers.Format.ArcXML( options );
t.ok(format instanceof OpenLayers.Format.ArcXML,
"new OpenLayers.Format.ArcXML returns object" );
t.ok(format.request instanceof OpenLayers.Format.ArcXML.Request,
"constructor with 'feature' requesttype generates a request");
t.ok( format.request.get_feature !== null, "get_feature property exists" );
t.ok( format.request.get_image === null, "get_image property does not exists" );
t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function");
}
//
// read in a known good axl image response
//
function test_Format_ArcXML_read1(t) {
t.plan(4);
var f = new OpenLayers.Format.ArcXML();
var response = f.read(axl_image_response);
t.ok(response !== null, "get_image response object is not null" );
t.ok(response.image !== null, "get_image image tag is not null");
t.ok(response.image.envelope !== null, "get_image image envelope tag is not null");
t.ok(response.image.output !== null, "get_image image output tag is not null");
}
//
// read in a known good axl feature response
//
function test_Format_ArcXML_read2(t) {
t.plan(10);
var f = new OpenLayers.Format.ArcXML();
var response = f.read(axl_feature_response);
t.ok(response !== null, "get_feature response object is not null" );
t.ok(response.features !== null, "get_feature features tag is not null");
t.ok(response.features.envelope !== null, "get_feature envelope tag is not null");
t.eq(response.features.featurecount, "2", "feature count is 2" );
// test the second feature parsed
// <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" />
t.eq( response.features.feature[1].attributes['UNIQUE_ID'], "514504b5-0458-461d-b540-8e81a454f619", "field 1 for feature 2 is correct" );
t.eq( response.features.feature[1].attributes['LABEL'], "LIBRARY2", "field 2 for feature 2 is correct" );
t.eq( response.features.feature[1].attributes['Y_COORD'], "39.75", "field 3 for feature 2 is correct" );
t.eq( response.features.feature[1].attributes['X_COORD'], "-104.42", "field 4 for feature 2 is correct" );
t.eq( response.features.feature[1].attributes['#SHAPE#'], "[Geometry]", "field 5 for feature 2 is correct" );
t.eq( response.features.feature[1].attributes['OBJECTID'], "2", "field 6 for feature 2 is correct" );
}
//
// cause an error by parsing bad axl
//
function test_Format_ArcXML_parseerror(t) {
t.plan(1);
var f = new OpenLayers.Format.ArcXML();
try {
f.read( '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><NO END TAG>' );
t.fail("parsing failed to fail")
} catch (ex) {
t.ok( true, "Exception message indicates parsing error." );
}
}
//
// create an arcxml image request, and verify that it matches a known image request
//
function test_format_ArcXML_write1(t) {
var options = {
requesttype:'image',
envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
layers: [],
tileSize: new OpenLayers.Size( 256,256 ),
featureCoordSys: '4326',
filterCoordSys: '4326'
};
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>';
axl_write(t,options,truth);
}
//
// create an arcxml image request that specifies layer visibilities, and
// verify that it matches a known image request
//
function test_format_ArcXML_write2(t) {
var options = {
requesttype:'image',
envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
layers: [{
id: "0",
visible: "true"
}],
tileSize: new OpenLayers.Size( 256,256 ),
featureCoordSys: '4326',
filterCoordSys: '4326'
};
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>';
axl_write(t, options, truth );
}
//
// create an arcxml image request that performs a query for thematic mapping,
// and verify that it matches a known image request
//
function test_format_ArcXML_write3(t) {
var options = {
requesttype:'image',
envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
layers: [{
id: "0",
visible: "true",
query: {
where: "COMPANY='AVENCIA'"
}
}],
tileSize: new OpenLayers.Size( 256,256 ),
featureCoordSys: '4326',
filterCoordSys: '4326'
};
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>';
axl_write(t, options, truth );
}
//
// create an arcxml image request that performs a spatial query for thematic mapping,
// and verify that it matches a known image request
//
function test_format_ArcXML_write4(t) {
var options = {
requesttype:'image',
envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
layers: [{
id: "0",
visible: "true",
query: {
spatialfilter: true,
where: "COMPANY='AVENCIA'"
}
}],
tileSize: new OpenLayers.Size( 256,256 ),
featureCoordSys: '4326',
filterCoordSys: '4326'
};
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>';
axl_write(t, options, truth );
}
//
// create an arcxml image request that performs a thematic map request, and
// verify that it matches a known image request.
//
function test_format_ArcXML_write5(t) {
var options = {
requesttype:'image',
envelope: new OpenLayers.Bounds( -180, -90, 180, 90 ).toArray(),
layers: [{
id: "0",
visible: "true",
query: {
spatialfilter: true,
where: "COMPANY='AVENCIA'"
},
renderer: {
type: 'valuemap',
lookupfield: 'lookup',
ranges: [{
lower: 0,
upper: 10,
symbol: {
type: 'simplepolygon',
fillcolor: '0,0,0'
}
},{
lower: 10,
upper: 20,
symbol: {
type: 'simplepolygon',
fillcolor: '255,255,255'
}
}]
}
}],
tileSize: new OpenLayers.Size( 256,256 ),
featureCoordSys: '4326',
filterCoordSys: '4326'
};
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>';
axl_write(t, options, truth );
}
//
// helper function to write some axl, and compare it against a truth axl string
//
function axl_write(t, options, truth) {
t.plan(1);
var f = new OpenLayers.Format.ArcXML( options );
var arcxml = f.write();
t.eq( arcxml, truth, "ArcXML request is correct.");
}
</script>
</head>
<body>
</body>
</html>
|