source: branches/PublicaMundi_David-devel/workshop/2013/_build/html/js_services_chaining.html @ 686

Last change on this file since 686 was 686, checked in by nbozon, 9 years ago

added workshop directory at root

File size: 64.2 KB
Line 
1
2
3<!DOCTYPE html>
4<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
5<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
6<head>
7  <meta charset="utf-8">
8  <meta name="viewport" content="width=device-width, initial-scale=1.0">
9 
10  <title>Playing with buildign blocks - Creating JavaScript Web Services &mdash; ZOO-Project 1.5 documentation</title>
11 
12  <link href="http://fonts.googleapis.com/css?family=Days+One" rel="stylesheet" type="text/css">
13 
14 
15
16 
17
18 
19 
20   
21      <link rel="search" type="application/opensearchdescription+xml" title="Search within ZOO-Project 1.5 documentation" href="_static/opensearch.xml"/>
22   
23
24 
25
26 
27 
28    <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
29 
30
31 
32
33 
34    <link rel="top" title="ZOO-Project 1.5 documentation" href="index.html"/>
35        <link rel="prev" title="Building blocks presentation - Using OGR and PgRouting based Web Services" href="building_blocks_presentation.html"/> 
36
37 
38  <script src="_static/js/modernizr.min.js"></script>
39
40</head>
41
42<body class="wy-body-for-nav" role="document">
43
44  <div class="wy-grid-for-nav">
45
46   
47    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
48      <div class="wy-side-nav-search">
49       
50
51       
52          <a class="shrink" href="http://zoo-project.org"><img src="http://zoo-project.org/img/zoo-sun-logo.png" class="img-responsive sun" style="display: inline;"> ZOO</a>
53       
54
55       
56        </a>
57
58       
59<div role="search">
60  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
61    <input type="text" name="q" placeholder="Search docs" />
62    <input type="hidden" name="check_keywords" value="yes" />
63    <input type="hidden" name="area" value="default" />
64  </form>
65</div>
66
67       
68      </div>
69
70      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
71       
72         
73         
74              <ul class="current">
75<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a><ul>
76<li class="toctree-l2"><a class="reference internal" href="introduction.html#what-is-zoo">What is ZOO ?</a></li>
77<li class="toctree-l2"><a class="reference internal" href="introduction.html#how-does-zoo-works">How does ZOO works ?</a></li>
78<li class="toctree-l2"><a class="reference internal" href="introduction.html#what-are-we-going-to-do-in-this-workshop">What are we going to do in this workshop?</a></li>
79<li class="toctree-l2"><a class="reference internal" href="introduction.html#usefull-tips-for-reading">Usefull tips for reading</a></li>
80</ul>
81</li>
82<li class="toctree-l1"><a class="reference internal" href="using_zoo_from_osgeolivevm.html">Configuration and ZOO-Kernel use</a><ul>
83<li class="toctree-l2"><a class="reference internal" href="using_zoo_from_osgeolivevm.html#zoo-project-installation">ZOO-Project Installation</a></li>
84<li class="toctree-l2"><a class="reference internal" href="using_zoo_from_osgeolivevm.html#zoo-kernel-configuration">ZOO-Kernel Configuration</a></li>
85<li class="toctree-l2"><a class="reference internal" href="using_zoo_from_osgeolivevm.html#testing-the-zoo-installation-with-getcapabilities">Testing the ZOO installation with GetCapabilities</a></li>
86</ul>
87</li>
88<li class="toctree-l1"><a class="reference internal" href="first_service.html">Creating your first ZOO Service</a><ul>
89<li class="toctree-l2"><a class="reference internal" href="first_service.html#introduction">Introduction</a></li>
90<li class="toctree-l2"><a class="reference internal" href="first_service.html#service-and-publication-process-overview">Service and publication process overview</a></li>
91<li class="toctree-l2"><a class="reference internal" href="first_service.html#creating-your-first-zcfg-file">Creating your first ZCFG file</a></li>
92<li class="toctree-l2"><a class="reference internal" href="first_service.html#test-requests">Test requests</a></li>
93<li class="toctree-l2"><a class="reference internal" href="first_service.html#implementing-the-python-service">Implementing the Python Service</a></li>
94<li class="toctree-l2"><a class="reference internal" href="first_service.html#interracting-with-your-service-using-execute-requests">Interracting with your service using Execute requests</a></li>
95<li class="toctree-l2"><a class="reference internal" href="first_service.html#conclusion">Conclusion</a></li>
96</ul>
97</li>
98<li class="toctree-l1"><a class="reference internal" href="building_blocks_presentation.html">Building blocks presentation - Using OGR and PgRouting based Web Services</a><ul>
99<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#introduction">Introduction</a></li>
100<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#services-provider-and-configuration-files">Services Provider and configuration files</a></li>
101<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#the-buffer-service">The Buffer Service</a></li>
102<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#the-intersection-service">The Intersection Service</a></li>
103<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#the-differencepy-service">The DifferencePy Service</a></li>
104<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#the-routing-and-profile-services">The Routing and Profile Services</a></li>
105<li class="toctree-l2"><a class="reference internal" href="building_blocks_presentation.html#conclusion">Conclusion</a></li>
106</ul>
107</li>
108<li class="toctree-l1 current"><a class="current reference internal" href="">Playing with buildign blocks - Creating JavaScript Web Services</a><ul>
109<li class="toctree-l2"><a class="reference internal" href="#introduction">Introduction</a></li>
110<li class="toctree-l2"><a class="reference internal" href="#zoo-api-overview">ZOO-API Overview</a></li>
111<li class="toctree-l2"><a class="reference internal" href="#the-mask-service">The Mask Service</a></li>
112<li class="toctree-l2"><a class="reference internal" href="#buffermask-service">BufferMask Service</a></li>
113<li class="toctree-l2"><a class="reference internal" href="#bufferrequest-service">BufferRequest service</a></li>
114<li class="toctree-l2"><a class="reference internal" href="#add-union-into-the-chain">Add Union into the chain</a></li>
115<li class="toctree-l2"><a class="reference internal" href="#conclusion">Conclusion</a></li>
116</ul>
117</li>
118</ul>
119
120         
121       
122      </div>
123      &nbsp;
124    </nav>
125
126    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
127
128     
129      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
130        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
131        <a href="index.html">ZOO-Project</a>
132      </nav>
133
134
135     
136      <div class="wy-nav-content">
137        <div class="rst-content">
138          <div role="navigation" aria-label="breadcrumbs navigation">
139  <ul class="wy-breadcrumbs">
140
141    <li><a href="index.html"> Docs</a> &#8725; &#160;</li>
142     
143    <li>Playing with buildign blocks - Creating JavaScript Web Services</li>
144      <li class="wy-breadcrumbs-aside">
145       
146          <a href="_sources/js_services_chaining.txt" rel="nofollow"> View page source</a>
147       
148      </li>
149  </ul>
150  <hr/>
151</div>
152          <div role="main" class="document">
153           
154  <div class="section" id="playing-with-buildign-blocks-creating-javascript-web-services">
155<span id="ogr-base-vect-ops"></span><h1><a class="toc-backref" href="#table-of-contents">Playing with buildign blocks - Creating JavaScript Web Services</a><a class="headerlink" href="#playing-with-buildign-blocks-creating-javascript-web-services" title="Permalink to this headline"></a></h1>
156<div class="contents topic" id="table-of-contents">
157<p class="topic-title first">Table of Contents</p>
158<ul class="simple">
159<li><a class="reference internal" href="#playing-with-buildign-blocks-creating-javascript-web-services" id="id12">Playing with buildign blocks - Creating JavaScript Web Services</a><ul>
160<li><a class="reference internal" href="#introduction" id="id13">Introduction</a></li>
161<li><a class="reference internal" href="#zoo-api-overview" id="id14">ZOO-API Overview</a></li>
162<li><a class="reference internal" href="#the-mask-service" id="id15">The Mask Service</a><ul>
163<li><a class="reference internal" href="#the-zcfg" id="id16">The ZCFG</a></li>
164<li><a class="reference internal" href="#the-javascript-service" id="id17">The JavaScript service</a></li>
165<li><a class="reference internal" href="#publish-and-use-your-service" id="id18">Publish and use your Service</a></li>
166</ul>
167</li>
168<li><a class="reference internal" href="#buffermask-service" id="id19">BufferMask Service</a><ul>
169<li><a class="reference internal" href="#id6" id="id20">The ZCFG</a></li>
170<li><a class="reference internal" href="#id7" id="id21">The JavaScript service</a></li>
171<li><a class="reference internal" href="#id8" id="id22">Publish and use your Service</a></li>
172</ul>
173</li>
174<li><a class="reference internal" href="#bufferrequest-service" id="id23">BufferRequest service</a><ul>
175<li><a class="reference internal" href="#id10" id="id24">The ZCFG</a></li>
176<li><a class="reference internal" href="#the-javascript-code" id="id25">The JavaScript code</a></li>
177<li><a class="reference internal" href="#id11" id="id26">Publish and use your Service</a></li>
178</ul>
179</li>
180<li><a class="reference internal" href="#add-union-into-the-chain" id="id27">Add Union into the chain</a></li>
181<li><a class="reference internal" href="#conclusion" id="id28">Conclusion</a></li>
182</ul>
183</li>
184</ul>
185</div>
186<div class="section" id="introduction">
187<h2><a class="toc-backref" href="#table-of-contents">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
188<p>This section illustrate how you can use JavaScript on the server-side to chain
189services together to build new ones. You will create a ZOO Services Provider
190using the services you seen before and the WFS server using the ZOO-API. The
191final goal is to query all POIs included in a buffer around a feature and
192to highlight them using a mask around this buffer. The following screenshot show
193you the expected result:</p>
194<a class="reference internal image-reference" href="_images/BufferMaskAndRequest_Level_15.png"><img alt="_images/BufferMaskAndRequest_Level_15.png" class="align-center" src="_images/BufferMaskAndRequest_Level_15.png" style="width: 650px;" /></a>
195<p>For the routing interface result should look like this:</p>
196<a class="reference internal image-reference" href="_images/BufferMaskAndRequest_Routing_Level_15.png"><img alt="_images/BufferMaskAndRequest_Routing_Level_15.png" class="align-center" src="_images/BufferMaskAndRequest_Routing_Level_15.png" style="width: 650px;" /></a>
197<p>You can decompose the result above in two different ones: the mask around the
198buffer and the points included in the buffer. So you will create two different
199Services: one called <code class="docutils literal"><span class="pre">BufferMask</span></code> and another one called <code class="docutils literal"><span class="pre">BufferRequest</span></code>.</p>
200<p>But before implementing any JavaScript Service, you will get an overview of how
201to use ZOO-API from your ZOO-Project installation in the next section.</p>
202<p>As before, you first create a new directory to store files for your new Services
203Provider:</p>
204<div class="highlight-guess"><div class="highlight"><pre>mkdir -p ~/zoo-ws2013/jschains/cgi-env/
205</pre></div>
206</div>
207</div>
208<div class="section" id="zoo-api-overview">
209<h2><a class="toc-backref" href="#table-of-contents">ZOO-API Overview</a><a class="headerlink" href="#zoo-api-overview" title="Permalink to this headline"></a></h2>
210<p>ZOO-API and ZOO-Kernel JavaScript support make you able to run services
211implemented in JavaScript on the server side. JavaScript is a popular programing
212language but mostly used on the client side. Let say from a browser, but here it
213is a bit different.</p>
214<p>To support JavaScript language ZOO-Kernel use the
215<a class="reference external" href="https://developer.mozilla.org/en/SpiderMonkey">SpiderMonkey</a> API to create a
216javascript runtime environment from which it will load your JS file then extract
217the function corresponding to the service to run it using the prefilled
218parameters. The JavaScript runtime environment created by the ZOO-Kernel
219depend on your setup. If you placed the <code class="docutils literal"><span class="pre">ZOO-api.js</span></code> and <code class="docutils literal"><span class="pre">ZOO-proj4js.js</span></code> in
220the same directory as your ZOO-Kernel it means that your environment will
221contains ZOO-API and Proj4js will be loaded before your service. In such case you can access to the Classes defined in the JavaScript ZOO-API
222to manipulate geographic data, for more informations please refer to the
223<a class="reference external" href="http://zoo-project.org/docs/api/index.html">ZOO-API Documentation</a>.</p>
224<p>Even if it can be useful to run JavaScript on the server side, you should
225remember that some basic JavaScript functions you are familiar with does not
226exist or get a different behavior. For instance the simple <code class="docutils literal"><span class="pre">alert</span></code>
227function will display messages in apache error logs rather than in a window when
228used from a browser. The <code class="docutils literal"><span class="pre">alert</span></code> function can be used as follow:</p>
229<div class="highlight-guess"><div class="highlight"><pre>alert(&quot;My alert message&quot;);
230</pre></div>
231</div>
232<p>There is no XMLHttpRequest available in the JavaScript evironement your service
233will run into. Hopefully, the ZOO-Kernel expose a C function to the JavaScript
234world named: <code class="docutils literal"><span class="pre">JSRequest</span></code>. This function make you able from your JavaScript
235services to call other WPS services (locally or remotelly) or other kind OGC
236services such as WFS. When you are using the ZOO-API it is possible to call
237Services using a <code class="docutils literal"><span class="pre">ZOO.Process</span></code> instance <a class="footnote-reference" href="#f3" id="id1">[1]</a>, to parse WPS Responses using
238<code class="docutils literal"><span class="pre">ZOO.Format.WPS</span></code>
239(cf. <a class="reference external" href="http://zoo-project.org/docs/api/zoo-process.html">ref</a>).</p>
240<p>As for Python services you already seen in previous sections, the functions
241corresponding to a Service should take three arguments: <code class="docutils literal"><span class="pre">conf</span></code>, <code class="docutils literal"><span class="pre">inputs</span></code> and
242<code class="docutils literal"><span class="pre">outputs</span></code> <a class="footnote-reference" href="#f4" id="id2">[2]</a>. Nevertheless, as the ZOO-Kernel is not able to access the
243values modified <a class="footnote-reference" href="#f5" id="id3">[3]</a> by the Service code, rather than returning an integer as
244in Python, here you&#8217;ll need to return both the integer value representing the
245Status of your Service in a JavaScript Object and the resulting <code class="docutils literal"><span class="pre">outputs</span></code>
246values as an Object <a class="footnote-reference" href="#f6" id="id4">[4]</a>. You can see in the following an example of a JavaScript
247Service code:</p>
248<div class="highlight-none"><div class="highlight"><pre>function SampleService(conf,inputs,outputs){
249  var resultValue=someComputation(inputs);
250  return
251    {
252        result: ZOO.SERVICE_SUCCEEDED,
253        outputs: { &quot;Result&quot;: { &quot;mimeType&quot;: &quot;application/json&quot;, &quot;value&quot;: resultValue } }
254    };
255}
256</pre></div>
257</div>
258<p>Before starting to implement the Services we will need to get our final
259BufferRequest service, let start with a simplier one.</p>
260</div>
261<div class="section" id="the-mask-service">
262<h2><a class="toc-backref" href="#table-of-contents">The Mask Service</a><a class="headerlink" href="#the-mask-service" title="Permalink to this headline"></a></h2>
263<p>In this section you will learn how to create your first JavaScript service which
264will simply return a rectangular mask around a selected feature. To build this
265mask you will use the Buffer service to create a buffer big enough around a
266selected geometry to cover a significant part of your map. You can see the
267expected result in the following screenshot:</p>
268<a class="reference internal image-reference" href="_images/Mask_Level_12.png"><img alt="_images/Mask_Level_12.png" class="align-center" src="_images/Mask_Level_12.png" style="width: 650px;" /></a>
269<p>As before, you will first start by writting the ZCFG, then you will write the
270JavaScript source code and finish by publishing your Services Provider.</p>
271<div class="section" id="the-zcfg">
272<h3><a class="toc-backref" href="#table-of-contents">The ZCFG</a><a class="headerlink" href="#the-zcfg" title="Permalink to this headline"></a></h3>
273<p>Open the file named
274<code class="docutils literal"><span class="pre">~/zoo-ws2013/jschains/cgi-env/Mask.zcfg</span></code>
275with your favorite text editor and add the following content:</p>
276<div class="highlight-none"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
277 2
278 3
279 4
280 5
281 6
282 7
283 8
284 9
28510
28611
28712
28813
28914
29015
29116
29217
29318
29419
29520
29621
29722
29823
29924
30025
30126
30227
30328
30429
30530
30631</pre></div></td><td class="code"><div class="highlight"><pre>[Mask]
307 Title = Compute mask
308 Abstract = Compute mask around a geometry
309 processVersion = 1
310 storeSupported = true
311 statusSupported = true
312 serviceProvider = foss4gws.js
313 serviceType = JS
314 &lt;DataInputs&gt;
315  [InputData]
316   Title = The feature
317   Abstract = The feature to run the service with
318   minOccurs = 1
319   maxOccurs = 1
320   &lt;ComplexData&gt;
321    &lt;Default&gt;
322    mimeType = text/xml
323    encoding = utf-8
324    &lt;/Default&gt;
325   &lt;/ComplexData&gt;
326 &lt;/DataInputs&gt;
327 &lt;DataOutputs&gt;
328  [Result]
329   Title = The resulting feature
330   Abstract = The feature created by the service.
331   &lt;ComplexOutput&gt;
332     &lt;Default&gt;
333     mimeType = application/json
334     &lt;/Default&gt;
335   &lt;/ComplexOutput&gt;
336 &lt;/DataOutputs&gt;
337</pre></div>
338</td></tr></table></div>
339<p>Here you simply define one default <code class="docutils literal"><span class="pre">ComplexData</span></code> for both <code class="docutils literal"><span class="pre">inputData</span></code> and
340<code class="docutils literal"><span class="pre">Result</span></code>: a GML and a GeoJSON respectively <a class="footnote-reference" href="#f7" id="id5">[5]</a>.</p>
341</div>
342<div class="section" id="the-javascript-service">
343<h3><a class="toc-backref" href="#table-of-contents">The JavaScript service</a><a class="headerlink" href="#the-javascript-service" title="Permalink to this headline"></a></h3>
344<p>As you will have to request the Buffer service many times from your service, you
345will first define a <code class="docutils literal"><span class="pre">Buffer</span></code> function as follow. It uses the <code class="docutils literal"><span class="pre">ZOO.Process</span></code>
346to request the Buffer service you seen in the previous section.</p>
347<p>Open a file named
348<code class="docutils literal"><span class="pre">~/zoo-ws2013/jschains/cgi-env/foss4gws.js</span></code> and
349add the following content:</p>
350<div class="highlight-javascript"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
351 2
352 3
353 4
354 5
355 6
356 7
357 8
358 9
35910
36011
36112
36213
36314
36415
36516
36617
36718
36819
36920
37021
37122
37223</pre></div></td><td class="code"><div class="highlight"><pre><span class="kd">var</span> <span class="nx">zoo_url</span><span class="o">=</span><span class="s1">&#39;http://localhost/cgi-bin/zoo_loader.cgi&#39;</span><span class="p">;</span>
373<span class="kd">var</span> <span class="nx">mapfile</span><span class="o">=</span><span class="s2">&quot;/var/www/zoows2013-demo/map/w2013_1.map&quot;</span><span class="p">;</span>
374<span class="kd">var</span> <span class="nx">mapserv_url</span><span class="o">=</span><span class="s2">&quot;http://localhost/cgi-bin/mapserv?map=&quot;</span><span class="o">+</span><span class="nx">mapfile</span><span class="p">;</span>
375
376<span class="kd">function</span> <span class="nx">Buffer</span><span class="p">(</span><span class="nx">inputData</span><span class="p">,</span><span class="nx">bDist</span><span class="p">){</span>
377
378  <span class="c1">// Create all required ZOO.formats</span>
379  <span class="kd">var</span> <span class="nx">fJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">JSON</span><span class="p">();</span>
380  <span class="kd">var</span> <span class="nx">fGJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">();</span>
381  <span class="kd">var</span> <span class="nx">fWPS</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">WPS</span><span class="p">();</span>
382
383  <span class="c1">// Pass the value as json</span>
384  <span class="kd">var</span> <span class="nx">myInputs</span> <span class="o">=</span> <span class="p">{</span>
385      <span class="nx">InputPolygon</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">inputData</span><span class="p">),</span> <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">},</span>
386      <span class="nx">BufferDistance</span><span class="o">:</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;float&#39;</span><span class="p">,</span> <span class="s2">&quot;value&quot;</span><span class="o">:</span> <span class="nx">bDist</span> <span class="p">}</span>
387  <span class="p">};</span>
388  <span class="kd">var</span> <span class="nx">myOutputs</span><span class="o">=</span> <span class="p">{</span> <span class="nx">Result</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;RawDataOutput&#39;</span><span class="p">,</span> <span class="s2">&quot;mimeType&quot;</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span> <span class="p">}</span> <span class="p">};</span>
389  <span class="kd">var</span> <span class="nx">myProcess</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Process</span><span class="p">(</span><span class="nx">zoo_url</span><span class="p">,</span><span class="s1">&#39;BufferPy&#39;</span><span class="p">);</span>
390  <span class="kd">var</span> <span class="nx">myExecuteResult</span><span class="o">=</span><span class="nx">myProcess</span><span class="p">.</span><span class="nx">Execute</span><span class="p">(</span><span class="nx">myInputs</span><span class="p">,</span><span class="nx">myOutputs</span><span class="p">);</span>
391
392  <span class="k">return</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">myExecuteResult</span><span class="p">);</span>
393
394<span class="p">}</span>
395</pre></div>
396</td></tr></table></div>
397<p>From line 12 to 15, you give a GeoJSON string (created from <code class="docutils literal"><span class="pre">inputData</span></code>) for
398InputPolygon and, on line 14, you set the BufferDistance value to <code class="docutils literal"><span class="pre">bDist</span></code>.
399On line 16, you define Result as a ResponseDocument, so you&#8217;ll have to parse the
400WPS response using the ZOO.Format.WPS, on line 21.</p>
401<p>On line 17, you create a
402<a class="reference external" href="http://zoo-project.org/docs/api/zoo-process.html#zoo-process">ZOO.Process</a>
403instance providing the ZOO-Kernel url and the Service name. Then, on line 18, you
404run the request passing inputs and outputs previously defined (from line 12 to 15).</p>
405<p>Now, you get your <code class="docutils literal"><span class="pre">Buffer</span></code> function, it is time to create your first JavaScript
406service. So, edit your <code class="docutils literal"><span class="pre">foss4gws.js</span></code> file you created before and add the following content:</p>
407<div class="highlight-javascript"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
408 2
409 3
410 4
411 5
412 6
413 7
414 8
415 9
41610
41711
41812
41913
42014
42115
42216
42317
42418
42519
42620
42721
42822
42923
43024
43125
43226
43327
43428</pre></div></td><td class="code"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">Mask</span><span class="p">(</span><span class="nx">conf</span><span class="p">,</span><span class="nx">inputs</span><span class="p">,</span><span class="nx">outputs</span><span class="p">){</span>
435
436  <span class="c1">// Create all required ZOO.formats</span>
437  <span class="kd">var</span> <span class="nx">fGML</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GML</span><span class="p">();</span>
438  <span class="kd">var</span> <span class="nx">fGJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">();</span>
439
440  <span class="c1">// Read the input GML</span>
441  <span class="kd">var</span> <span class="nx">inputData</span><span class="o">=</span><span class="nx">fGML</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">inputs</span><span class="p">[</span><span class="s2">&quot;InputData&quot;</span><span class="p">][</span><span class="s2">&quot;value&quot;</span><span class="p">]);</span>
442
443  <span class="c1">// Compute Buffer</span>
444  <span class="kd">var</span> <span class="nx">bufferResultAsJSON</span><span class="o">=</span><span class="nx">Buffer</span><span class="p">(</span><span class="nx">inputData</span><span class="p">,</span><span class="mf">0.015</span><span class="p">);</span>
445
446  <span class="c1">// Create the Buffer result BBOX and store its geometry in a ZOO.Feature</span>
447  <span class="kd">var</span> <span class="nx">bbox</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Bounds</span><span class="p">();</span>
448  <span class="kd">var</span> <span class="nx">bounds</span><span class="o">=</span><span class="nx">bufferResultAsJSON</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">geometry</span><span class="p">.</span><span class="nx">getVertices</span><span class="p">();</span>
449  <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">t</span> <span class="k">in</span> <span class="nx">bounds</span><span class="p">){</span>
450    <span class="nx">bbox</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">bounds</span><span class="p">[</span><span class="nx">t</span><span class="p">]);</span>
451  <span class="p">}</span>
452  <span class="kd">var</span> <span class="nx">finalG</span><span class="o">=</span><span class="nx">bbox</span><span class="p">.</span><span class="nx">toGeometry</span><span class="p">();</span>
453  <span class="kd">var</span> <span class="nx">result</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Feature</span><span class="p">(</span><span class="nx">finalG</span><span class="p">,{</span><span class="s2">&quot;name&quot;</span><span class="o">:</span> <span class="s2">&quot;Result1000&quot;</span><span class="p">});</span>
454
455  <span class="c1">// Return the created feature</span>
456  <span class="k">return</span> <span class="p">{</span>
457      <span class="nx">result</span><span class="o">:</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">SERVICE_SUCCEEDED</span><span class="p">,</span>
458      <span class="nx">outputs</span><span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;Result&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="p">}</span> <span class="p">}</span>
459  <span class="p">};</span>
460
461<span class="p">}</span>
462</pre></div>
463</td></tr></table></div>
464</div>
465<div class="section" id="publish-and-use-your-service">
466<h3><a class="toc-backref" href="#table-of-contents">Publish and use your Service</a><a class="headerlink" href="#publish-and-use-your-service" title="Permalink to this headline"></a></h3>
467<p>Now you get both your ZCFG and your service code ready, you need to deploy your
468new Services Provider using the following command:</p>
469<div class="highlight-bash"><div class="highlight"><pre>cp ~/zoo-ws2013/jschains/cgi-env/* /usr/lib/cgi-bin
470</pre></div>
471</div>
472<p>Now you are ready to use your JavaScript service by loading the following <a class="reference external" href="http://localhost/zoows2013-demo/spatialtools.html">url</a>, click on a street then click on
473the &#8220;Mask&#8221; button.</p>
474</div>
475</div>
476<div class="section" id="buffermask-service">
477<h2><a class="toc-backref" href="#table-of-contents">BufferMask Service</a><a class="headerlink" href="#buffermask-service" title="Permalink to this headline"></a></h2>
478<p>In this section you will implement a simple JavaScript service which will be able create
479a hole in the mask you created in <a class="reference external" href="#mask-service">previous section</a>. This service
480will be used to highlight the buffer zone around a selected fature. You get a preview of
481the expected result in the following screenshot:</p>
482<a class="reference internal image-reference" href="_images/BufferMask_Level_15.png"><img alt="_images/BufferMask_Level_15.png" class="align-center" src="_images/BufferMask_Level_15.png" style="width: 650px;" /></a>
483<div class="section" id="id6">
484<h3><a class="toc-backref" href="#table-of-contents">The ZCFG</a><a class="headerlink" href="#id6" title="Permalink to this headline"></a></h3>
485<p>Open the file named
486<code class="docutils literal"><span class="pre">~/zoo-ws2013/jschains/cgi-env/BufferMask.zcfg</span></code>
487with your favorite text editor and copy / paste the following content:</p>
488<div class="highlight-none"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
489 2
490 3
491 4
492 5
493 6
494 7
495 8
496 9
49710
49811
49912
50013
50114
50215
50316
50417
50518
50619
50720
50821
50922
51023
51124
51225
51326
51427
51528
51629
51730
51831</pre></div></td><td class="code"><div class="highlight"><pre>[BufferMask]
519 Title = Compute buffer mask
520 Abstract = Compute buffer mask around a geometry
521 processVersion = 1
522 storeSupported = true
523 statusSupported = true
524 serviceProvider = foss4gws.js
525 serviceType = JS
526 &lt;DataInputs&gt;
527  [InputData]
528   Title = The feature
529   Abstract = The feature to run the service with
530   minOccurs = 1
531   maxOccurs = 1
532   &lt;ComplexData&gt;
533    &lt;Default&gt;
534    mimeType = text/xml
535    encoding = utf-8
536    &lt;/Default&gt;
537   &lt;/ComplexData&gt;
538 &lt;/DataInputs&gt;
539 &lt;DataOutputs&gt;
540  [Result]
541   Title = The resulting feature
542   Abstract = The feature created by the service.
543   &lt;ComplexOutput&gt;
544     &lt;Default&gt;
545     mimeType = application/json
546     &lt;/Default&gt;
547   &lt;/ComplexOutput&gt;
548 &lt;/DataOutputs&gt;
549</pre></div>
550</td></tr></table></div>
551<p>This ZCFG is similar to the previous one. Please, refer to comments in the
552<a class="reference external" href="#the-zcfg">previous section</a> for more informations.</p>
553</div>
554<div class="section" id="id7">
555<h3><a class="toc-backref" href="#table-of-contents">The JavaScript service</a><a class="headerlink" href="#id7" title="Permalink to this headline"></a></h3>
556<p>In this Service you will use same source code (until line 19) you used in the
557<a class="reference external" href="#the-javascript-service">previous section</a>. Indeed, you should compute the Mask
558as you did before then compute Buffer for creating a hole in the mask (on line 22) to run
559the Difference service (from line 25 to 40).</p>
560<div class="highlight-guess"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
561 2
562 3
563 4
564 5
565 6
566 7
567 8
568 9
56910
57011
57112
57213
57314
57415
57516
57617
57718
57819
57920
58021
58122
58223
58324
58425
58526
58627
58728
58829
58930
59031
59132
59233
59334
59435
59536
59637
59738
59839
59940
60041
60142
60243
60344
60445
60546
60647
60748
60849</pre></div></td><td class="code"><div class="highlight"><pre> <span class="kd">function</span> <span class="nx">BufferMask</span><span class="p">(</span><span class="nx">conf</span><span class="p">,</span><span class="nx">inputs</span><span class="p">,</span><span class="nx">outputs</span><span class="p">){</span>
609
610   <span class="c1">// Create all required ZOO.formats</span>
611   <span class="kd">var</span> <span class="nx">fGML</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GML</span><span class="p">();</span>
612   <span class="kd">var</span> <span class="nx">fGJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">();</span>
613
614   <span class="c1">// Read the input GML</span>
615   <span class="kd">var</span> <span class="nx">inputData</span><span class="o">=</span><span class="nx">fGML</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">inputs</span><span class="cp">[</span><span class="s2">&quot;InputData&quot;</span><span class="cp">][</span><span class="s2">&quot;value&quot;</span><span class="cp">]</span><span class="p">);</span>
616
617   <span class="c1">// Compute Buffer</span>
618   <span class="kd">var</span> <span class="nx">bufferResultAsJSON</span><span class="o">=</span><span class="nx">Buffer</span><span class="p">(</span><span class="nx">inputData</span><span class="p">,</span><span class="mf">0.015</span><span class="p">);</span>
619
620   <span class="c1">// Create the Buffer result BBOX</span>
621   <span class="kd">var</span> <span class="nx">bbox</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Bounds</span><span class="p">();</span>
622   <span class="kd">var</span> <span class="nx">bounds</span><span class="o">=</span><span class="nx">bufferResultAsJSON</span><span class="cp">[</span><span class="mi">0</span><span class="cp">]</span><span class="p">.</span><span class="nx">geometry</span><span class="p">.</span><span class="nx">getVertices</span><span class="p">();</span>
623   <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">t</span> <span class="k">in</span> <span class="nx">bounds</span><span class="p">){</span>
624     <span class="nx">bbox</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">bounds</span><span class="cp">[</span><span class="nx">t</span><span class="cp">]</span><span class="p">);</span>
625   <span class="p">}</span>
626   <span class="kd">var</span> <span class="nx">finalG</span><span class="o">=</span><span class="nx">bbox</span><span class="p">.</span><span class="nx">toGeometry</span><span class="p">();</span>
627
628  <span class="c1">// Compute Buffer standard buffer</span>
629  <span class="kd">var</span> <span class="nx">bufferResultAsJSON</span><span class="o">=</span><span class="nx">Buffer</span><span class="p">(</span><span class="nx">inputData</span><span class="p">,</span><span class="mf">0.0015</span><span class="p">);</span>
630
631  <span class="c1">// Request Difference service using Buffer result and features in the BBOX</span>
632  <span class="kd">var</span> <span class="nx">result</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Feature</span><span class="p">(</span><span class="nx">finalG</span><span class="p">,{</span><span class="s2">&quot;name&quot;</span><span class="o">:</span> <span class="s2">&quot;Result1000&quot;</span><span class="p">});</span>
633  <span class="kd">var</span> <span class="nx">myProcess2</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Process</span><span class="p">(</span><span class="nx">zoo_url</span><span class="p">,</span><span class="s1">&#39;DifferencePy&#39;</span><span class="p">);</span>
634  <span class="kd">var</span> <span class="nx">myInputs2</span> <span class="o">=</span> <span class="p">{</span>
635      <span class="nx">InputEntity1</span><span class="o">:</span> <span class="p">{</span>
636          <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span>
637          <span class="nx">value</span><span class="o">:</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">finalG</span><span class="p">),</span>
638          <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span>
639      <span class="p">},</span>
640      <span class="nx">InputEntity2</span><span class="o">:</span> <span class="p">{</span>
641          <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span>
642          <span class="nx">value</span><span class="o">:</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">bufferResultAsJSON</span><span class="p">),</span>
643          <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span>
644      <span class="p">}</span>
645  <span class="p">};</span>
646  <span class="kd">var</span> <span class="nx">myOutputs2</span><span class="o">=</span> <span class="p">{</span><span class="nx">Result</span><span class="o">:</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;RawDataOutput&#39;</span><span class="p">,</span>  <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span> <span class="p">}</span> <span class="p">};</span>
647  <span class="kd">var</span> <span class="nx">myExecuteResult4</span><span class="o">=</span><span class="nx">myProcess2</span><span class="p">.</span><span class="nx">Execute</span><span class="p">(</span><span class="nx">myInputs2</span><span class="p">,</span><span class="nx">myOutputs2</span><span class="p">);</span>
648
649   <span class="c1">// Return the bbox</span>
650   <span class="kd">var</span> <span class="nx">result</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Feature</span><span class="p">(</span><span class="nx">finalG</span><span class="p">,{</span><span class="s2">&quot;name&quot;</span><span class="o">:</span> <span class="s2">&quot;Result1000&quot;</span><span class="p">});</span>
651   <span class="k">return</span> <span class="p">{</span>
652       <span class="nx">result</span><span class="o">:</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">SERVICE_SUCCEEDED</span><span class="p">,</span>
653       <span class="nx">outputs</span><span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;Result&quot;</span><span class="o">:</span> <span class="p">{</span><span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">myExecuteResult4</span> <span class="p">}</span> <span class="p">}</span>
654   <span class="p">};</span>
655
656 <span class="p">}</span>
657</pre></div>
658</td></tr></table></div>
659</div>
660<div class="section" id="id8">
661<h3><a class="toc-backref" href="#table-of-contents">Publish and use your Service</a><a class="headerlink" href="#id8" title="Permalink to this headline"></a></h3>
662<p>Now, you can publish your service as you did <a class="reference external" href="#publish-your-service">before</a>. To
663use your service, please use the following <a class="reference external" href="http://localhost/zoows2013-demo/spatialtools.html">url</a>.</p>
664</div>
665</div>
666<div class="section" id="bufferrequest-service">
667<h2><a class="toc-backref" href="#table-of-contents">BufferRequest service</a><a class="headerlink" href="#bufferrequest-service" title="Permalink to this headline"></a></h2>
668<p>In this section, you will create a new Service: <code class="docutils literal"><span class="pre">BufferRequest</span></code> which will request
669POIs included in the Buffer around a selected feature <a class="footnote-reference" href="#f8" id="id9">[6]</a>. You will use the <code class="docutils literal"><span class="pre">poi</span></code>
670layer served as WFS through your local mapserver installation. You can see in the
671following screenshot the expected result:</p>
672<a class="reference internal image-reference" href="_images/BufferRequest_Level_15.png"><img alt="_images/BufferRequest_Level_15.png" class="align-center" src="_images/BufferRequest_Level_15.png" style="width: 650px;" /></a>
673<div class="section" id="id10">
674<h3><a class="toc-backref" href="#table-of-contents">The ZCFG</a><a class="headerlink" href="#id10" title="Permalink to this headline"></a></h3>
675<p>Open the file named
676<code class="docutils literal"><span class="pre">~/zoo-ws2013/jschains/cgi-env/BufferRequest.zcfg</span></code>
677with your favorite text editor and copy / paste the following content:</p>
678<div class="highlight-none"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
679 2
680 3
681 4
682 5
683 6
684 7
685 8
686 9
68710
68811
68912
69013
69114
69215
69316
69417
69518
69619
69720
69821
69922
70023
70124
70225
70326
70427
70528
70629
70730
70831</pre></div></td><td class="code"><div class="highlight"><pre>[BufferRequest]
709 Title = Compute buffer request
710 Abstract = Compute buffer request around a geometry
711 processVersion = 1
712 storeSupported = true
713 statusSupported = true
714 serviceProvider = foss4gws.js
715 serviceType = JS
716 &lt;DataInputs&gt;
717  [InputData]
718   Title = The feature
719   Abstract = The feature to run the service with
720   minOccurs = 1
721   maxOccurs = 1
722   &lt;ComplexData&gt;
723    &lt;Default&gt;
724    mimeType = text/xml
725    encoding = utf-8
726    &lt;/Default&gt;
727   &lt;/ComplexData&gt;
728 &lt;/DataInputs&gt;
729 &lt;DataOutputs&gt;
730  [Result]
731   Title = The resulting feature
732   Abstract = The feature created by the service.
733   &lt;ComplexOutput&gt;
734     &lt;Default&gt;
735     mimeType = application/json
736     &lt;/Default&gt;
737   &lt;/ComplexOutput&gt;
738 &lt;/DataOutputs&gt;
739</pre></div>
740</td></tr></table></div>
741</div>
742<div class="section" id="the-javascript-code">
743<h3><a class="toc-backref" href="#table-of-contents">The JavaScript code</a><a class="headerlink" href="#the-javascript-code" title="Permalink to this headline"></a></h3>
744<p>As in the previous Service, you will compute a buffer around the input feature. But then
745you will request POIs available in the Buffer extent using a WFS request to use them to
746run <code class="docutils literal"><span class="pre">Intersection</span></code> service using the initial Buffer. The WFS request is useful to limit
747the number of points to use when requesting the <code class="docutils literal"><span class="pre">Intersection</span></code> Service.</p>
748<div class="highlight-javascript"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
749 2
750 3
751 4
752 5
753 6
754 7
755 8
756 9
75710
75811
75912
76013
76114
76215
76316
76417
76518
76619
76720
76821
76922
77023
77124
77225
77326
77427
77528
77629
77730
77831
77932
78033
78134
78235
78336
78437
78538
78639
78740
78841
78942
79043
79144
79245</pre></div></td><td class="code"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">BufferRequest</span><span class="p">(</span><span class="nx">conf</span><span class="p">,</span><span class="nx">inputs</span><span class="p">,</span><span class="nx">outputs</span><span class="p">){</span>
793
794  <span class="c1">// Create all required ZOO.formats</span>
795  <span class="kd">var</span> <span class="nx">fGJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">();</span>
796  <span class="kd">var</span> <span class="nx">fGML</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GML</span><span class="p">();</span>
797
798  <span class="c1">// Read the input GML</span>
799  <span class="kd">var</span> <span class="nx">inputData</span><span class="o">=</span><span class="nx">fGML</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">inputs</span><span class="p">[</span><span class="s2">&quot;InputData&quot;</span><span class="p">][</span><span class="s2">&quot;value&quot;</span><span class="p">]);</span>
800
801  <span class="c1">// Compute Buffer</span>
802  <span class="kd">var</span> <span class="nx">bufferResultAsJSON</span><span class="o">=</span><span class="nx">Buffer</span><span class="p">(</span><span class="nx">inputData</span><span class="p">,</span><span class="mf">0.0015</span><span class="p">);</span>
803
804  <span class="c1">// Create the Buffer result BBOX</span>
805  <span class="kd">var</span> <span class="nx">bbox</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Bounds</span><span class="p">();</span>
806  <span class="kd">var</span> <span class="nx">bounds</span><span class="o">=</span><span class="nx">bufferResultAsJSON</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">geometry</span><span class="p">.</span><span class="nx">getVertices</span><span class="p">();</span>
807  <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">t</span> <span class="k">in</span> <span class="nx">bounds</span><span class="p">){</span>
808    <span class="nx">bbox</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">bounds</span><span class="p">[</span><span class="nx">t</span><span class="p">]);</span>
809  <span class="p">}</span>
810
811  <span class="c1">// Request Intersection service using Buffer result and WFS request using the</span>
812  <span class="c1">// BBOX</span>
813  <span class="kd">var</span> <span class="nx">myProcess2</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Process</span><span class="p">(</span><span class="nx">zoo_url</span><span class="p">,</span><span class="s1">&#39;Intersection&#39;</span><span class="p">);</span>
814  <span class="kd">var</span> <span class="nx">req</span><span class="o">=</span><span class="s2">&quot;&amp;amp;version=1.0.0&amp;amp;request=GetFeature&amp;amp;typename=poi1&quot;</span><span class="p">;</span>
815  <span class="nx">req</span><span class="o">+=</span><span class="s2">&quot;&amp;amp;SRS=EPSG:4326&amp;amp;BBOX=&quot;</span><span class="p">;</span>
816  <span class="kd">var</span> <span class="nx">myInputs2</span> <span class="o">=</span> <span class="p">{</span>
817    <span class="nx">InputEntity1</span><span class="o">:</span> <span class="p">{</span>
818      <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span>
819      <span class="nx">value</span><span class="o">:</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">bufferResultAsJSON</span><span class="p">),</span>
820      <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span>
821    <span class="p">},</span>
822    <span class="nx">InputEntity2</span><span class="o">:</span> <span class="p">{</span>
823      <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span>
824      <span class="nx">xlink</span><span class="o">:</span> <span class="nx">mapserv_url</span><span class="o">+</span><span class="nx">req</span><span class="o">+</span><span class="nx">bbox</span><span class="p">.</span><span class="nx">left</span><span class="o">+</span><span class="s2">&quot;,&quot;</span><span class="o">+</span><span class="nx">bbox</span><span class="p">.</span><span class="nx">bottom</span><span class="o">+</span><span class="s2">&quot;,&quot;</span><span class="o">+</span><span class="nx">bbox</span><span class="p">.</span><span class="nx">right</span><span class="o">+</span><span class="s2">&quot;,&quot;</span><span class="o">+</span><span class="nx">bbox</span><span class="p">.</span><span class="nx">top</span><span class="p">,</span>
825      <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;text/xml&quot;</span>
826    <span class="p">}</span>
827  <span class="p">};</span>
828  <span class="kd">var</span> <span class="nx">myOutputs2</span><span class="o">=</span> <span class="p">{</span><span class="nx">Result</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;RawDataOutput&#39;</span><span class="p">,</span> <span class="s2">&quot;mimeType&quot;</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span> <span class="p">}</span> <span class="p">};</span>
829  <span class="kd">var</span> <span class="nx">myExecuteResult4</span><span class="o">=</span><span class="nx">myProcess2</span><span class="p">.</span><span class="nx">Execute</span><span class="p">(</span><span class="nx">myInputs2</span><span class="p">,</span><span class="nx">myOutputs2</span><span class="p">);</span>
830
831  <span class="k">return</span> <span class="p">{</span>
832    <span class="nx">result</span><span class="o">:</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">SERVICE_SUCCEEDED</span><span class="p">,</span>
833    <span class="nx">outputs</span><span class="o">:</span> <span class="p">[</span> <span class="p">{</span><span class="nx">name</span><span class="o">:</span><span class="s2">&quot;Result&quot;</span><span class="p">,</span> <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">myExecuteResult4</span><span class="p">}</span> <span class="p">]</span>
834  <span class="p">};</span>
835
836<span class="p">}</span>
837</pre></div>
838</td></tr></table></div>
839<div class="admonition warning">
840<p class="first admonition-title">Warning</p>
841<p class="last">to take advantage of the ZOO-Kernel cache system, you directly use the WFS
842request  as <code class="docutils literal"><span class="pre">xlink:href</span></code> rather than value for <code class="docutils literal"><span class="pre">InputEntity2</span></code> (from line 31 to 34) and use <code class="docutils literal"><span class="pre">text/xml</span></code> <code class="docutils literal"><span class="pre">mimeType</span></code>
843(on line 40). Indeed, the ZOO-API doesn&#8217;t use the internal cache mechanisms.</p>
844</div>
845</div>
846<div class="section" id="id11">
847<h3><a class="toc-backref" href="#table-of-contents">Publish and use your Service</a><a class="headerlink" href="#id11" title="Permalink to this headline"></a></h3>
848<p>Now, you can publish your service as you did <a class="reference external" href="#publish-your-service">before</a>. To
849use your service, please use the following <a class="reference external" href="http://localhost/zoows2013-demo/spatialtools.html">url</a>.</p>
850<div class="admonition note">
851<p class="first admonition-title">Note</p>
852<p class="last">You can click on &#8220;Buffer Request and Mask&#8221;  to get the same result as presented
853in  <a class="reference external" href="#introduction">the initial screenshot</a>.</p>
854</div>
855</div>
856</div>
857<div class="section" id="add-union-into-the-chain">
858<h2><a class="toc-backref" href="#table-of-contents">Add Union into the chain</a><a class="headerlink" href="#add-union-into-the-chain" title="Permalink to this headline"></a></h2>
859<p>As you can see in the following screenshot, when using the Buffer
860service using a feature collection containing more than one geometry,
861the result is made of multiple geometries. So, running Buffer service
862on the routing interface will result in multiple buffer:</p>
863<a class="reference internal image-reference" href="_images/Buffer_Routing_Level_15.png"><img alt="_images/Buffer_Routing_Level_15.png" class="align-center" src="_images/Buffer_Routing_Level_15.png" style="width: 650px;" /></a>
864<p>So, to get the same result as you got when selecting a single
865road, you should use Union of geometry (input or the one outputed by the
866<code class="docutils literal"><span class="pre">Buffer</span></code> Service). As you are using the JavaScript ZOO-API, you can
867simply update the <code class="docutils literal"><span class="pre">Buffer</span></code> JavaScript function you defined earlier, to
868first call the Union of each geometry avaible in a feature collection
869prior to request (or after requesting) the Buffer Service. Hopefully,
870there is already this Python Service available, its name is
871<code class="docutils literal"><span class="pre">UnionOne1</span></code>, so you just need to add it in your Service chain.</p>
872<p>Here is the final code for the Buffer JavaScript function:</p>
873<div class="highlight-javascript"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
874 2
875 3
876 4
877 5
878 6
879 7
880 8
881 9
88210
88311
88412
88513
88614
88715
88816
88917
89018
89119
89220
89321
89422
89523
89624
89725
89826
89927
90028</pre></div></td><td class="code"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">Buffer</span><span class="p">(</span><span class="nx">inputData</span><span class="p">,</span><span class="nx">bDist</span><span class="p">){</span>
901
902  <span class="c1">// Create all required ZOO.formats</span>
903  <span class="kd">var</span> <span class="nx">fJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">JSON</span><span class="p">();</span>
904  <span class="kd">var</span> <span class="nx">fGJ</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">();</span>
905  <span class="kd">var</span> <span class="nx">fWPS</span><span class="o">=</span><span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">WPS</span><span class="p">();</span>
906
907  <span class="c1">// Call the UnionOne1 Service</span>
908  <span class="kd">var</span> <span class="nx">myInputs0</span> <span class="o">=</span> <span class="p">{</span>
909      <span class="nx">InputPolygon</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">inputData</span><span class="p">),</span> <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">},</span>
910      <span class="nx">BufferDistance</span><span class="o">:</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;float&#39;</span><span class="p">,</span> <span class="s2">&quot;value&quot;</span><span class="o">:</span> <span class="nx">bDist</span> <span class="p">}</span>
911  <span class="p">};</span>
912  <span class="kd">var</span> <span class="nx">myOutputs0</span><span class="o">=</span> <span class="p">{</span> <span class="nx">Result</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;RawDataOutput&#39;</span><span class="p">,</span> <span class="s2">&quot;mimeType&quot;</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span> <span class="p">}</span> <span class="p">};</span>
913  <span class="kd">var</span> <span class="nx">myProcess0</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Process</span><span class="p">(</span><span class="nx">zoo_url</span><span class="p">,</span><span class="s1">&#39;UnionOne1&#39;</span><span class="p">);</span>
914  <span class="kd">var</span> <span class="nx">myExecuteResult0</span><span class="o">=</span><span class="nx">myProcess0</span><span class="p">.</span><span class="nx">Execute</span><span class="p">(</span><span class="nx">myInputs0</span><span class="p">,</span><span class="nx">myOutputs0</span><span class="p">);</span>
915
916  <span class="c1">// Call the BufferPy Service</span>
917  <span class="kd">var</span> <span class="nx">myInputs</span> <span class="o">=</span> <span class="p">{</span>
918      <span class="nx">InputPolygon</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;complex&#39;</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">myExecuteResult0</span><span class="p">,</span> <span class="nx">mimeType</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">},</span>
919      <span class="nx">BufferDistance</span><span class="o">:</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;float&#39;</span><span class="p">,</span> <span class="s2">&quot;value&quot;</span><span class="o">:</span> <span class="nx">bDist</span> <span class="p">}</span>
920  <span class="p">};</span>
921  <span class="kd">var</span> <span class="nx">myOutputs</span><span class="o">=</span> <span class="p">{</span> <span class="nx">Result</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;RawDataOutput&#39;</span><span class="p">,</span> <span class="s2">&quot;mimeType&quot;</span><span class="o">:</span> <span class="s2">&quot;application/json&quot;</span> <span class="p">}</span> <span class="p">};</span>
922  <span class="kd">var</span> <span class="nx">myProcess</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ZOO</span><span class="p">.</span><span class="nx">Process</span><span class="p">(</span><span class="nx">zoo_url</span><span class="p">,</span><span class="s1">&#39;BufferPy&#39;</span><span class="p">);</span>
923  <span class="kd">var</span> <span class="nx">myExecuteResult</span><span class="o">=</span><span class="nx">myProcess</span><span class="p">.</span><span class="nx">Execute</span><span class="p">(</span><span class="nx">myInputs</span><span class="p">,</span><span class="nx">myOutputs</span><span class="p">);</span>
924
925  <span class="k">return</span> <span class="nx">fGJ</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">myExecuteResult</span><span class="p">);</span>
926
927<span class="p">}</span>
928</pre></div>
929</td></tr></table></div>
930</div>
931<div class="section" id="conclusion">
932<h2><a class="toc-backref" href="#table-of-contents">Conclusion</a><a class="headerlink" href="#conclusion" title="Permalink to this headline"></a></h2>
933<p>After understanding how basic Geometric Operation Services works, here you built step by step new JavaScript services which reuse the previous ones and combine them in different ways. This was achieved using the ZOO-API, composed by C functions exposed by the ZOO-Kernel to the JavaScript services runtime environement and the JS files which can be optionally installed.</p>
934<p class="rubric">Footnotes</p>
935<table class="docutils footnote" frame="void" id="f3" rules="none">
936<colgroup><col class="label" /><col /></colgroup>
937<tbody valign="top">
938<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>The <code class="docutils literal"><span class="pre">ZOO.Process</span></code> class uses <code class="docutils literal"><span class="pre">JSRequest</span></code> (cf. <a class="reference external" href="http://zoo-project.org/docs/api/zoo-format-wps.html">ref</a>). You will get example
939of use <a class="reference external" href="#the-javascript-service">later</a>.</td></tr>
940</tbody>
941</table>
942<table class="docutils footnote" frame="void" id="f4" rules="none">
943<colgroup><col class="label" /><col /></colgroup>
944<tbody valign="top">
945<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>So <code class="docutils literal"><span class="pre">conf</span></code>, <code class="docutils literal"><span class="pre">inputs</span></code> and <code class="docutils literal"><span class="pre">outputs</span></code> are simple JavaScript objects, similar
946to the Python dictionaries used in the <a class="reference external" href="ogr_base_vect_ops.html">previous section</a>.</td></tr>
947</tbody>
948</table>
949<table class="docutils footnote" frame="void" id="f5" rules="none">
950<colgroup><col class="label" /><col /></colgroup>
951<tbody valign="top">
952<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td>Such as <code class="docutils literal"><span class="pre">conf</span></code>, <code class="docutils literal"><span class="pre">inputs</span></code> and <code class="docutils literal"><span class="pre">outputs</span></code>.</td></tr>
953</tbody>
954</table>
955<table class="docutils footnote" frame="void" id="f6" rules="none">
956<colgroup><col class="label" /><col /></colgroup>
957<tbody valign="top">
958<tr><td class="label"><a class="fn-backref" href="#id4">[4]</a></td><td>You can also return a conf Object if you get any informations updated from your JavaScript service (such as cookie for instance)</td></tr>
959</tbody>
960</table>
961<table class="docutils footnote" frame="void" id="f7" rules="none">
962<colgroup><col class="label" /><col /></colgroup>
963<tbody valign="top">
964<tr><td class="label"><a class="fn-backref" href="#id5">[5]</a></td><td>Using one of the available <code class="docutils literal"><span class="pre">ZOO.formats</span></code> you are also able to support various
965<code class="docutils literal"><span class="pre">ComplexData</span></code> for both input and output of the service. To simplify the
966presentation here, you will use only this default ones.</td></tr>
967</tbody>
968</table>
969<table class="docutils footnote" frame="void" id="f8" rules="none">
970<colgroup><col class="label" /><col /></colgroup>
971<tbody valign="top">
972<tr><td class="label"><a class="fn-backref" href="#id9">[6]</a></td><td>So in the hole you created in the previous section.</td></tr>
973</tbody>
974</table>
975</div>
976</div>
977
978
979          </div>
980          <footer>
981 
982    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
983     
984     
985        <a href="building_blocks_presentation.html" class="btn btn-neutral" title="Building blocks presentation - Using OGR and PgRouting based Web Services"><span class="fa fa-arrow-circle-left"></span> Previous</a>
986     
987    </div>
988 
989
990  <hr/>
991  <div class="pfoot">
992  <div role="contentinfo">
993    <p>
994        &copy; Copyright 2009-2015, ZOO-Project team.
995    </p>
996  </div>
997  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> inspired by <a href="https://readthedocs.org">Read the Docs</a>.
998</div>
999</footer>
1000
1001        </div>
1002      </div>
1003
1004    </section>
1005
1006  </div>
1007 
1008
1009
1010 
1011
1012    <script type="text/javascript">
1013        var DOCUMENTATION_OPTIONS = {
1014            URL_ROOT:'./',
1015            VERSION:'1.5',
1016            COLLAPSE_INDEX:false,
1017            FILE_SUFFIX:'.html',
1018            HAS_SOURCE:  true
1019        };
1020    </script>
1021      <script type="text/javascript" src="_static/jquery.js"></script>
1022      <script type="text/javascript" src="_static/underscore.js"></script>
1023      <script type="text/javascript" src="_static/doctools.js"></script>
1024
1025 
1026
1027 
1028 
1029    <script type="text/javascript" src="_static/js/theme.js"></script>
1030 
1031
1032 
1033 
1034  <script type="text/javascript">
1035      jQuery(function () {
1036          SphinxRtdTheme.StickyNav.enable();
1037      });
1038  </script>
1039   
1040
1041</body>
1042</html>
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png