1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository for the
|
4
|
* full text of the license. */
|
5
|
|
6
|
/**
|
7
|
* @requires OpenLayers/Format/XML.js
|
8
|
* @requires OpenLayers/Geometry/Polygon.js
|
9
|
* @requires OpenLayers/Geometry/Point.js
|
10
|
* @requires OpenLayers/Geometry/MultiPolygon.js
|
11
|
* @requires OpenLayers/Geometry/LinearRing.js
|
12
|
*/
|
13
|
|
14
|
/**
|
15
|
* Class: OpenLayers.Format.ArcXML
|
16
|
* Read/Write ArcXML. Create a new instance with the <OpenLayers.Format.ArcXML>
|
17
|
* constructor.
|
18
|
*
|
19
|
* Inherits from:
|
20
|
* - <OpenLayers.Format.XML>
|
21
|
*/
|
22
|
OpenLayers.Format.ArcXML = OpenLayers.Class(OpenLayers.Format.XML, {
|
23
|
|
24
|
/**
|
25
|
* Property: fontStyleKeys
|
26
|
* {Array} List of keys used in font styling.
|
27
|
*/
|
28
|
fontStyleKeys: [
|
29
|
'antialiasing', 'blockout', 'font', 'fontcolor','fontsize', 'fontstyle',
|
30
|
'glowing', 'interval', 'outline', 'printmode', 'shadow', 'transparency'
|
31
|
],
|
32
|
|
33
|
/**
|
34
|
* Property: request
|
35
|
* A get_image request destined for an ArcIMS server.
|
36
|
*/
|
37
|
request: null,
|
38
|
|
39
|
/**
|
40
|
* Property: response
|
41
|
* A parsed response from an ArcIMS server.
|
42
|
*/
|
43
|
response: null,
|
44
|
|
45
|
/**
|
46
|
* Constructor: OpenLayers.Format.ArcXML
|
47
|
* Create a new parser/writer for ArcXML. Create an instance of this class
|
48
|
* to begin authoring a request to an ArcIMS service. This is used
|
49
|
* primarily by the ArcIMS layer, but could be used to do other wild
|
50
|
* stuff, like geocoding.
|
51
|
*
|
52
|
* Parameters:
|
53
|
* options - {Object} An optional object whose properties will be set on
|
54
|
* this instance.
|
55
|
*/
|
56
|
initialize: function(options) {
|
57
|
this.request = new OpenLayers.Format.ArcXML.Request();
|
58
|
this.response = new OpenLayers.Format.ArcXML.Response();
|
59
|
|
60
|
if (options) {
|
61
|
if (options.requesttype == "feature") {
|
62
|
this.request.get_image = null;
|
63
|
|
64
|
var qry = this.request.get_feature.query;
|
65
|
this.addCoordSys(qry.featurecoordsys, options.featureCoordSys);
|
66
|
this.addCoordSys(qry.filtercoordsys, options.filterCoordSys);
|
67
|
|
68
|
if (options.polygon) {
|
69
|
qry.isspatial = true;
|
70
|
qry.spatialfilter.polygon = options.polygon;
|
71
|
} else if (options.envelope) {
|
72
|
qry.isspatial = true;
|
73
|
qry.spatialfilter.envelope = {minx:0, miny:0, maxx:0, maxy:0};
|
74
|
this.parseEnvelope(qry.spatialfilter.envelope, options.envelope);
|
75
|
}
|
76
|
} else if (options.requesttype == "image") {
|
77
|
this.request.get_feature = null;
|
78
|
|
79
|
var props = this.request.get_image.properties;
|
80
|
this.parseEnvelope(props.envelope, options.envelope);
|
81
|
|
82
|
this.addLayers(props.layerlist, options.layers);
|
83
|
this.addImageSize(props.imagesize, options.tileSize);
|
84
|
this.addCoordSys(props.featurecoordsys, options.featureCoordSys);
|
85
|
this.addCoordSys(props.filtercoordsys, options.filterCoordSys);
|
86
|
} else {
|
87
|
// if an arcxml object is being created with no request type, it is
|
88
|
// probably going to consume a response, so do not throw an error if
|
89
|
// the requesttype is not defined
|
90
|
this.request = null;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
95
|
},
|
96
|
|
97
|
/**
|
98
|
* Method: parseEnvelope
|
99
|
* Parse an array of coordinates into an ArcXML envelope structure.
|
100
|
*
|
101
|
* Parameters:
|
102
|
* env - {Object} An envelope object that will contain the parsed coordinates.
|
103
|
* arr - {Array(double)} An array of coordinates in the order: [ minx, miny, maxx, maxy ]
|
104
|
*/
|
105
|
parseEnvelope: function(env, arr) {
|
106
|
if (arr && arr.length == 4) {
|
107
|
env.minx = arr[0];
|
108
|
env.miny = arr[1];
|
109
|
env.maxx = arr[2];
|
110
|
env.maxy = arr[3];
|
111
|
}
|
112
|
},
|
113
|
|
114
|
/**
|
115
|
* Method: addLayers
|
116
|
* Add a collection of layers to another collection of layers. Each layer in the list is tuple of
|
117
|
* { id, visible }. These layer collections represent the
|
118
|
* /ARCXML/REQUEST/get_image/PROPERTIES/LAYERLIST/LAYERDEF items in ArcXML
|
119
|
*
|
120
|
* TODO: Add support for dynamic layer rendering.
|
121
|
*
|
122
|
* Parameters:
|
123
|
* ll - {Array({id,visible})} A list of layer definitions.
|
124
|
* lyrs - {Array({id,visible})} A list of layer definitions.
|
125
|
*/
|
126
|
addLayers: function(ll, lyrs) {
|
127
|
for(var lind = 0, len=lyrs.length; lind < len; lind++) {
|
128
|
ll.push(lyrs[lind]);
|
129
|
}
|
130
|
},
|
131
|
|
132
|
/**
|
133
|
* Method: addImageSize
|
134
|
* Set the size of the requested image.
|
135
|
*
|
136
|
* Parameters:
|
137
|
* imsize - {Object} An ArcXML imagesize object.
|
138
|
* olsize - {<OpenLayers.Size>} The image size to set.
|
139
|
*/
|
140
|
addImageSize: function(imsize, olsize) {
|
141
|
if (olsize !== null) {
|
142
|
imsize.width = olsize.w;
|
143
|
imsize.height = olsize.h;
|
144
|
imsize.printwidth = olsize.w;
|
145
|
imsize.printheight = olsize.h;
|
146
|
}
|
147
|
},
|
148
|
|
149
|
/**
|
150
|
* Method: addCoordSys
|
151
|
* Add the coordinate system information to an object. The object may be
|
152
|
*
|
153
|
* Parameters:
|
154
|
* featOrFilt - {Object} A featurecoordsys or filtercoordsys ArcXML structure.
|
155
|
* fsys - {String} or {<OpenLayers.Projection>} or {filtercoordsys} or
|
156
|
* {featurecoordsys} A projection representation. If it's a {String},
|
157
|
* the value is assumed to be the SRID. If it's a {OpenLayers.Projection}
|
158
|
* AND Proj4js is available, the projection number and name are extracted
|
159
|
* from there. If it's a filter or feature ArcXML structure, it is copied.
|
160
|
*/
|
161
|
addCoordSys: function(featOrFilt, fsys) {
|
162
|
if (typeof fsys == "string") {
|
163
|
featOrFilt.id = parseInt(fsys);
|
164
|
featOrFilt.string = fsys;
|
165
|
}
|
166
|
// is this a proj4js instance?
|
167
|
else if (typeof fsys == "object" && fsys.proj !== null){
|
168
|
featOrFilt.id = fsys.proj.srsProjNumber;
|
169
|
featOrFilt.string = fsys.proj.srsCode;
|
170
|
} else {
|
171
|
featOrFilt = fsys;
|
172
|
}
|
173
|
},
|
174
|
|
175
|
/**
|
176
|
* APIMethod: iserror
|
177
|
* Check to see if the response from the server was an error.
|
178
|
*
|
179
|
* Parameters:
|
180
|
* data - {String} or {DOMElement} data to read/parse. If nothing is supplied,
|
181
|
* the current response is examined.
|
182
|
*
|
183
|
* Returns:
|
184
|
* {Boolean} true if the response was an error.
|
185
|
*/
|
186
|
iserror: function(data) {
|
187
|
var ret = null;
|
188
|
|
189
|
if (!data) {
|
190
|
ret = (this.response.error !== '');
|
191
|
} else {
|
192
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
193
|
var errorNodes = data.documentElement.getElementsByTagName("ERROR");
|
194
|
ret = (errorNodes !== null && errorNodes.length > 0);
|
195
|
}
|
196
|
|
197
|
return ret;
|
198
|
},
|
199
|
|
200
|
/**
|
201
|
* APIMethod: read
|
202
|
* Read data from a string, and return an response.
|
203
|
*
|
204
|
* Parameters:
|
205
|
* data - {String} or {DOMElement} data to read/parse.
|
206
|
*
|
207
|
* Returns:
|
208
|
* {<OpenLayers.Format.ArcXML.Response>} An ArcXML response. Note that this response
|
209
|
* data may change in the future.
|
210
|
*/
|
211
|
read: function(data) {
|
212
|
if(typeof data == "string") {
|
213
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
214
|
}
|
215
|
|
216
|
var arcNode = null;
|
217
|
if (data && data.documentElement) {
|
218
|
if(data.documentElement.nodeName == "ARCXML") {
|
219
|
arcNode = data.documentElement;
|
220
|
} else {
|
221
|
arcNode = data.documentElement.getElementsByTagName("ARCXML")[0];
|
222
|
}
|
223
|
}
|
224
|
|
225
|
// in Safari, arcNode will be there but will have a child named
|
226
|
// parsererror
|
227
|
if (!arcNode || arcNode.firstChild.nodeName === 'parsererror') {
|
228
|
var error, source;
|
229
|
try {
|
230
|
error = data.firstChild.nodeValue;
|
231
|
source = data.firstChild.childNodes[1].firstChild.nodeValue;
|
232
|
} catch (err) {
|
233
|
// pass
|
234
|
}
|
235
|
throw {
|
236
|
message: "Error parsing the ArcXML request",
|
237
|
error: error,
|
238
|
source: source
|
239
|
};
|
240
|
}
|
241
|
|
242
|
var response = this.parseResponse(arcNode);
|
243
|
return response;
|
244
|
},
|
245
|
|
246
|
/**
|
247
|
* APIMethod: write
|
248
|
* Generate an ArcXml document string for sending to an ArcIMS server.
|
249
|
*
|
250
|
* Returns:
|
251
|
* {String} A string representing the ArcXML document request.
|
252
|
*/
|
253
|
write: function(request) {
|
254
|
if (!request) {
|
255
|
request = this.request;
|
256
|
}
|
257
|
var root = this.createElementNS("", "ARCXML");
|
258
|
root.setAttribute("version","1.1");
|
259
|
|
260
|
var reqElem = this.createElementNS("", "REQUEST");
|
261
|
|
262
|
if (request.get_image != null) {
|
263
|
var getElem = this.createElementNS("", "GET_IMAGE");
|
264
|
reqElem.appendChild(getElem);
|
265
|
|
266
|
var propElem = this.createElementNS("", "PROPERTIES");
|
267
|
getElem.appendChild(propElem);
|
268
|
|
269
|
var props = request.get_image.properties;
|
270
|
if (props.featurecoordsys != null) {
|
271
|
var feat = this.createElementNS("", "FEATURECOORDSYS");
|
272
|
propElem.appendChild(feat);
|
273
|
|
274
|
if (props.featurecoordsys.id === 0) {
|
275
|
feat.setAttribute("string", props.featurecoordsys['string']);
|
276
|
}
|
277
|
else {
|
278
|
feat.setAttribute("id", props.featurecoordsys.id);
|
279
|
}
|
280
|
}
|
281
|
|
282
|
if (props.filtercoordsys != null) {
|
283
|
var filt = this.createElementNS("", "FILTERCOORDSYS");
|
284
|
propElem.appendChild(filt);
|
285
|
|
286
|
if (props.filtercoordsys.id === 0) {
|
287
|
filt.setAttribute("string", props.filtercoordsys.string);
|
288
|
}
|
289
|
else {
|
290
|
filt.setAttribute("id", props.filtercoordsys.id);
|
291
|
}
|
292
|
}
|
293
|
|
294
|
if (props.envelope != null) {
|
295
|
var env = this.createElementNS("", "ENVELOPE");
|
296
|
propElem.appendChild(env);
|
297
|
|
298
|
env.setAttribute("minx", props.envelope.minx);
|
299
|
env.setAttribute("miny", props.envelope.miny);
|
300
|
env.setAttribute("maxx", props.envelope.maxx);
|
301
|
env.setAttribute("maxy", props.envelope.maxy);
|
302
|
}
|
303
|
|
304
|
var imagesz = this.createElementNS("", "IMAGESIZE");
|
305
|
propElem.appendChild(imagesz);
|
306
|
|
307
|
imagesz.setAttribute("height", props.imagesize.height);
|
308
|
imagesz.setAttribute("width", props.imagesize.width);
|
309
|
|
310
|
if (props.imagesize.height != props.imagesize.printheight ||
|
311
|
props.imagesize.width != props.imagesize.printwidth) {
|
312
|
imagesz.setAttribute("printheight", props.imagesize.printheight);
|
313
|
imagesz.setArrtibute("printwidth", props.imagesize.printwidth);
|
314
|
}
|
315
|
|
316
|
if (props.background != null) {
|
317
|
var backgrnd = this.createElementNS("", "BACKGROUND");
|
318
|
propElem.appendChild(backgrnd);
|
319
|
|
320
|
backgrnd.setAttribute("color",
|
321
|
props.background.color.r + "," +
|
322
|
props.background.color.g + "," +
|
323
|
props.background.color.b);
|
324
|
|
325
|
if (props.background.transcolor !== null) {
|
326
|
backgrnd.setAttribute("transcolor",
|
327
|
props.background.transcolor.r + "," +
|
328
|
props.background.transcolor.g + "," +
|
329
|
props.background.transcolor.b);
|
330
|
}
|
331
|
}
|
332
|
|
333
|
if (props.layerlist != null && props.layerlist.length > 0) {
|
334
|
var layerlst = this.createElementNS("", "LAYERLIST");
|
335
|
propElem.appendChild(layerlst);
|
336
|
|
337
|
for (var ld = 0; ld < props.layerlist.length; ld++) {
|
338
|
var ldef = this.createElementNS("", "LAYERDEF");
|
339
|
layerlst.appendChild(ldef);
|
340
|
|
341
|
ldef.setAttribute("id", props.layerlist[ld].id);
|
342
|
ldef.setAttribute("visible", props.layerlist[ld].visible);
|
343
|
|
344
|
if (typeof props.layerlist[ld].query == "object") {
|
345
|
var query = props.layerlist[ld].query;
|
346
|
|
347
|
if (query.where.length < 0) {
|
348
|
continue;
|
349
|
}
|
350
|
|
351
|
var queryElem = null;
|
352
|
if (typeof query.spatialfilter == "boolean" && query.spatialfilter) {
|
353
|
// handle spatial filter madness
|
354
|
queryElem = this.createElementNS("", "SPATIALQUERY");
|
355
|
}
|
356
|
else {
|
357
|
queryElem = this.createElementNS("", "QUERY");
|
358
|
}
|
359
|
|
360
|
queryElem.setAttribute("where", query.where);
|
361
|
|
362
|
if (typeof query.accuracy == "number" && query.accuracy > 0) {
|
363
|
queryElem.setAttribute("accuracy", query.accuracy);
|
364
|
}
|
365
|
if (typeof query.featurelimit == "number" && query.featurelimit < 2000) {
|
366
|
queryElem.setAttribute("featurelimit", query.featurelimit);
|
367
|
}
|
368
|
if (typeof query.subfields == "string" && query.subfields != "#ALL#") {
|
369
|
queryElem.setAttribute("subfields", query.subfields);
|
370
|
}
|
371
|
if (typeof query.joinexpression == "string" && query.joinexpression.length > 0) {
|
372
|
queryElem.setAttribute("joinexpression", query.joinexpression);
|
373
|
}
|
374
|
if (typeof query.jointables == "string" && query.jointables.length > 0) {
|
375
|
queryElem.setAttribute("jointables", query.jointables);
|
376
|
}
|
377
|
|
378
|
ldef.appendChild(queryElem);
|
379
|
}
|
380
|
|
381
|
if (typeof props.layerlist[ld].renderer == "object") {
|
382
|
this.addRenderer(ldef, props.layerlist[ld].renderer);
|
383
|
}
|
384
|
}
|
385
|
}
|
386
|
} else if (request.get_feature != null) {
|
387
|
var getElem = this.createElementNS("", "GET_FEATURES");
|
388
|
getElem.setAttribute("outputmode", "newxml");
|
389
|
getElem.setAttribute("checkesc", "true");
|
390
|
|
391
|
if (request.get_feature.geometry) {
|
392
|
getElem.setAttribute("geometry", request.get_feature.geometry);
|
393
|
}
|
394
|
else {
|
395
|
getElem.setAttribute("geometry", "false");
|
396
|
}
|
397
|
|
398
|
if (request.get_feature.compact) {
|
399
|
getElem.setAttribute("compact", request.get_feature.compact);
|
400
|
}
|
401
|
|
402
|
if (request.get_feature.featurelimit == "number") {
|
403
|
getElem.setAttribute("featurelimit", request.get_feature.featurelimit);
|
404
|
}
|
405
|
|
406
|
getElem.setAttribute("globalenvelope", "true");
|
407
|
reqElem.appendChild(getElem);
|
408
|
|
409
|
if (request.get_feature.layer != null && request.get_feature.layer.length > 0) {
|
410
|
var lyrElem = this.createElementNS("", "LAYER");
|
411
|
lyrElem.setAttribute("id", request.get_feature.layer);
|
412
|
getElem.appendChild(lyrElem);
|
413
|
}
|
414
|
|
415
|
var fquery = request.get_feature.query;
|
416
|
if (fquery != null) {
|
417
|
var qElem = null;
|
418
|
if (fquery.isspatial) {
|
419
|
qElem = this.createElementNS("", "SPATIALQUERY");
|
420
|
} else {
|
421
|
qElem = this.createElementNS("", "QUERY");
|
422
|
}
|
423
|
getElem.appendChild(qElem);
|
424
|
|
425
|
if (typeof fquery.accuracy == "number") {
|
426
|
qElem.setAttribute("accuracy", fquery.accuracy);
|
427
|
}
|
428
|
//qElem.setAttribute("featurelimit", "5");
|
429
|
|
430
|
if (fquery.featurecoordsys != null) {
|
431
|
var fcsElem1 = this.createElementNS("", "FEATURECOORDSYS");
|
432
|
|
433
|
if (fquery.featurecoordsys.id == 0) {
|
434
|
fcsElem1.setAttribute("string", fquery.featurecoordsys.string);
|
435
|
} else {
|
436
|
fcsElem1.setAttribute("id", fquery.featurecoordsys.id);
|
437
|
}
|
438
|
qElem.appendChild(fcsElem1);
|
439
|
}
|
440
|
|
441
|
if (fquery.filtercoordsys != null) {
|
442
|
var fcsElem2 = this.createElementNS("", "FILTERCOORDSYS");
|
443
|
|
444
|
if (fquery.filtercoordsys.id === 0) {
|
445
|
fcsElem2.setAttribute("string", fquery.filtercoordsys.string);
|
446
|
} else {
|
447
|
fcsElem2.setAttribute("id", fquery.filtercoordsys.id);
|
448
|
}
|
449
|
qElem.appendChild(fcsElem2);
|
450
|
}
|
451
|
|
452
|
if (fquery.buffer > 0) {
|
453
|
var bufElem = this.createElementNS("", "BUFFER");
|
454
|
bufElem.setAttribute("distance", fquery.buffer);
|
455
|
qElem.appendChild(bufElem);
|
456
|
}
|
457
|
|
458
|
if (fquery.isspatial) {
|
459
|
var spfElem = this.createElementNS("", "SPATIALFILTER");
|
460
|
spfElem.setAttribute("relation", fquery.spatialfilter.relation);
|
461
|
qElem.appendChild(spfElem);
|
462
|
|
463
|
if (fquery.spatialfilter.envelope) {
|
464
|
var envElem = this.createElementNS("", "ENVELOPE");
|
465
|
envElem.setAttribute("minx", fquery.spatialfilter.envelope.minx);
|
466
|
envElem.setAttribute("miny", fquery.spatialfilter.envelope.miny);
|
467
|
envElem.setAttribute("maxx", fquery.spatialfilter.envelope.maxx);
|
468
|
envElem.setAttribute("maxy", fquery.spatialfilter.envelope.maxy);
|
469
|
spfElem.appendChild(envElem);
|
470
|
} else if(typeof fquery.spatialfilter.polygon == "object") {
|
471
|
spfElem.appendChild(this.writePolygonGeometry(fquery.spatialfilter.polygon));
|
472
|
}
|
473
|
}
|
474
|
|
475
|
if (fquery.where != null && fquery.where.length > 0) {
|
476
|
qElem.setAttribute("where", fquery.where);
|
477
|
}
|
478
|
}
|
479
|
}
|
480
|
|
481
|
root.appendChild(reqElem);
|
482
|
|
483
|
return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
|
484
|
},
|
485
|
|
486
|
|
487
|
addGroupRenderer: function(ldef, toprenderer) {
|
488
|
var topRelem = this.createElementNS("", "GROUPRENDERER");
|
489
|
ldef.appendChild(topRelem);
|
490
|
|
491
|
for (var rind = 0; rind < toprenderer.length; rind++) {
|
492
|
var renderer = toprenderer[rind];
|
493
|
this.addRenderer(topRelem, renderer);
|
494
|
}
|
495
|
},
|
496
|
|
497
|
|
498
|
addRenderer: function(topRelem, renderer) {
|
499
|
if (OpenLayers.Util.isArray(renderer)) {
|
500
|
this.addGroupRenderer(topRelem, renderer);
|
501
|
} else {
|
502
|
var renderElem = this.createElementNS("", renderer.type.toUpperCase() + "RENDERER");
|
503
|
topRelem.appendChild(renderElem);
|
504
|
|
505
|
if (renderElem.tagName == "VALUEMAPRENDERER") {
|
506
|
this.addValueMapRenderer(renderElem, renderer);
|
507
|
} else if (renderElem.tagName == "VALUEMAPLABELRENDERER") {
|
508
|
this.addValueMapLabelRenderer(renderElem, renderer);
|
509
|
} else if (renderElem.tagName == "SIMPLELABELRENDERER") {
|
510
|
this.addSimpleLabelRenderer(renderElem, renderer);
|
511
|
} else if (renderElem.tagName == "SCALEDEPENDENTRENDERER") {
|
512
|
this.addScaleDependentRenderer(renderElem, renderer);
|
513
|
}
|
514
|
}
|
515
|
},
|
516
|
|
517
|
|
518
|
addScaleDependentRenderer: function(renderElem, renderer) {
|
519
|
if (typeof renderer.lower == "string" || typeof renderer.lower == "number") {
|
520
|
renderElem.setAttribute("lower", renderer.lower);
|
521
|
}
|
522
|
if (typeof renderer.upper == "string" || typeof renderer.upper == "number") {
|
523
|
renderElem.setAttribute("upper", renderer.upper);
|
524
|
}
|
525
|
|
526
|
this.addRenderer(renderElem, renderer.renderer);
|
527
|
},
|
528
|
|
529
|
|
530
|
addValueMapLabelRenderer: function(renderElem, renderer) {
|
531
|
renderElem.setAttribute("lookupfield", renderer.lookupfield);
|
532
|
renderElem.setAttribute("labelfield", renderer.labelfield);
|
533
|
|
534
|
if (typeof renderer.exacts == "object") {
|
535
|
for (var ext=0, extlen=renderer.exacts.length; ext<extlen; ext++) {
|
536
|
var exact = renderer.exacts[ext];
|
537
|
|
538
|
var eelem = this.createElementNS("", "EXACT");
|
539
|
|
540
|
if (typeof exact.value == "string") {
|
541
|
eelem.setAttribute("value", exact.value);
|
542
|
}
|
543
|
if (typeof exact.label == "string") {
|
544
|
eelem.setAttribute("label", exact.label);
|
545
|
}
|
546
|
if (typeof exact.method == "string") {
|
547
|
eelem.setAttribute("method", exact.method);
|
548
|
}
|
549
|
|
550
|
renderElem.appendChild(eelem);
|
551
|
|
552
|
if (typeof exact.symbol == "object") {
|
553
|
var selem = null;
|
554
|
|
555
|
if (exact.symbol.type == "text") {
|
556
|
selem = this.createElementNS("", "TEXTSYMBOL");
|
557
|
}
|
558
|
|
559
|
if (selem != null) {
|
560
|
var keys = this.fontStyleKeys;
|
561
|
for (var i = 0, len = keys.length; i < len; i++) {
|
562
|
var key = keys[i];
|
563
|
if (exact.symbol[key]) {
|
564
|
selem.setAttribute(key, exact.symbol[key]);
|
565
|
}
|
566
|
}
|
567
|
eelem.appendChild(selem);
|
568
|
}
|
569
|
}
|
570
|
} // for each exact
|
571
|
}
|
572
|
},
|
573
|
|
574
|
addValueMapRenderer: function(renderElem, renderer) {
|
575
|
renderElem.setAttribute("lookupfield", renderer.lookupfield);
|
576
|
|
577
|
if (typeof renderer.ranges == "object") {
|
578
|
for(var rng=0, rnglen=renderer.ranges.length; rng<rnglen; rng++) {
|
579
|
var range = renderer.ranges[rng];
|
580
|
|
581
|
var relem = this.createElementNS("", "RANGE");
|
582
|
relem.setAttribute("lower", range.lower);
|
583
|
relem.setAttribute("upper", range.upper);
|
584
|
|
585
|
renderElem.appendChild(relem);
|
586
|
|
587
|
if (typeof range.symbol == "object") {
|
588
|
var selem = null;
|
589
|
|
590
|
if (range.symbol.type == "simplepolygon") {
|
591
|
selem = this.createElementNS("", "SIMPLEPOLYGONSYMBOL");
|
592
|
}
|
593
|
|
594
|
if (selem != null) {
|
595
|
if (typeof range.symbol.boundarycolor == "string") {
|
596
|
selem.setAttribute("boundarycolor", range.symbol.boundarycolor);
|
597
|
}
|
598
|
if (typeof range.symbol.fillcolor == "string") {
|
599
|
selem.setAttribute("fillcolor", range.symbol.fillcolor);
|
600
|
}
|
601
|
if (typeof range.symbol.filltransparency == "number") {
|
602
|
selem.setAttribute("filltransparency", range.symbol.filltransparency);
|
603
|
}
|
604
|
relem.appendChild(selem);
|
605
|
}
|
606
|
}
|
607
|
} // for each range
|
608
|
} else if (typeof renderer.exacts == "object") {
|
609
|
for (var ext=0, extlen=renderer.exacts.length; ext<extlen; ext++) {
|
610
|
var exact = renderer.exacts[ext];
|
611
|
|
612
|
var eelem = this.createElementNS("", "EXACT");
|
613
|
if (typeof exact.value == "string") {
|
614
|
eelem.setAttribute("value", exact.value);
|
615
|
}
|
616
|
if (typeof exact.label == "string") {
|
617
|
eelem.setAttribute("label", exact.label);
|
618
|
}
|
619
|
if (typeof exact.method == "string") {
|
620
|
eelem.setAttribute("method", exact.method);
|
621
|
}
|
622
|
|
623
|
renderElem.appendChild(eelem);
|
624
|
|
625
|
if (typeof exact.symbol == "object") {
|
626
|
var selem = null;
|
627
|
|
628
|
if (exact.symbol.type == "simplemarker") {
|
629
|
selem = this.createElementNS("", "SIMPLEMARKERSYMBOL");
|
630
|
}
|
631
|
|
632
|
if (selem != null) {
|
633
|
if (typeof exact.symbol.antialiasing == "string") {
|
634
|
selem.setAttribute("antialiasing", exact.symbol.antialiasing);
|
635
|
}
|
636
|
if (typeof exact.symbol.color == "string") {
|
637
|
selem.setAttribute("color", exact.symbol.color);
|
638
|
}
|
639
|
if (typeof exact.symbol.outline == "string") {
|
640
|
selem.setAttribute("outline", exact.symbol.outline);
|
641
|
}
|
642
|
if (typeof exact.symbol.overlap == "string") {
|
643
|
selem.setAttribute("overlap", exact.symbol.overlap);
|
644
|
}
|
645
|
if (typeof exact.symbol.shadow == "string") {
|
646
|
selem.setAttribute("shadow", exact.symbol.shadow);
|
647
|
}
|
648
|
if (typeof exact.symbol.transparency == "number") {
|
649
|
selem.setAttribute("transparency", exact.symbol.transparency);
|
650
|
}
|
651
|
//if (typeof exact.symbol.type == "string")
|
652
|
// selem.setAttribute("type", exact.symbol.type);
|
653
|
if (typeof exact.symbol.usecentroid == "string") {
|
654
|
selem.setAttribute("usecentroid", exact.symbol.usecentroid);
|
655
|
}
|
656
|
if (typeof exact.symbol.width == "number") {
|
657
|
selem.setAttribute("width", exact.symbol.width);
|
658
|
}
|
659
|
|
660
|
eelem.appendChild(selem);
|
661
|
}
|
662
|
}
|
663
|
} // for each exact
|
664
|
}
|
665
|
},
|
666
|
|
667
|
|
668
|
addSimpleLabelRenderer: function(renderElem, renderer) {
|
669
|
renderElem.setAttribute("field", renderer.field);
|
670
|
var keys = ['featureweight', 'howmanylabels', 'labelbufferratio',
|
671
|
'labelpriorities', 'labelweight', 'linelabelposition',
|
672
|
'rotationalangles'];
|
673
|
for (var i=0, len=keys.length; i<len; i++) {
|
674
|
var key = keys[i];
|
675
|
if (renderer[key]) {
|
676
|
renderElem.setAttribute(key, renderer[key]);
|
677
|
}
|
678
|
}
|
679
|
|
680
|
if (renderer.symbol.type == "text") {
|
681
|
var symbol = renderer.symbol;
|
682
|
var selem = this.createElementNS("", "TEXTSYMBOL");
|
683
|
renderElem.appendChild(selem);
|
684
|
|
685
|
var keys = this.fontStyleKeys;
|
686
|
for (var i=0, len=keys.length; i<len; i++) {
|
687
|
var key = keys[i];
|
688
|
if (symbol[key]) {
|
689
|
selem.setAttribute(key, renderer[key]);
|
690
|
}
|
691
|
}
|
692
|
}
|
693
|
},
|
694
|
|
695
|
writePolygonGeometry: function(polygon) {
|
696
|
if (!(polygon instanceof OpenLayers.Geometry.Polygon)) {
|
697
|
throw {
|
698
|
message:'Cannot write polygon geometry to ArcXML with an ' +
|
699
|
polygon.CLASS_NAME + ' object.',
|
700
|
geometry: polygon
|
701
|
};
|
702
|
}
|
703
|
|
704
|
var polyElem = this.createElementNS("", "POLYGON");
|
705
|
|
706
|
for (var ln=0, lnlen=polygon.components.length; ln<lnlen; ln++) {
|
707
|
var ring = polygon.components[ln];
|
708
|
var ringElem = this.createElementNS("", "RING");
|
709
|
|
710
|
for (var rn=0, rnlen=ring.components.length; rn<rnlen; rn++) {
|
711
|
var point = ring.components[rn];
|
712
|
var pointElem = this.createElementNS("", "POINT");
|
713
|
|
714
|
pointElem.setAttribute("x", point.x);
|
715
|
pointElem.setAttribute("y", point.y);
|
716
|
|
717
|
ringElem.appendChild(pointElem);
|
718
|
}
|
719
|
|
720
|
polyElem.appendChild(ringElem);
|
721
|
}
|
722
|
|
723
|
return polyElem;
|
724
|
},
|
725
|
|
726
|
/**
|
727
|
* Method: parseResponse
|
728
|
* Take an ArcXML response, and parse in into this object's internal properties.
|
729
|
*
|
730
|
* Parameters:
|
731
|
* data - {String} or {DOMElement} The ArcXML response, as either a string or the
|
732
|
* top level DOMElement of the response.
|
733
|
*/
|
734
|
parseResponse: function(data) {
|
735
|
if(typeof data == "string") {
|
736
|
var newData = new OpenLayers.Format.XML();
|
737
|
data = newData.read(data);
|
738
|
}
|
739
|
var response = new OpenLayers.Format.ArcXML.Response();
|
740
|
|
741
|
var errorNode = data.getElementsByTagName("ERROR");
|
742
|
|
743
|
if (errorNode != null && errorNode.length > 0) {
|
744
|
response.error = this.getChildValue(errorNode, "Unknown error.");
|
745
|
} else {
|
746
|
var responseNode = data.getElementsByTagName("RESPONSE");
|
747
|
|
748
|
if (responseNode == null || responseNode.length == 0) {
|
749
|
response.error = "No RESPONSE tag found in ArcXML response.";
|
750
|
return response;
|
751
|
}
|
752
|
|
753
|
var rtype = responseNode[0].firstChild.nodeName;
|
754
|
if (rtype == "#text") {
|
755
|
rtype = responseNode[0].firstChild.nextSibling.nodeName;
|
756
|
}
|
757
|
|
758
|
if (rtype == "IMAGE") {
|
759
|
var envelopeNode = data.getElementsByTagName("ENVELOPE");
|
760
|
var outputNode = data.getElementsByTagName("OUTPUT");
|
761
|
|
762
|
if (envelopeNode == null || envelopeNode.length == 0) {
|
763
|
response.error = "No ENVELOPE tag found in ArcXML response.";
|
764
|
} else if (outputNode == null || outputNode.length == 0) {
|
765
|
response.error = "No OUTPUT tag found in ArcXML response.";
|
766
|
} else {
|
767
|
var envAttr = this.parseAttributes(envelopeNode[0]);
|
768
|
var outputAttr = this.parseAttributes(outputNode[0]);
|
769
|
|
770
|
if (typeof outputAttr.type == "string") {
|
771
|
response.image = {
|
772
|
envelope: envAttr,
|
773
|
output: {
|
774
|
type: outputAttr.type,
|
775
|
data: this.getChildValue(outputNode[0])
|
776
|
}
|
777
|
};
|
778
|
} else {
|
779
|
response.image = { envelope: envAttr, output: outputAttr };
|
780
|
}
|
781
|
}
|
782
|
} else if (rtype == "FEATURES") {
|
783
|
var features = responseNode[0].getElementsByTagName("FEATURES");
|
784
|
|
785
|
// get the feature count
|
786
|
var featureCount = features[0].getElementsByTagName("FEATURECOUNT");
|
787
|
response.features.featurecount = featureCount[0].getAttribute("count");
|
788
|
|
789
|
if (response.features.featurecount > 0) {
|
790
|
// get the feature envelope
|
791
|
var envelope = features[0].getElementsByTagName("ENVELOPE");
|
792
|
response.features.envelope = this.parseAttributes(envelope[0], typeof(0));
|
793
|
|
794
|
// get the field values per feature
|
795
|
var featureList = features[0].getElementsByTagName("FEATURE");
|
796
|
for (var fn = 0; fn < featureList.length; fn++) {
|
797
|
var feature = new OpenLayers.Feature.Vector();
|
798
|
var fields = featureList[fn].getElementsByTagName("FIELD");
|
799
|
|
800
|
for (var fdn = 0; fdn < fields.length; fdn++) {
|
801
|
var fieldName = fields[fdn].getAttribute("name");
|
802
|
var fieldValue = fields[fdn].getAttribute("value");
|
803
|
feature.attributes[ fieldName ] = fieldValue;
|
804
|
}
|
805
|
|
806
|
var geom = featureList[fn].getElementsByTagName("POLYGON");
|
807
|
|
808
|
if (geom.length > 0) {
|
809
|
// if there is a polygon, create an openlayers polygon, and assign
|
810
|
// it to the .geometry property of the feature
|
811
|
var ring = geom[0].getElementsByTagName("RING");
|
812
|
|
813
|
var polys = [];
|
814
|
for (var rn = 0; rn < ring.length; rn++) {
|
815
|
var linearRings = [];
|
816
|
linearRings.push(this.parsePointGeometry(ring[rn]));
|
817
|
|
818
|
var holes = ring[rn].getElementsByTagName("HOLE");
|
819
|
for (var hn = 0; hn < holes.length; hn++) {
|
820
|
linearRings.push(this.parsePointGeometry(holes[hn]));
|
821
|
}
|
822
|
holes = null;
|
823
|
polys.push(new OpenLayers.Geometry.Polygon(linearRings));
|
824
|
linearRings = null;
|
825
|
}
|
826
|
ring = null;
|
827
|
|
828
|
if (polys.length == 1) {
|
829
|
feature.geometry = polys[0];
|
830
|
} else
|
831
|
{
|
832
|
feature.geometry = new OpenLayers.Geometry.MultiPolygon(polys);
|
833
|
}
|
834
|
}
|
835
|
|
836
|
response.features.feature.push(feature);
|
837
|
}
|
838
|
}
|
839
|
} else {
|
840
|
response.error = "Unidentified response type.";
|
841
|
}
|
842
|
}
|
843
|
return response;
|
844
|
},
|
845
|
|
846
|
|
847
|
/**
|
848
|
* Method: parseAttributes
|
849
|
*
|
850
|
* Parameters:
|
851
|
* node - {<DOMElement>} An element to parse attributes from.
|
852
|
*
|
853
|
* Returns:
|
854
|
* {Object} An attributes object, with properties set to attribute values.
|
855
|
*/
|
856
|
parseAttributes: function(node,type) {
|
857
|
var attributes = {};
|
858
|
for(var attr = 0; attr < node.attributes.length; attr++) {
|
859
|
if (type == "number") {
|
860
|
attributes[node.attributes[attr].nodeName] = parseFloat(node.attributes[attr].nodeValue);
|
861
|
} else {
|
862
|
attributes[node.attributes[attr].nodeName] = node.attributes[attr].nodeValue;
|
863
|
}
|
864
|
}
|
865
|
return attributes;
|
866
|
},
|
867
|
|
868
|
|
869
|
/**
|
870
|
* Method: parsePointGeometry
|
871
|
*
|
872
|
* Parameters:
|
873
|
* node - {<DOMElement>} An element to parse <COORDS> or <POINT> arcxml data from.
|
874
|
*
|
875
|
* Returns:
|
876
|
* {<OpenLayers.Geometry.LinearRing>} A linear ring represented by the node's points.
|
877
|
*/
|
878
|
parsePointGeometry: function(node) {
|
879
|
var ringPoints = [];
|
880
|
var coords = node.getElementsByTagName("COORDS");
|
881
|
|
882
|
if (coords.length > 0) {
|
883
|
// if coords is present, it's the only coords item
|
884
|
var coordArr = this.getChildValue(coords[0]);
|
885
|
coordArr = coordArr.split(/;/);
|
886
|
for (var cn = 0; cn < coordArr.length; cn++) {
|
887
|
var coordItems = coordArr[cn].split(/ /);
|
888
|
ringPoints.push(new OpenLayers.Geometry.Point(coordItems[0], coordItems[1]));
|
889
|
}
|
890
|
coords = null;
|
891
|
} else {
|
892
|
var point = node.getElementsByTagName("POINT");
|
893
|
if (point.length > 0) {
|
894
|
for (var pn = 0; pn < point.length; pn++) {
|
895
|
ringPoints.push(
|
896
|
new OpenLayers.Geometry.Point(
|
897
|
parseFloat(point[pn].getAttribute("x")),
|
898
|
parseFloat(point[pn].getAttribute("y"))
|
899
|
)
|
900
|
);
|
901
|
}
|
902
|
}
|
903
|
point = null;
|
904
|
}
|
905
|
|
906
|
return new OpenLayers.Geometry.LinearRing(ringPoints);
|
907
|
},
|
908
|
|
909
|
CLASS_NAME: "OpenLayers.Format.ArcXML"
|
910
|
});
|
911
|
|
912
|
OpenLayers.Format.ArcXML.Request = OpenLayers.Class({
|
913
|
initialize: function(params) {
|
914
|
var defaults = {
|
915
|
get_image: {
|
916
|
properties: {
|
917
|
background: null,
|
918
|
/*{
|
919
|
color: { r:255, g:255, b:255 },
|
920
|
transcolor: null
|
921
|
},*/
|
922
|
draw: true,
|
923
|
envelope: {
|
924
|
minx: 0,
|
925
|
miny: 0,
|
926
|
maxx: 0,
|
927
|
maxy: 0
|
928
|
},
|
929
|
featurecoordsys: {
|
930
|
id:0,
|
931
|
string:"",
|
932
|
datumtransformid:0,
|
933
|
datumtransformstring:""
|
934
|
},
|
935
|
filtercoordsys:{
|
936
|
id:0,
|
937
|
string:"",
|
938
|
datumtransformid:0,
|
939
|
datumtransformstring:""
|
940
|
},
|
941
|
imagesize:{
|
942
|
height:0,
|
943
|
width:0,
|
944
|
dpi:96,
|
945
|
printheight:0,
|
946
|
printwidth:0,
|
947
|
scalesymbols:false
|
948
|
},
|
949
|
layerlist:[],
|
950
|
/* no support for legends */
|
951
|
output:{
|
952
|
baseurl:"",
|
953
|
legendbaseurl:"",
|
954
|
legendname:"",
|
955
|
legendpath:"",
|
956
|
legendurl:"",
|
957
|
name:"",
|
958
|
path:"",
|
959
|
type:"jpg",
|
960
|
url:""
|
961
|
}
|
962
|
}
|
963
|
},
|
964
|
|
965
|
get_feature: {
|
966
|
layer: "",
|
967
|
query: {
|
968
|
isspatial: false,
|
969
|
featurecoordsys: {
|
970
|
id:0,
|
971
|
string:"",
|
972
|
datumtransformid:0,
|
973
|
datumtransformstring:""
|
974
|
},
|
975
|
filtercoordsys: {
|
976
|
id:0,
|
977
|
string:"",
|
978
|
datumtransformid:0,
|
979
|
datumtransformstring:""
|
980
|
},
|
981
|
buffer:0,
|
982
|
where:"",
|
983
|
spatialfilter: {
|
984
|
relation: "envelope_intersection",
|
985
|
envelope: null
|
986
|
}
|
987
|
}
|
988
|
},
|
989
|
|
990
|
environment: {
|
991
|
separators: {
|
992
|
cs:" ",
|
993
|
ts:";"
|
994
|
}
|
995
|
},
|
996
|
|
997
|
layer: [],
|
998
|
workspaces: []
|
999
|
};
|
1000
|
|
1001
|
return OpenLayers.Util.extend(this, defaults);
|
1002
|
},
|
1003
|
|
1004
|
CLASS_NAME: "OpenLayers.Format.ArcXML.Request"
|
1005
|
});
|
1006
|
|
1007
|
OpenLayers.Format.ArcXML.Response = OpenLayers.Class({
|
1008
|
initialize: function(params) {
|
1009
|
var defaults = {
|
1010
|
image: {
|
1011
|
envelope:null,
|
1012
|
output:''
|
1013
|
},
|
1014
|
|
1015
|
features: {
|
1016
|
featurecount: 0,
|
1017
|
envelope: null,
|
1018
|
feature: []
|
1019
|
},
|
1020
|
|
1021
|
error:''
|
1022
|
};
|
1023
|
|
1024
|
return OpenLayers.Util.extend(this, defaults);
|
1025
|
},
|
1026
|
|
1027
|
CLASS_NAME: "OpenLayers.Format.ArcXML.Response"
|
1028
|
});
|