[140] | 1 | .. _api-examples: |
---|
| 2 | |
---|
| 3 | Examples |
---|
| 4 | ======== |
---|
| 5 | |
---|
| 6 | In this page you can find some small examples on how to use the JavaScript ZOO-API |
---|
| 7 | on the server side. |
---|
| 8 | |
---|
| 9 | ZOO-API contains many classes and functions. You can find the description list here. |
---|
| 10 | |
---|
| 11 | ZOO.Process example of use |
---|
| 12 | -------------------------- |
---|
| 13 | |
---|
| 14 | :: |
---|
| 15 | |
---|
| 16 | function SampleService(conf,inputs,outputs){ |
---|
| 17 | var myProcess = new ZOO.Process('http://localhost/cgi-bin-new1/zoo_loader_new1.cgi','Boundary'); |
---|
| 18 | var myInputs = {InputPolygon: { type: 'complex', value: '{"type":"Polygon","coordinates":[[[-106.993853,35.998758],[-107.407233,35.997524],[-107.430525,35.997726],[-107.4824,35.99878],[-108.37013,35.999472],[-109.043633,35.996652],[-109.096265,35.997817],[-109.148763,36.001751],[-109.200981,36.008442],[-109.252775,36.017871],[-109.304,36.030014],[-109.354516,36.044835],[-106.468201,35.991497],[-106.855511,35.989504],[-106.90933,35.990676],[-106.963008,35.994743],[-106.993853,35.998758]]]}', mimeType: "application/json"} }; |
---|
| 19 | var myExecuteResult=myProcess.Execute(myInputs); |
---|
| 20 | return {result: ZOO.SERVICE_SUCCEEDED, outputs: [ {name:"Result", value: myExecuteResult} ] }; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | In this really short example you can see how to create ZOO.Process class instance and |
---|
| 24 | call the Execute method on such an instance. Then you'll just need to return a JavaScript |
---|
| 25 | object containing the attributes result and outputs, which I'm sure you already know |
---|
| 26 | what is about. The first is about the status of the process (can be ZOO.SERVICE_ |
---|
| 27 | SUCEEDED,ZOO.SERVICE_FAILED ad so on), the last is obviously the resulting maps (take a |
---|
| 28 | look at the maps internal data structure used by ZOO Kernel in service.h). |
---|
| 29 | |
---|
| 30 | ZOO.UpdateStatus |
---|
| 31 | ---------------- |
---|
| 32 | |
---|
| 33 | :: |
---|
| 34 | |
---|
| 35 | function SampleLongService(conf,inputs,outputs){ |
---|
| 36 | var my_i=0; |
---|
| 37 | while(my_i<100){ |
---|
| 38 | try{ |
---|
| 39 | conf["lenv"]["status"]=my_i; |
---|
| 40 | } |
---|
| 41 | catch(e){ |
---|
| 42 | } |
---|
| 43 | ZOOUpdateStatus(conf,my_i); |
---|
| 44 | SampleService(conf,inputs,outputs); |
---|
| 45 | my_i+=10; |
---|
| 46 | } |
---|
| 47 | return SampleService(conf,inputs,outputs); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | You can see in this sample code how to use the ZOOUpdateStatus function to update the |
---|
| 51 | current status of your running process. This information will be really helpfull when the |
---|
| 52 | ZOO Kernel will run your JavaScript Service in background mode (if the user set to true |
---|
| 53 | the storeExecuteResponse parameter in his request). |
---|
| 54 | |
---|