| 1 | .. _ogr_base_vect_ops: |
---|
| 2 | |
---|
| 3 | *************************************************************** |
---|
| 4 | Playing with buildign blocks - Creating JavaScript Web Services |
---|
| 5 | *************************************************************** |
---|
| 6 | |
---|
| 7 | .. contents:: Table of Contents |
---|
| 8 | :depth: 5 |
---|
| 9 | :backlinks: top |
---|
| 10 | |
---|
| 11 | Introduction |
---|
| 12 | ============ |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | This section illustrate how you can use JavaScript on the server-side to chain |
---|
| 16 | services together to build new ones. You will create a ZOO Services Provider |
---|
| 17 | using the services you seen before and the WFS server using the ZOO-API. The |
---|
| 18 | final goal is to query all POIs included in a buffer around a feature and |
---|
| 19 | to highlight them using a mask around this buffer. The following screenshot show |
---|
| 20 | you the expected result: |
---|
| 21 | |
---|
| 22 | .. image:: ./images/BufferMaskAndRequest_Level_15.png |
---|
| 23 | :width: 650px |
---|
| 24 | :align: center |
---|
| 25 | |
---|
| 26 | You can decompose the result above in two different ones: the mask around the |
---|
| 27 | buffer and the points included in the buffer. So you will create two different |
---|
| 28 | Services: one called ``BufferMask`` and another one called ``BufferRequest``. |
---|
| 29 | |
---|
| 30 | But before implementing any JavaScript Service, you will get an overview of how |
---|
| 31 | to use ZOO-API from your ZOO-Project installation in the next section. |
---|
| 32 | |
---|
| 33 | As before, you first create a new directory to store files for your new Services |
---|
| 34 | Provider named ``ws2012js``: |
---|
| 35 | |
---|
| 36 | .. code-block:: guess |
---|
| 37 | |
---|
| 38 | mkdir -p ~/zoo-ws-2012/zoo-project/zoo-services/ws2012js/cgi-env/ |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | ZOO-API Overview |
---|
| 42 | ================ |
---|
| 43 | |
---|
| 44 | ZOO-API and ZOO-Kernel JavaScript support make you able to run services |
---|
| 45 | implemented in JavaScript on the server side. JavaScript is a popular programing |
---|
| 46 | language but mostly used on the client side. Let say from a browser, but here it |
---|
| 47 | is a bit different. |
---|
| 48 | |
---|
| 49 | To support JavaScript language ZOO-Kernel use the |
---|
| 50 | `SpiderMonkey <https://developer.mozilla.org/en/SpiderMonkey>`__ API to create a |
---|
| 51 | javascript runtime environment from which it will load your JS file then extract |
---|
| 52 | the function corresponding to the service to run it using the prefilled |
---|
| 53 | parameters. The JavaScript runtime environment created by the ZOO-Kernel |
---|
| 54 | depend on your setup. If you placed the ``ZOO-api.js`` and ``ZOO-proj4js.js`` in |
---|
| 55 | the same directory as your ZOO-Kernel it means that your environment will |
---|
| 56 | contains 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 |
---|
| 57 | to manipulate geographic data, for more informations please refer to the |
---|
| 58 | `ZOO-API Documentation <http://zoo-project.org/docs/api/index.html>`__. |
---|
| 59 | |
---|
| 60 | Even if it can be useful to run JavaScript on the server side, you should |
---|
| 61 | remember that some basic JavaScript functions you are familiar with does not |
---|
| 62 | exist or get a different behavior. For instance the simple ``alert`` |
---|
| 63 | function will display messages in apache error logs rather than in a window when |
---|
| 64 | used from a browser. The ``alert`` function can be used as follow: |
---|
| 65 | |
---|
| 66 | .. code-block:: guess |
---|
| 67 | |
---|
| 68 | alert("My alert message"); |
---|
| 69 | |
---|
| 70 | There is no XMLHttpRequest available in the JavaScript evironement your service |
---|
| 71 | will run into. Hopefully, the ZOO-Kernel expose a C function to the JavaScript |
---|
| 72 | world named: ``JSRequest``. This function make you able from your JavaScript |
---|
| 73 | services to call other WPS services (locally or remotelly) or other kind OGC |
---|
| 74 | services such as WFS. When you are using the ZOO-API it is possible to call |
---|
| 75 | Services using a ``ZOO.Process`` instance [#f3]_, to parse WPS Responses using |
---|
| 76 | ``ZOO.Format.WPS`` |
---|
| 77 | (cf. `ref <http://zoo-project.org/docs/api/zoo-process.html>`__). |
---|
| 78 | |
---|
| 79 | As for Python services you already seen in previous sections, the functions |
---|
| 80 | corresponding to a Service should take three arguments: ``conf``, ``inputs`` and |
---|
| 81 | ``outputs`` [#f4]_. Nevertheless, as the ZOO-Kernel is not able to access the |
---|
| 82 | values modified [#f5]_ by the Service code, rather than returning an integer as |
---|
| 83 | in Python, here you'll need to return both the integer value representing the |
---|
| 84 | Status of your Service in a JavaScript Object and the resulting ``outputs`` |
---|
| 85 | values as an Object. You can see in the following an example of a JavaScript |
---|
| 86 | Service code: |
---|
| 87 | |
---|
| 88 | .. code-block:: none |
---|
| 89 | |
---|
| 90 | function SampleService(conf,inputs,outputs){ |
---|
| 91 | var resultValue=someComputation(inputs); |
---|
| 92 | return |
---|
| 93 | { |
---|
| 94 | result: ZOO.SERVICE_SUCCEEDED, |
---|
| 95 | outputs: { "Result": { "mimeType": "application/json", "value": resultValue } } |
---|
| 96 | }; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | Before starting to implement the Services we will need to get our final |
---|
| 100 | BufferRequest service, let start with a simplier one. |
---|
| 101 | |
---|
| 102 | The Mask Service |
---|
| 103 | ================ |
---|
| 104 | |
---|
| 105 | In this section you will learn how to create your first JavaScript service which |
---|
| 106 | will simply return a rectangular mask around a selected feature. To build this |
---|
| 107 | mask you will use the Buffer service to create a buffer big enough around a |
---|
| 108 | selected geometry to cover a significant part of your map. You can see the |
---|
| 109 | expected result in the following screenshot: |
---|
| 110 | |
---|
| 111 | .. image:: ./images/Mask_Level_12.png |
---|
| 112 | :width: 650px |
---|
| 113 | :align: center |
---|
| 114 | |
---|
| 115 | As before, you will first start by writting the ZCFG, then you will write the |
---|
| 116 | JavaScript source code and finish by publishing your Services Provider. |
---|
| 117 | |
---|
| 118 | The ZCFG |
---|
| 119 | -------- |
---|
| 120 | |
---|
| 121 | Open the file named |
---|
| 122 | ``~/zoo-ws-2012/src/zoo-project/zoo-services/ws2012js/cgi-env/Mask.zcfg`` |
---|
| 123 | with your favorite text editor and add the following content: |
---|
| 124 | |
---|
| 125 | .. code-block:: none |
---|
| 126 | :linenos: |
---|
| 127 | |
---|
| 128 | [Mask] |
---|
| 129 | Title = Compute mask |
---|
| 130 | Abstract = Compute mask around a geometry |
---|
| 131 | processVersion = 1 |
---|
| 132 | storeSupported = true |
---|
| 133 | statusSupported = true |
---|
| 134 | serviceProvider = foss4gws.js |
---|
| 135 | serviceType = JS |
---|
| 136 | <DataInputs> |
---|
| 137 | [InputData] |
---|
| 138 | Title = The feature |
---|
| 139 | Abstract = The feature to run the service with |
---|
| 140 | minOccurs = 1 |
---|
| 141 | maxOccurs = 1 |
---|
| 142 | <ComplexData> |
---|
| 143 | <Default> |
---|
| 144 | mimeType = text/xml |
---|
| 145 | encoding = utf-8 |
---|
| 146 | </Default> |
---|
| 147 | </ComplexData> |
---|
| 148 | </DataInputs> |
---|
| 149 | <DataOutputs> |
---|
| 150 | [Result] |
---|
| 151 | Title = The resulting feature |
---|
| 152 | Abstract = The feature created by the service. |
---|
| 153 | <ComplexOutput> |
---|
| 154 | <Default> |
---|
| 155 | mimeType = application/json |
---|
| 156 | </Default> |
---|
| 157 | </ComplexOutput> |
---|
| 158 | </DataOutputs> |
---|
| 159 | |
---|
| 160 | Here you simply define one default ``ComplexData`` for both ``inputData`` and |
---|
| 161 | ``Result``: a GML and a GeoJSON respectively [#f6]_. |
---|
| 162 | |
---|
| 163 | The JavaScript service |
---|
| 164 | ---------------------- |
---|
| 165 | |
---|
| 166 | As you will have to request the Buffer service many times from your service, you |
---|
| 167 | will first define a ``Buffer`` function as follow. It uses the ``ZOO.Process`` |
---|
| 168 | to request the Buffer service you seen in the previous section. |
---|
| 169 | |
---|
| 170 | Open a file named |
---|
| 171 | ``~/zoo-ws-2012/src/zoo-project/zoo-services/ws2012js/cgi-env/foss4gws.js`` and |
---|
| 172 | add the following content: |
---|
| 173 | |
---|
| 174 | .. code-block:: javascript |
---|
| 175 | :linenos: |
---|
| 176 | |
---|
| 177 | var zoo_url='http://localhost/cgi-bin/zoo_loader.cgi'; |
---|
| 178 | var mapserv_url='http://localhost/cgi-bin/mapserv?'+ |
---|
| 179 | 'map=/var/www/zoows-demo/map/w2011.map&SERVICE=WFS'; |
---|
| 180 | |
---|
| 181 | function Buffer(inputData,bDist){ |
---|
| 182 | |
---|
| 183 | // Create all required ZOO.formats |
---|
| 184 | var fJ=new ZOO.Format.JSON(); |
---|
| 185 | var fGJ=new ZOO.Format.GeoJSON(); |
---|
| 186 | var fWPS=new ZOO.Format.WPS(); |
---|
| 187 | |
---|
| 188 | // Pass the value as json |
---|
| 189 | var myInputs = { |
---|
| 190 | InputPolygon: { type: 'complex', value: fGJ.write(inputData), mimeType: "application/json"}, |
---|
| 191 | BufferDistance: {type: 'float', "value": bDist } |
---|
| 192 | }; |
---|
| 193 | var myOutputs= { Result: { type: 'ResponseDocument', "mimeType": "application/json" } }; |
---|
| 194 | var myProcess = new ZOO.Process(zoo_url,'BufferPy'); |
---|
| 195 | var myExecuteResult=myProcess.Execute(myInputs,myOutputs); |
---|
| 196 | |
---|
| 197 | // Parse the result and extract JSON geometry |
---|
| 198 | var bufferResult=fWPS.read(myExecuteResult); |
---|
| 199 | var bufferResultAsGeoJSON=fJ.read(bufferResult.value); |
---|
| 200 | return fGJ.read(bufferResultAsGeoJSON); |
---|
| 201 | |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | From line 12 to 15, you give a GeoJSON string (created from ``inputData``) for |
---|
| 205 | InputPolygon and, on line 14, you set the BufferDistance value to ``bDist``. |
---|
| 206 | On line 16, you define Result as a ResponseDocument, so you'll have to parse the |
---|
| 207 | WPS response using the ZOO.Format.WPS, on line 21. |
---|
| 208 | |
---|
| 209 | On line 17, you create a |
---|
| 210 | `ZOO.Process <http://zoo-project.org/docs/api/zoo-process.html#zoo-process>`__ |
---|
| 211 | instance providing the ZOO-Kernel url and the Service name. Then, on line 18, you |
---|
| 212 | run the request passing inputs and outputs previously defined (from line 12 to 15). |
---|
| 213 | |
---|
| 214 | Now, you get your ``Buffer`` function, it is time to create your first JavaScript |
---|
| 215 | service. So, edit your ``foss4gws.js`` file you created before and add the following content: |
---|
| 216 | |
---|
| 217 | .. code-block:: javascript |
---|
| 218 | :linenos: |
---|
| 219 | |
---|
| 220 | function Mask(conf,inputs,outputs){ |
---|
| 221 | |
---|
| 222 | // Create all required ZOO.formats |
---|
| 223 | var fGML=new ZOO.Format.GML(); |
---|
| 224 | var fGJ=new ZOO.Format.GeoJSON(); |
---|
| 225 | |
---|
| 226 | // Read the input GML |
---|
| 227 | var inputData=fGML.read(inputs["InputData"]["value"]); |
---|
| 228 | |
---|
| 229 | // Compute Buffer |
---|
| 230 | var bufferResultAsJSON=Buffer(inputData,0.015); |
---|
| 231 | |
---|
| 232 | // Create the Buffer result BBOX and store its geometry in a ZOO.Feature |
---|
| 233 | var bbox = new ZOO.Bounds(); |
---|
| 234 | var bounds=bufferResultAsJSON[0].geometry.getVertices(); |
---|
| 235 | for(var t in bounds){ |
---|
| 236 | bbox.extend(bounds[t]); |
---|
| 237 | } |
---|
| 238 | var finalG=bbox.toGeometry(); |
---|
| 239 | var result=new ZOO.Feature(finalG,{"name": "Result1000"}); |
---|
| 240 | |
---|
| 241 | // Return the created feature |
---|
| 242 | return { |
---|
| 243 | result: ZOO.SERVICE_SUCCEEDED, |
---|
| 244 | outputs: { "Result": { mimeType: "application/json", value: fGJ.write(result) } } |
---|
| 245 | }; |
---|
| 246 | |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | Publish and use your Service |
---|
| 250 | ---------------------------- |
---|
| 251 | |
---|
| 252 | Now you get both your ZCFG and your service code ready, you need to deploy your |
---|
| 253 | new Services Provider using the following command: |
---|
| 254 | |
---|
| 255 | .. code-block:: bash |
---|
| 256 | |
---|
| 257 | cp ~/zoo-ws-2012/src/zoo-project/zoo-services/ws2012js/cgi-env/* /usr/lib/cgi-bin |
---|
| 258 | |
---|
| 259 | Now you are ready to use your JavaScript service by loading the the following `url |
---|
| 260 | <http://localhost/zoows-demo/spatialtools.html>`__, click on a street then click on |
---|
| 261 | the "Mask" button. |
---|
| 262 | |
---|
| 263 | BufferMask Service |
---|
| 264 | ================== |
---|
| 265 | |
---|
| 266 | In this section you will implement a simple JavaScript service which will be able create |
---|
| 267 | a hole in the mask you created in `previous section <#mask-service>`__. This service |
---|
| 268 | will be used to highlight the buffer zone around a selected fature. You get a preview of |
---|
| 269 | the expected result in the following screenshot: |
---|
| 270 | |
---|
| 271 | .. image:: ./images/BufferMask_Level_15.png |
---|
| 272 | :width: 650px |
---|
| 273 | :align: center |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | The ZCFG |
---|
| 277 | -------- |
---|
| 278 | |
---|
| 279 | Open the file named |
---|
| 280 | ``~/zoo-ws-2012/src/zoo-project/zoo-services/ws2012js/cgi-env/BufferMask.zcfg`` |
---|
| 281 | with your favorite text editor and copy / paste the following content: |
---|
| 282 | |
---|
| 283 | .. code-block:: none |
---|
| 284 | :linenos: |
---|
| 285 | |
---|
| 286 | [BufferMask] |
---|
| 287 | Title = Compute buffer mask |
---|
| 288 | Abstract = Compute buffer mask around a geometry |
---|
| 289 | processVersion = 1 |
---|
| 290 | storeSupported = true |
---|
| 291 | statusSupported = true |
---|
| 292 | serviceProvider = foss4gws.js |
---|
| 293 | serviceType = JS |
---|
| 294 | <DataInputs> |
---|
| 295 | [InputData] |
---|
| 296 | Title = The feature |
---|
| 297 | Abstract = The feature to run the service with |
---|
| 298 | minOccurs = 1 |
---|
| 299 | maxOccurs = 1 |
---|
| 300 | <ComplexData> |
---|
| 301 | <Default> |
---|
| 302 | mimeType = text/xml |
---|
| 303 | encoding = utf-8 |
---|
| 304 | </Default> |
---|
| 305 | </ComplexData> |
---|
| 306 | </DataInputs> |
---|
| 307 | <DataOutputs> |
---|
| 308 | [Result] |
---|
| 309 | Title = The resulting feature |
---|
| 310 | Abstract = The feature created by the service. |
---|
| 311 | <ComplexOutput> |
---|
| 312 | <Default> |
---|
| 313 | mimeType = application/json |
---|
| 314 | </Default> |
---|
| 315 | </ComplexOutput> |
---|
| 316 | </DataOutputs> |
---|
| 317 | |
---|
| 318 | This ZCFG is similar to the previous one. Please, refer to comments in the |
---|
| 319 | `previous section <#the-zcfg>`__ for more informations. |
---|
| 320 | |
---|
| 321 | The JavaScript service |
---|
| 322 | ---------------------- |
---|
| 323 | |
---|
| 324 | In this Service you will use same source code (until line 19) you used in the |
---|
| 325 | `previous section <#the-javascript-service>`__. Indeed, you should compute the Mask |
---|
| 326 | as you did before then compute Buffer for creating a hole in the mask (on line 22) to run |
---|
| 327 | the Difference service (from line 25 to 40). |
---|
| 328 | |
---|
| 329 | .. code-block:: guess |
---|
| 330 | :linenos: |
---|
| 331 | |
---|
| 332 | function BufferMask(conf,inputs,outputs){ |
---|
| 333 | |
---|
| 334 | // Create all required ZOO.formats |
---|
| 335 | var fGML=new ZOO.Format.GML(); |
---|
| 336 | var fGJ=new ZOO.Format.GeoJSON(); |
---|
| 337 | |
---|
| 338 | // Read the input GML |
---|
| 339 | var inputData=fGML.read(inputs["InputData"]["value"]); |
---|
| 340 | |
---|
| 341 | // Compute Buffer |
---|
| 342 | var bufferResultAsJSON=Buffer(inputData,0.015); |
---|
| 343 | |
---|
| 344 | // Create the Buffer result BBOX |
---|
| 345 | var bbox = new ZOO.Bounds(); |
---|
| 346 | var bounds=bufferResultAsJSON[0].geometry.getVertices(); |
---|
| 347 | for(var t in bounds){ |
---|
| 348 | bbox.extend(bounds[t]); |
---|
| 349 | } |
---|
| 350 | var finalG=bbox.toGeometry(); |
---|
| 351 | |
---|
| 352 | // Compute Buffer standard buffer |
---|
| 353 | var bufferResultAsJSON=Buffer(inputData,0.0015); |
---|
| 354 | |
---|
| 355 | // Request Difference service using Buffer result and features in the BBOX |
---|
| 356 | var result=new ZOO.Feature(finalG,{"name": "Result1000"}); |
---|
| 357 | var myProcess2 = new ZOO.Process(zoo_url,'DifferencePy'); |
---|
| 358 | var myInputs2 = { |
---|
| 359 | InputEntity1: { |
---|
| 360 | type: 'complex', |
---|
| 361 | value: fGJ.write(finalG), |
---|
| 362 | mimeType: "application/json" |
---|
| 363 | }, |
---|
| 364 | InputEntity2: { |
---|
| 365 | type: 'complex', |
---|
| 366 | value: fGJ.write(bufferResultAsJSON), |
---|
| 367 | mimeType: "application/json" |
---|
| 368 | } |
---|
| 369 | }; |
---|
| 370 | var myOutputs2= {Result: {type: 'RawDataOutput', mimeType: "application/json" } }; |
---|
| 371 | var myExecuteResult4=myProcess2.Execute(myInputs2,myOutputs2); |
---|
| 372 | |
---|
| 373 | // Return the bbox |
---|
| 374 | var result=new ZOO.Feature(finalG,{"name": "Result1000"}); |
---|
| 375 | return { |
---|
| 376 | result: ZOO.SERVICE_SUCCEEDED, |
---|
| 377 | outputs: { "Result": {mimeType: "application/json", value: myExecuteResult4 } } |
---|
| 378 | }; |
---|
| 379 | |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | Publish and use your Service |
---|
| 383 | ---------------------------- |
---|
| 384 | |
---|
| 385 | Now, you can publish your service as you did `before <#publish-your-service>`__. To |
---|
| 386 | use your service, please use the following `url |
---|
| 387 | <http://localhost/zoows-demo/spatialtools.html>`__. |
---|
| 388 | |
---|
| 389 | BufferRequest service |
---|
| 390 | ====================== |
---|
| 391 | |
---|
| 392 | In this section, you will create a new Service: ``BufferRequest`` which will request |
---|
| 393 | POIs included in the Buffer around a selected feature [#f7]_. You will use the ``poi`` |
---|
| 394 | layer served as WFS through your local mapserver installation. You can see in the |
---|
| 395 | following screenshot the expected result: |
---|
| 396 | |
---|
| 397 | .. image:: ./images/BufferRequest_Level_15.png |
---|
| 398 | :width: 650px |
---|
| 399 | :align: center |
---|
| 400 | |
---|
| 401 | The ZCFG |
---|
| 402 | -------- |
---|
| 403 | |
---|
| 404 | Open the file named |
---|
| 405 | ``~/zoo-ws-2012/zoo-project/zoo-services/ws2011js/cgi-env/BufferRequest.zcfg`` |
---|
| 406 | with your favorite text editor and copy / paste the following content: |
---|
| 407 | |
---|
| 408 | .. code-block:: none |
---|
| 409 | :linenos: |
---|
| 410 | |
---|
| 411 | [BufferRequest] |
---|
| 412 | Title = Compute buffer request |
---|
| 413 | Abstract = Compute buffer request around a geometry |
---|
| 414 | processVersion = 1 |
---|
| 415 | storeSupported = true |
---|
| 416 | statusSupported = true |
---|
| 417 | serviceProvider = foss4gws.js |
---|
| 418 | serviceType = JS |
---|
| 419 | <DataInputs> |
---|
| 420 | [InputData] |
---|
| 421 | Title = The feature |
---|
| 422 | Abstract = The feature to run the service with |
---|
| 423 | minOccurs = 1 |
---|
| 424 | maxOccurs = 1 |
---|
| 425 | <ComplexData> |
---|
| 426 | <Default> |
---|
| 427 | mimeType = text/xml |
---|
| 428 | encoding = utf-8 |
---|
| 429 | </Default> |
---|
| 430 | </ComplexData> |
---|
| 431 | </DataInputs> |
---|
| 432 | <DataOutputs> |
---|
| 433 | [Result] |
---|
| 434 | Title = The resulting feature |
---|
| 435 | Abstract = The feature created by the service. |
---|
| 436 | <ComplexOutput> |
---|
| 437 | <Default> |
---|
| 438 | mimeType = application/json |
---|
| 439 | </Default> |
---|
| 440 | </ComplexOutput> |
---|
| 441 | </DataOutputs> |
---|
| 442 | |
---|
| 443 | |
---|
| 444 | The JavaScript code |
---|
| 445 | ------------------- |
---|
| 446 | |
---|
| 447 | As in the previous Service, you will compute a buffer around the input feature. But then |
---|
| 448 | you will request POIs available in the Buffer extent using a WFS request to use them to |
---|
| 449 | run ``Intersection`` service using the initial Buffer. The WFS request is useful to limit |
---|
| 450 | the number of points to use when requesting the ``Intersection`` Service. |
---|
| 451 | |
---|
| 452 | .. code-block:: javascript |
---|
| 453 | :linenos: |
---|
| 454 | |
---|
| 455 | function BufferRequest(conf,inputs,outputs){ |
---|
| 456 | |
---|
| 457 | // Create all required ZOO.formats |
---|
| 458 | var fGJ=new ZOO.Format.GeoJSON(); |
---|
| 459 | var fGML=new ZOO.Format.GML(); |
---|
| 460 | |
---|
| 461 | // Read the input GML |
---|
| 462 | var inputData=fGML.read(inputs["InputData"]["value"]); |
---|
| 463 | |
---|
| 464 | // Compute Buffer |
---|
| 465 | var bufferResultAsJSON=Buffer(inputData,0.0015); |
---|
| 466 | |
---|
| 467 | // Create the Buffer result BBOX |
---|
| 468 | var bbox = new ZOO.Bounds(); |
---|
| 469 | var bounds=bufferResultAsJSON[0].geometry.getVertices(); |
---|
| 470 | for(var t in bounds){ |
---|
| 471 | bbox.extend(bounds[t]); |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | // Request Intersection service using Buffer result and WFS request using the |
---|
| 475 | // BBOX |
---|
| 476 | var myProcess2 = new ZOO.Process(zoo_url,'IntersectionPy'); |
---|
| 477 | var req="&version=1.0.0&request=GetFeature&typename=poi1"; |
---|
| 478 | req+="&SRS=EPSG:4326&BBOX="; |
---|
| 479 | var myInputs2 = { |
---|
| 480 | InputEntity1: { |
---|
| 481 | type: 'complex', |
---|
| 482 | value: fGJ.write(bufferResultAsJSON), |
---|
| 483 | mimeType: "application/json" |
---|
| 484 | }, |
---|
| 485 | InputEntity2: { |
---|
| 486 | type: 'complex', |
---|
| 487 | xlink: mapserv_url+req+bbox.left+","+bbox.bottom+","+bbox.right+","+bbox.top, |
---|
| 488 | mimeType: "text/xml" |
---|
| 489 | } |
---|
| 490 | }; |
---|
| 491 | var myOutputs2= {Result: { type: 'RawDataOutput', "mimeType": "application/json" } }; |
---|
| 492 | var myExecuteResult4=myProcess2.Execute(myInputs2,myOutputs2); |
---|
| 493 | |
---|
| 494 | return { |
---|
| 495 | result: ZOO.SERVICE_SUCCEEDED, |
---|
| 496 | outputs: {name:"Result", mimeType: "application/json", value: myExecuteResult4} |
---|
| 497 | }; |
---|
| 498 | |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | .. warning:: to take advantage of the ZOO-Kernel cache system, you directly use the WFS |
---|
| 502 | request as ``xlink:href`` rather than value for ``InputEntity2`` (from line 31 to 34) and use ``text/xml`` ``mimeType`` |
---|
| 503 | (on line 40). Indeed, the ZOO-API doesn't use the internal cache mechanisms. |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | Publish and use your Service |
---|
| 507 | ---------------------------- |
---|
| 508 | |
---|
| 509 | Now, you can publish your service as you did `before <#publish-your-service>`__. To |
---|
| 510 | use your service, please use the following `url |
---|
| 511 | <http://localhost/zoows-demo/spatialtools.html>`__. |
---|
| 512 | |
---|
| 513 | .. note:: You can click on "Buffer Request and Mask" to get the same result as presented |
---|
| 514 | in `the initial screenshot <#introduction>`__. |
---|
| 515 | |
---|
| 516 | Conclusion |
---|
| 517 | ========== |
---|
| 518 | |
---|
| 519 | After understanding how basic Geometric Operation Services works, here you built step by |
---|
| 520 | step new JavaScript services which reuse the previous ones and combine them in |
---|
| 521 | different ways. This was achieved using the ZOO-API, composed by C functions |
---|
| 522 | exposed by the ZOO-Kernel to the JavaScript services runtime environement and |
---|
| 523 | the JS files which can be optionally installed. |
---|
| 524 | |
---|
| 525 | .. rubric:: Footnotes |
---|
| 526 | |
---|
| 527 | .. [#f3] The ``ZOO.Process`` class uses ``JSRequest`` (cf. `ref |
---|
| 528 | <http://zoo-project.org/docs/api/zoo-format-wps.html>`__). You will get example |
---|
| 529 | of use `later <#the-javascript-service>`__. |
---|
| 530 | .. [#f4] So ``conf``, ``inputs`` and ``outputs`` are simple JavaScript objects, similar |
---|
| 531 | to the Python dictionaries used in the `previous section <ogr_base_vect_ops.html>`__. |
---|
| 532 | .. [#f5] Such as ``conf``, ``inputs`` and ``outputs``. |
---|
| 533 | .. [#f6] Using one of the available ``ZOO.formats`` you are also able to support various |
---|
| 534 | ``ComplexData`` for both input and output of the service. To simplify the |
---|
| 535 | presentation here, you will use only this default ones. |
---|
| 536 | .. [#f7] So in the hole you created in the previous section. |
---|