1
|
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
|
2
|
<html>
|
3
|
<head>
|
4
|
<title>
|
5
|
<a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008 Overview
|
6
|
</title>
|
7
|
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
|
8
|
<script>
|
9
|
function asd() {
|
10
|
|
11
|
parent.document.title="WebServiceRequest.js Overview";
|
12
|
|
13
|
}
|
14
|
</script>
|
15
|
</head>
|
16
|
<body bgcolor="white" onload="asd();">
|
17
|
|
18
|
<!-- ========== START OF NAVBAR ========== -->
|
19
|
<a name="navbar_top"><!-- --></a>
|
20
|
<table border="0" width="100%" cellpadding="1" cellspacing="0">
|
21
|
<tr>
|
22
|
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
|
23
|
<a name="navbar_top_firstrow"><!-- --></a>
|
24
|
<table border="0" cellpadding="0" cellspacing="3">
|
25
|
<tr align="center" valign="top">
|
26
|
|
27
|
|
28
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td>
|
29
|
<td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td>
|
30
|
|
31
|
|
32
|
<td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td>
|
33
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td>
|
34
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td>
|
35
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td>
|
36
|
</tr>
|
37
|
</table>
|
38
|
</td>
|
39
|
<td bgcolor="#EEEEFF" align="right" valign="top">
|
40
|
<em>
|
41
|
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
|
42
|
</td>
|
43
|
</tr>
|
44
|
|
45
|
<tr>
|
46
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
47
|
PREV
|
48
|
NEXT</font></td>
|
49
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
50
|
<a href="index.html" target="_top"><b>FRAMES</b></a>
|
51
|
<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
|
52
|
|
53
|
<script>
|
54
|
<!--
|
55
|
if(window==top) {
|
56
|
document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
|
57
|
}
|
58
|
//-->
|
59
|
</script>
|
60
|
<noscript>
|
61
|
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
|
62
|
</noscript>
|
63
|
</font></td>
|
64
|
</tr>
|
65
|
</table>
|
66
|
<!-- =========== END OF NAVBAR =========== -->
|
67
|
|
68
|
<hr>
|
69
|
<center>
|
70
|
|
71
|
<h2>WebServiceRequest.js</h2>
|
72
|
|
73
|
</center>
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
<h4>Summary</h4>
|
79
|
<p>
|
80
|
|
81
|
No overview generated for 'WebServiceRequest.js'<BR/><BR/>
|
82
|
|
83
|
</p>
|
84
|
|
85
|
<hr>
|
86
|
|
87
|
|
88
|
<table border="1" cellpadding="3" cellspacing="0" width="100%">
|
89
|
<tr bgcolor="#CCCCFF" class="TableHeadingColor">
|
90
|
<td colspan=2><font size="+2">
|
91
|
|
92
|
<b>Class Summary</b>
|
93
|
|
94
|
</font></td>
|
95
|
</tr>
|
96
|
|
97
|
<tr bgcolor="white" class="TableRowColor">
|
98
|
<td width="15%"><b><a href="WebServiceRequest.html">WebServiceRequest</a></b></td>
|
99
|
<td> </td>
|
100
|
</tr>
|
101
|
|
102
|
</table>
|
103
|
<hr/>
|
104
|
|
105
|
|
106
|
<!-- ========== METHOD SUMMARY =========== -->
|
107
|
|
108
|
<!-- ========== END METHOD SUMMARY =========== -->
|
109
|
|
110
|
|
111
|
<pre class="sourceview"><span class="comment">/*
|
112
|
Author: Mike Adair mike.adairATccrs.nrcan.gc.ca
|
113
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
114
|
|
115
|
$Id: WebServiceRequest.js 3881 2008-02-27 15:41:07Z gjvoosten $
|
116
|
*/</span>
|
117
|
<span class="comment">
|
118
|
// Ensure this object's dependancies are loaded.</span>
|
119
|
mapbuilder.loadScript(baseDir+<span class="literal">"/tool/ToolBase.js"</span>);
|
120
|
|
121
|
<span class="comment">/**
|
122
|
* A controller issuing OGC web service requests. The request is generated
|
123
|
* by applying a stylesheet to a Layer/FeatureType/Coverage node from a
|
124
|
* capabilities document as a listener function. The listener event name is
|
125
|
* a combination of the service type and the request name (e.g. wfs_GetFeature)
|
126
|
* and the parameter passed to the listener is the featureName (Layer/FeatureType/Coverage).
|
127
|
* The response from the request is stored in the targetModel. If the
|
128
|
* targetModel is a template model (attribute template="true") the a new model
|
129
|
* is created and appended to the parentModel's <models> list.
|
130
|
* <span class="attrib">@constructor</span>
|
131
|
* <span class="attrib">@base</span> ToolBase
|
132
|
* <span class="attrib">@param</span> toolNode The tools's XML object node from the configuration document.
|
133
|
* <span class="attrib">@param</span> model The model that this tool belongs to
|
134
|
*/</span>
|
135
|
<span class="reserved">function</span> WebServiceRequest(toolNode, model) {
|
136
|
ToolBase.apply(<span class="reserved">this</span>, new Array(toolNode, model));
|
137
|
<span class="comment">
|
138
|
//this.debug=true;</span>
|
139
|
<span class="comment">
|
140
|
//get the request name to add listener to</span>
|
141
|
<span class="reserved">this</span>.requestName = <span class="reserved">this</span>.getProperty(<span class="literal">"mb:requestName"</span>);
|
142
|
<span class="comment">
|
143
|
//get the request filter to add to the request</span>
|
144
|
<span class="reserved">this</span>.requestFilter = <span class="reserved">this</span>.getProperty(<span class="literal">"mb:requestFilter"</span>);
|
145
|
|
146
|
var styleUrl = toolNode.selectSingleNode(<span class="literal">"mb:stylesheet"</span>);
|
147
|
styleUrl = styleUrl ? getNodeValue(styleUrl) :
|
148
|
baseDir+<span class="literal">"/tool/xsl/"</span>+<span class="reserved">this</span>.requestName.replace(/:/,<span class="literal">"_"</span>)+<span class="literal">".xsl"</span>;
|
149
|
<span class="reserved">this</span>.requestStylesheet = new XslProcessor(styleUrl);
|
150
|
<span class="comment">
|
151
|
// Set stylesheet parameters for all the child nodes from the config file</span>
|
152
|
<span class="reserved">for</span> (var j=0;j<toolNode.childNodes.length;j++) {
|
153
|
<span class="reserved">if</span> (getNodeValue(toolNode.childNodes[j])) {
|
154
|
<span class="reserved">this</span>.requestStylesheet.setParameter(toolNode.childNodes[j].nodeName,getNodeValue(toolNode.childNodes[j]));
|
155
|
}
|
156
|
}
|
157
|
|
158
|
<span class="reserved">this</span>.model.addListener(<span class="literal">"init"</span>, <span class="reserved">this</span>.init, <span class="reserved">this</span>);
|
159
|
<span class="reserved">this</span>.model.addListener(<span class="reserved">this</span>.requestName.replace(/:/,<span class="literal">"_"</span>), <span class="reserved">this</span>.doRequest, <span class="reserved">this</span>);
|
160
|
}
|
161
|
|
162
|
<span class="comment">/**
|
163
|
* Function which create the HTTP payload for a request
|
164
|
* <span class="attrib">@param</span> feature the feature object
|
165
|
*/</span>
|
166
|
WebServiceRequest.<span class="reserved">prototype</span>.createHttpPayload = <span class="reserved">function</span>(feature) {
|
167
|
<span class="comment"> //confirm inputs</span>
|
168
|
<span class="reserved">if</span> (<span class="reserved">this</span>.debug) mbDebugMessage(<span class="reserved">this</span>, <span class="literal">"source:"</span>+(new XMLSerializer()).serializeToString(feature));
|
169
|
<span class="comment"> //if (this.debug) mbDebugMessage(this, "stylesheet:"+(new XMLSerializer()).serializeToString(this.requestStylesheet.xslDom));</span>
|
170
|
<span class="comment">
|
171
|
|
172
|
//prepare the stylesheet</span>
|
173
|
var httpPayload = new Object();
|
174
|
httpPayload.method = <span class="reserved">this</span>.targetModel.method;
|
175
|
<span class="reserved">this</span>.requestStylesheet.setParameter(<span class="literal">"httpMethod"</span>, httpPayload.method );
|
176
|
<span class="reserved">this</span>.requestStylesheet.setParameter(<span class="literal">"version"</span>, <span class="reserved">this</span>.model.getVersion(feature) );
|
177
|
<span class="reserved">if</span> (<span class="reserved">this</span>.requestFilter) {
|
178
|
var filter = config.objects[<span class="reserved">this</span>.requestFilter];
|
179
|
<span class="reserved">this</span>.requestStylesheet.setParameter(<span class="literal">"filter"</span>, escape((new XMLSerializer()).serializeToString(filter.doc).replace(/[\n\f\r\t]/g,<span class="literal">''</span>) ));
|
180
|
<span class="reserved">if</span> (<span class="reserved">this</span>.debug) mbDebugMessage(<span class="reserved">this</span>, (new XMLSerializer()).serializeToString(filter.doc));
|
181
|
}
|
182
|
<span class="comment">
|
183
|
//process the doc with the stylesheet</span>
|
184
|
httpPayload.postData = <span class="reserved">this</span>.requestStylesheet.transformNodeToObject(feature);
|
185
|
<span class="reserved">if</span> (<span class="reserved">this</span>.debug) {
|
186
|
mbDebugMessage(<span class="reserved">this</span>, <span class="literal">"request data:"</span>+(new XMLSerializer()).serializeToString(httpPayload.postData));
|
187
|
<span class="reserved">if</span> (config.serializeUrl) var response = postLoad(config.serializeUrl, httpPayload.postData);
|
188
|
}
|
189
|
|
190
|
httpPayload.url = <span class="reserved">this</span>.model.getServerUrl(<span class="reserved">this</span>.requestName, httpPayload.method, feature);
|
191
|
<span class="comment">
|
192
|
//extract the URL from the transformation result for GET method</span>
|
193
|
<span class="reserved">if</span> (httpPayload.method.toLowerCase() == <span class="literal">"get"</span>) {
|
194
|
httpPayload.postData.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);
|
195
|
Sarissa.setXpathNamespaces(httpPayload.postData, <span class="literal">"xmlns:mb='http://mapbuilder.sourceforge.net/mapbuilder'"</span>);
|
196
|
var queryString = httpPayload.postData.selectSingleNode(<span class="literal">"//mb:QueryString"</span>);
|
197
|
<span class="reserved">if</span> (httpPayload.url.indexOf(<span class="literal">"?"</span>) < 0) {
|
198
|
httpPayload.url += <span class="literal">"?"</span>;
|
199
|
} <span class="reserved">else</span> {
|
200
|
httpPayload.url += <span class="literal">"&"</span>;
|
201
|
}
|
202
|
httpPayload.url += getNodeValue(queryString);
|
203
|
httpPayload.postData = null;
|
204
|
}
|
205
|
mbDebugMessage(<span class="reserved">this</span>, <span class="literal">"URL:"</span>+httpPayload.url);
|
206
|
<span class="reserved">return</span> httpPayload;
|
207
|
}
|
208
|
|
209
|
|
210
|
<span class="comment">/**
|
211
|
* Listener function which will actually issue the request. This method
|
212
|
* will prepare the HTTP payload for a particular featureName.
|
213
|
* <span class="attrib">@param</span> requestName the name of the web service operation to execute
|
214
|
* <span class="attrib">@param</span> featureNodeId the id of the node in the doc to be processed by the stylesheet
|
215
|
*/</span>
|
216
|
WebServiceRequest.<span class="reserved">prototype</span>.doRequest = <span class="reserved">function</span>(objRef, featureName) {
|
217
|
objRef.targetModel.featureName = featureName;
|
218
|
|
219
|
var feature = objRef.model.getFeatureNode(featureName);
|
220
|
<span class="reserved">if</span> (!feature) {
|
221
|
alert(mbGetMessage(<span class="literal">"featureNotFoundWebServiceRequest"</span>, featureName));
|
222
|
<span class="reserved">return</span>;
|
223
|
}
|
224
|
<span class="reserved">if</span> (objRef.model.setRequestParameters) objRef.model.setRequestParameters(featureName, objRef.requestStylesheet);
|
225
|
var httpPayload = objRef.createHttpPayload(feature);
|
226
|
objRef.targetModel.newRequest(objRef.targetModel,httpPayload);
|
227
|
}
|
228
|
|
229
|
WebServiceRequest.<span class="reserved">prototype</span>.setAoiParameters = <span class="reserved">function</span>(objRef) {
|
230
|
<span class="comment"> //TBD: this depends on the targetModel having a containerModel to extract the AOI from.</span>
|
231
|
<span class="comment"> //we probably need a config property to point to the AOI model to handle this properly.</span>
|
232
|
<span class="reserved">if</span> (objRef.containerModel) {
|
233
|
var featureSRS = null;
|
234
|
var containerSRS = <span class="literal">"EPSG:4326"</span>;
|
235
|
var bbox = objRef.containerModel.getBoundingBox();
|
236
|
<span class="comment">/*
|
237
|
TBD: figure out when to use AOI or BBOX
|
238
|
var aoi = objRef.containerModel.getParam("aoi");
|
239
|
if (aoi) {
|
240
|
bbox[0] = aoi[0][0];
|
241
|
bbox[1] = aoi[1][1];
|
242
|
bbox[2] = aoi[1][0];
|
243
|
bbox[3] = aoi[0][1];
|
244
|
}
|
245
|
*/</span>
|
246
|
var containerSRS = objRef.containerModel.getSRS();
|
247
|
<span class="comment">/*
|
248
|
//convert the BBOX to the feature SRS for the request
|
249
|
if (featureSRS) {
|
250
|
var sourceProj = new Proj4js.Proj(getNodeValue(featureSRS));
|
251
|
if ( !sourceProj.matchSrs( containerSRS )) {
|
252
|
var containerProj = new Proj4js.Proj(objRef.containerModel.getSRS());
|
253
|
var llTemp = containerProj.Inverse(new Array(bbox[0],bbox[1]));
|
254
|
var xy = sourceProj.Forward(llTemp);
|
255
|
bbox[0] = xy[0]; bbox[1] = xy[1];
|
256
|
llTemp = containerProj.Inverse(new Array(bbox[2],bbox[3]));
|
257
|
xy = sourceProj.Forward(llTemp);
|
258
|
bbox[2] = xy[0]; bbox[3] = xy[1];
|
259
|
}
|
260
|
}
|
261
|
*/</span>
|
262
|
objRef.requestStylesheet.setParameter(<span class="literal">"bBoxMinX"</span>, bbox[0]);
|
263
|
objRef.requestStylesheet.setParameter(<span class="literal">"bBoxMinY"</span>, bbox[1]);
|
264
|
objRef.requestStylesheet.setParameter(<span class="literal">"bBoxMaxX"</span>, bbox[2]);
|
265
|
objRef.requestStylesheet.setParameter(<span class="literal">"bBoxMaxY"</span>, bbox[3]);
|
266
|
objRef.requestStylesheet.setParameter(<span class="literal">"srs"</span>, containerSRS );
|
267
|
objRef.requestStylesheet.setParameter(<span class="literal">"width"</span>, objRef.containerModel.getWindowWidth() );
|
268
|
objRef.requestStylesheet.setParameter(<span class="literal">"height"</span>, objRef.containerModel.getWindowHeight() );
|
269
|
}
|
270
|
}
|
271
|
|
272
|
WebServiceRequest.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(objRef) {
|
273
|
<span class="reserved">if</span> (objRef.targetModel.containerModel) {
|
274
|
objRef.containerModel = objRef.targetModel.containerModel;
|
275
|
} <span class="reserved">else</span> <span class="reserved">if</span> (objRef.model.containerModel) {
|
276
|
objRef.containerModel = objRef.model.containerModel;
|
277
|
}
|
278
|
<span class="reserved">if</span> (objRef.containerModel) {
|
279
|
objRef.containerModel.addListener(<span class="literal">"aoi"</span>, objRef.setAoiParameters, objRef);
|
280
|
objRef.containerModel.addListener(<span class="literal">"bbox"</span>, objRef.setAoiParameters, objRef);
|
281
|
objRef.containerModel.addListener(<span class="literal">"selectedLayer"</span>, objRef.selectFeature, objRef);
|
282
|
objRef.containerModel.addListener(<span class="literal">"loadModel"</span>, objRef.mapInit, objRef);
|
283
|
objRef.containerModel.addListener(<span class="literal">"newModel"</span>, objRef.clear, objRef);
|
284
|
}
|
285
|
}
|
286
|
|
287
|
<span class="comment">/**
|
288
|
* set map events needed for this tool
|
289
|
* <span class="attrib">@param</span> objRef reference to this tool
|
290
|
*/</span>
|
291
|
WebServiceRequest.<span class="reserved">prototype</span>.mapInit = <span class="reserved">function</span>(objRef) {
|
292
|
<span class="comment"> // register OpenLayers event to do updates onmouseup</span>
|
293
|
objRef.containerModel.map.events.registerPriority(<span class="literal">'mouseup'</span>, objRef, objRef.setClickPosition);
|
294
|
}
|
295
|
|
296
|
<span class="comment">/**
|
297
|
* remove map events for this tool
|
298
|
* <span class="attrib">@param</span> objRef reference to this tool
|
299
|
*/</span>
|
300
|
WebServiceRequest.<span class="reserved">prototype</span>.clear = <span class="reserved">function</span>(objRef) {
|
301
|
<span class="reserved">if</span> (objRef.containerModel.map && objRef.containerModel.map.events) {
|
302
|
objRef.containerModel.map.events.unregister(<span class="literal">'mouseup'</span>, objRef, objRef.setClickPosition);
|
303
|
}
|
304
|
}
|
305
|
|
306
|
<span class="comment">/**
|
307
|
* Listener function that will clear the templates and set the mouse
|
308
|
* positions when the user clicks on the map.
|
309
|
* <span class="attrib">@param</span> e OpenLayers event
|
310
|
*/</span>
|
311
|
WebServiceRequest.<span class="reserved">prototype</span>.setClickPosition = <span class="reserved">function</span>(e) {
|
312
|
<span class="reserved">this</span>.targetModel.deleteTemplates();
|
313
|
<span class="reserved">this</span>.requestStylesheet.setParameter(<span class="literal">"xCoord"</span>, e.xy.x);
|
314
|
<span class="reserved">this</span>.requestStylesheet.setParameter(<span class="literal">"yCoord"</span>, e.xy.y);
|
315
|
}
|
316
|
|
317
|
<span class="comment">/**
|
318
|
* Listener function which will actually issue the request. This method
|
319
|
* will prepare the HTTP payload for a particular featureName.
|
320
|
* <span class="attrib">@param</span> requestName the name of the web service operation to execute
|
321
|
* <span class="attrib">@param</span> featureNodeId the id of the node in the doc to be processed by the stylesheet
|
322
|
*/</span>
|
323
|
WebServiceRequest.<span class="reserved">prototype</span>.selectFeature = <span class="reserved">function</span>(objRef, featureName) {
|
324
|
objRef.requestStylesheet.setParameter(<span class="literal">"queryLayer"</span>, featureName);
|
325
|
}
|
326
|
|
327
|
</pre>
|
328
|
<hr>
|
329
|
|
330
|
|
331
|
|
332
|
<!-- ========== START OF NAVBAR ========== -->
|
333
|
<a name="navbar_top"><!-- --></a>
|
334
|
<table border="0" width="100%" cellpadding="1" cellspacing="0">
|
335
|
<tr>
|
336
|
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
|
337
|
<a name="navbar_top_firstrow"><!-- --></a>
|
338
|
<table border="0" cellpadding="0" cellspacing="3">
|
339
|
<tr align="center" valign="top">
|
340
|
|
341
|
|
342
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td>
|
343
|
<td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td>
|
344
|
|
345
|
|
346
|
<td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td>
|
347
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td>
|
348
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td>
|
349
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td>
|
350
|
</tr>
|
351
|
</table>
|
352
|
</td>
|
353
|
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
|
354
|
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
|
355
|
</td>
|
356
|
</tr>
|
357
|
|
358
|
<tr>
|
359
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
360
|
PREV
|
361
|
NEXT</font></td>
|
362
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
363
|
<a href="index.html" target="_top"><b>FRAMES</b></a>
|
364
|
<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
|
365
|
|
366
|
<script>
|
367
|
<!--
|
368
|
if(window==top) {
|
369
|
document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
|
370
|
}
|
371
|
//-->
|
372
|
</script>
|
373
|
<noscript>
|
374
|
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
|
375
|
</noscript>
|
376
|
</font></td>
|
377
|
</tr>
|
378
|
</table>
|
379
|
<!-- =========== END OF NAVBAR =========== -->
|
380
|
|
381
|
<hr>
|
382
|
<font size="-1">
|
383
|
|
384
|
</font>
|
385
|
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sun Apr 27 20:30:54 2008</div>
|
386
|
</body>
|
387
|
</html>
|