From c1fe2203a1889be1c6bc47aff5f41c197f7205b6 Mon Sep 17 00:00:00 2001 From: john gravois Date: Mon, 13 Jul 2015 18:54:24 -0700 Subject: [PATCH] building v1.0.1 --- dist/esri-leaflet-gp-src.js | 266 ++++++++++++++++++++++++++++++++++++ dist/esri-leaflet-gp.js | 10 ++ dist/esri-leaflet-gp.js.map | 1 + 3 files changed, 277 insertions(+) create mode 100644 dist/esri-leaflet-gp-src.js create mode 100644 dist/esri-leaflet-gp.js create mode 100644 dist/esri-leaflet-gp.js.map diff --git a/dist/esri-leaflet-gp-src.js b/dist/esri-leaflet-gp-src.js new file mode 100644 index 0000000..f7e01c0 --- /dev/null +++ b/dist/esri-leaflet-gp-src.js @@ -0,0 +1,266 @@ +/*! esri-leaflet-gp - v1.0.0 - 2015-07-13 +* Copyright (c) 2015 Environmental Systems Research Institute, Inc. +* Apache 2.0 License */ + +var EsriLeafletGP = { + Tasks: {}, + Services: {}, + Controls: {} +}; + +// attach to the L.esri global if we can +if(typeof window !== 'undefined' && window.L && window.L.esri) { + window.L.esri.GP = EsriLeafletGP; +} + +// We do not have an 'Esri' variable e.g loading this file directly from source define 'Esri' +if(!Esri){ + var Esri = window.L.esri; +} + +EsriLeafletGP.Services.Geoprocessing = Esri.Services.Service.extend({ + options: { + asyncInterval: 1 + }, + + createTask: function(){ + return new EsriLeafletGP.Tasks.Geoprocessing(this, this.options); + } +}); + +EsriLeafletGP.Services.geoprocessing = function(options) { + return new EsriLeafletGP.Services.Geoprocessing(options); +}; + +/* +to do: +setParam([]) +*/ + +EsriLeafletGP.Tasks.Geoprocessing = Esri.Tasks.Task.extend({ + + includes: L.Mixin.Events, + + //setters: {}, we don't use these because we don't know the ParamName OR value of custom GP services + params: {}, + resultParams: {}, + + initialize: function(options) { + //don't replace parent initialize + L.esri.Tasks.Task.prototype.initialize.call(this, options); + + //if path isn't supplied in options, try and determine if its sync or async to set automatically + if (!this.options.path) { + //assume initially, that service is synchronous + this.options.async = false; + this.options.path = 'execute'; + + //the parameters below seem wonky to me, but work for both CORS and JSONP requests + this._service.metadata(function(error, results) { + if (!error) { + if (results.executionType === 'esriExecutionTypeSynchronous') { + this.options.async = false; + this.options.path = 'execute'; + } else { + this.options.async = true; + this.options.path = 'submitJob'; + } + this.fire('initialized'); + } else { + //if check fails, hopefully its synchronous + this.options.async = false; + this.options.path = 'execute'; + return; + } + }, this); + } + else { + //if path is custom, hopefully its synchronous + if (this.options.async !== true && this.options.path !=='submitJob') { + this.options.async = false; + } + } + }, + + //doc for various GPInput types can be found here + //http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/GP_Result/02r3000000q7000000/ + + //set booleans, numbers, strings + setParam: function(paramName, paramValue) { + if (typeof paramValue === 'boolean') { + this.params[paramName] = paramValue; + return; + } + //strings, numbers + else if (typeof paramValue !== 'object') { + this.params[paramName] = paramValue; + return; + } + else { + //otherwise assume its latlng, marker, bounds or geojson + this._setGeometry(paramName, paramValue); + } + }, + + // not sure how best to handle passing more than one parameter at once + // setParams: function(inputArray) { + // if (L.Util.isArray(inputArray)) { + // for (var i = 0; i < inputArray.length; i++) { + // this.setParam(inputArray[i]); + // } + // } + // }, + + // give developer opportunity to point out where the output is going to be available + setOutputParam: function(paramName) { + this.params.outputParam = paramName; + }, + + /* necessary because of the design requirement that resultParams be specified + for async elevation services in order to get Zs (unnecessarily confusing)*/ + gpAsyncResultParam: function(paramName, paramValue) { + this.resultParams[paramName] = paramValue; + }, + + // we currently expect a single geometry or feature (ported from: Tasks.Query._setGeometry) + _setGeometry: function(paramName, geometry) { + var processedInput = { + 'geometryType': '', + 'features': [] + }; + + // convert bounds to extent and finish + if ( geometry instanceof L.LatLngBounds ) { + // set geometry + type + processedInput.features.push({'geometry': L.esri.Util.boundsToExtent(geometry)}); + processedInput.geometryType = L.esri.Util.geojsonTypeToArcGIS(geometry.type); + } + + // convert L.Marker > L.LatLng + if(geometry.getLatLng){ + geometry = geometry.getLatLng(); + } + + // convert L.LatLng to a geojson point and continue; + if (geometry instanceof L.LatLng) { + geometry = { + type: 'Point', + coordinates: [geometry.lng, geometry.lat] + }; + } + + // handle L.GeoJSON, pull out the first geometry + if ( geometry instanceof L.GeoJSON ) { + //reassign geometry to the GeoJSON value (we are assuming that only one feature is present) + geometry = geometry.getLayers()[0].feature.geometry; + processedInput.features.push({'geometry': L.esri.Util.geojsonToArcGIS(geometry)}); + processedInput.geometryType = L.esri.Util.geojsonTypeToArcGIS(geometry.type); + } + + // Handle L.Polyline and L.Polygon + if (geometry.toGeoJSON) { + geometry = geometry.toGeoJSON(); + } + + // handle GeoJSON feature by pulling out the geometry + if ( geometry.type === 'Feature' ) { + // get the geometry of the geojson feature + geometry = geometry.geometry; + } + + // confirm that our GeoJSON is a point, line or polygon + if ( geometry.type === 'Point' || geometry.type === 'LineString' || geometry.type === 'Polygon') { + processedInput.features.push({'geometry': L.esri.Util.geojsonToArcGIS(geometry)}); + processedInput.geometryType = L.esri.Util.geojsonTypeToArcGIS(geometry.type); + } + + else { + if(console && console.warn) { + console.warn('invalid geometry passed as GP input. Should be an L.LatLng, L.LatLngBounds, L.Marker or GeoJSON Point Line or Polygon object'); + } + } + + this.params[paramName] = processedInput; + return; + }, + + run: function(callback, context) { + this._done = false; + + if (this.options.async === true) { + this._service.request(this.options.path, this.params, function(error, response) { + this._currentJobId = response.jobId; + this.checkJob(this._currentJobId, callback, context); + }, this); + } else { + return this._service.request(this.options.path, this.params, function(error, response) { + callback.call(context, error, (response && this.processGPOutput(response)), response); + }, this); + } + }, + + checkJob: function(jobId, callback, context) { + var pollJob = function() { + this._service.request('jobs/' + jobId, {}, function polledJob(error, response) { + if (response.jobStatus === 'esriJobSucceeded') { + if (!this._done){ + this._done = true; + this._service.request('jobs/' + jobId + '/results/' + this.params.outputParam, this.resultParams, function processJobResult(error, response) { + callback.call(context, error, (response && this.processGPOutput(response)), response); + }, this); + } + window.clearInterval(counter); + } else if (response.jobStatus === 'esriJobFailed') { + callback.call(context, 'Job Failed', null); + window.clearInterval(counter); + } + }, this); + }.bind(this); + + var counter = window.setInterval(pollJob, this._service.options.asyncInterval*1000); + + }, + + processGPOutput: function(response) { + var processedResponse = {}; + var responseValue; + + // grab syncronous results + if (this.options.async === false) { + responseValue = response.results[0].value; + } + + //grab async results slightly differently + else { + processedResponse.jobId = this._currentJobId; + responseValue = response.value; + } + + // if output is a raster layer, we also need to stub out a MapService url using jobid + if (this.options.async === true && response.dataType === 'GPRasterDataLayer') { + var baseURL = this.options.url; + var n = baseURL.indexOf('GPServer'); + var serviceURL = baseURL.slice(0,n)+'MapServer/'; + processedResponse.outputMapService = serviceURL+'jobs/'+this._currentJobId; + } + + // if output is GPFeatureRecordSetLayer, convert to GeoJSON + if (responseValue.features) { + var featureCollection = L.esri.Util.responseToFeatureCollection(responseValue); + processedResponse.features = featureCollection.features; + } + + // if the output is a file, pass it along 'as is' + if (response.dataType === 'GPDataFile') { + processedResponse.outputFile = response.results[0]; + } + + //do we need to be able to pass back output booleans? strings? numbers? + return processedResponse; + } + +}); + +EsriLeafletGP.Tasks.geoprocessing = function(params) { + return new EsriLeafletGP.Tasks.Geoprocessing(params); +}; diff --git a/dist/esri-leaflet-gp.js b/dist/esri-leaflet-gp.js new file mode 100644 index 0000000..0e882b1 --- /dev/null +++ b/dist/esri-leaflet-gp.js @@ -0,0 +1,10 @@ +/*! esri-leaflet-gp - v1.0.0 - 2015-07-13 +* Copyright (c) 2015 Environmental Systems Research Institute, Inc. +* Apache 2.0 License */ + + +/*! esri-leaflet-gp - v1.0.0 - 2015-07-13 +* Copyright (c) 2015 Environmental Systems Research Institute, Inc. +* Apache 2.0 License */ +var EsriLeafletGP={Tasks:{},Services:{},Controls:{}};if("undefined"!=typeof window&&window.L&&window.L.esri&&(window.L.esri.GP=EsriLeafletGP),!Esri)var Esri=window.L.esri;EsriLeafletGP.Services.Geoprocessing=Esri.Services.Service.extend({options:{asyncInterval:1},createTask:function(){return new EsriLeafletGP.Tasks.Geoprocessing(this,this.options)}}),EsriLeafletGP.Services.geoprocessing=function(a){return new EsriLeafletGP.Services.Geoprocessing(a)},EsriLeafletGP.Tasks.Geoprocessing=Esri.Tasks.Task.extend({includes:L.Mixin.Events,params:{},resultParams:{},initialize:function(a){L.esri.Tasks.Task.prototype.initialize.call(this,a),this.options.path?this.options.async!==!0&&"submitJob"!==this.options.path&&(this.options.async=!1):(this.options.async=!1,this.options.path="execute",this._service.metadata(function(a,b){return a?(this.options.async=!1,void(this.options.path="execute")):("esriExecutionTypeSynchronous"===b.executionType?(this.options.async=!1,this.options.path="execute"):(this.options.async=!0,this.options.path="submitJob"),void this.fire("initialized"))},this))},setParam:function(a,b){return"boolean"==typeof b?void(this.params[a]=b):"object"!=typeof b?void(this.params[a]=b):void this._setGeometry(a,b)},setOutputParam:function(a){this.params.outputParam=a},gpAsyncResultParam:function(a,b){this.resultParams[a]=b},_setGeometry:function(a,b){var c={geometryType:"",features:[]};b instanceof L.LatLngBounds&&(c.features.push({geometry:L.esri.Util.boundsToExtent(b)}),c.geometryType=L.esri.Util.geojsonTypeToArcGIS(b.type)),b.getLatLng&&(b=b.getLatLng()),b instanceof L.LatLng&&(b={type:"Point",coordinates:[b.lng,b.lat]}),b instanceof L.GeoJSON&&(b=b.getLayers()[0].feature.geometry,c.features.push({geometry:L.esri.Util.geojsonToArcGIS(b)}),c.geometryType=L.esri.Util.geojsonTypeToArcGIS(b.type)),b.toGeoJSON&&(b=b.toGeoJSON()),"Feature"===b.type&&(b=b.geometry),"Point"===b.type||"LineString"===b.type||"Polygon"===b.type?(c.features.push({geometry:L.esri.Util.geojsonToArcGIS(b)}),c.geometryType=L.esri.Util.geojsonTypeToArcGIS(b.type)):console&&console.warn&&console.warn("invalid geometry passed as GP input. Should be an L.LatLng, L.LatLngBounds, L.Marker or GeoJSON Point Line or Polygon object"),this.params[a]=c},run:function(a,b){return this._done=!1,this.options.async!==!0?this._service.request(this.options.path,this.params,function(c,d){a.call(b,c,d&&this.processGPOutput(d),d)},this):void this._service.request(this.options.path,this.params,function(c,d){this._currentJobId=d.jobId,this.checkJob(this._currentJobId,a,b)},this)},checkJob:function(a,b,c){var d=function(){this._service.request("jobs/"+a,{},function(d,f){"esriJobSucceeded"===f.jobStatus?(this._done||(this._done=!0,this._service.request("jobs/"+a+"/results/"+this.params.outputParam,this.resultParams,function(a,d){b.call(c,a,d&&this.processGPOutput(d),d)},this)),window.clearInterval(e)):"esriJobFailed"===f.jobStatus&&(b.call(c,"Job Failed",null),window.clearInterval(e))},this)}.bind(this),e=window.setInterval(d,1e3*this._service.options.asyncInterval)},processGPOutput:function(a){var b,c={};if(this.options.async===!1?b=a.results[0].value:(c.jobId=this._currentJobId,b=a.value),this.options.async===!0&&"GPRasterDataLayer"===a.dataType){var d=this.options.url,e=d.indexOf("GPServer"),f=d.slice(0,e)+"MapServer/";c.outputMapService=f+"jobs/"+this._currentJobId}if(b.features){var g=L.esri.Util.responseToFeatureCollection(b);c.features=g.features}return"GPDataFile"===a.dataType&&(c.outputFile=a.results[0]),c}}),EsriLeafletGP.Tasks.geoprocessing=function(a){return new EsriLeafletGP.Tasks.Geoprocessing(a)}; +//# sourceMappingURL=esri-leaflet-gp.js.map \ No newline at end of file diff --git a/dist/esri-leaflet-gp.js.map b/dist/esri-leaflet-gp.js.map new file mode 100644 index 0000000..c308b99 --- /dev/null +++ b/dist/esri-leaflet-gp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"esri-leaflet-gp.js","sources":["esri-leaflet-gp-src.js"],"names":["EsriLeafletGP","Tasks","Services","Controls","window","L","esri","GP","Esri","Geoprocessing","Service","extend","options","asyncInterval","createTask","this","geoprocessing","Task","includes","Mixin","Events","params","resultParams","initialize","prototype","call","path","async","_service","metadata","error","results","executionType","fire","setParam","paramName","paramValue","_setGeometry","setOutputParam","outputParam","gpAsyncResultParam","geometry","processedInput","geometryType","features","LatLngBounds","push","Util","boundsToExtent","geojsonTypeToArcGIS","type","getLatLng","LatLng","coordinates","lng","lat","GeoJSON","getLayers","feature","geojsonToArcGIS","toGeoJSON","console","warn","run","callback","context","_done","request","response","processGPOutput","_currentJobId","jobId","checkJob","pollJob","jobStatus","clearInterval","counter","bind","setInterval","responseValue","processedResponse","value","dataType","baseURL","url","n","indexOf","serviceURL","slice","outputMapService","featureCollection","responseToFeatureCollection","outputFile"],"mappings":";;;;;;;;AAIA,GAAIA,gBACFC,SACAC,YACAC,YASF,IALqB,mBAAXC,SAA0BA,OAAOC,GAAKD,OAAOC,EAAEC,OACvDF,OAAOC,EAAEC,KAAKC,GAAKP,gBAIjBQ,KACF,GAAIA,MAAOJ,OAAOC,EAAEC,IAGtBN,eAAcE,SAASO,cAAgBD,KAAKN,SAASQ,QAAQC,QAC3DC,SACEC,cAAe,GAGjBC,WAAY,WACV,MAAO,IAAId,eAAcC,MAAMQ,cAAcM,KAAMA,KAAKH,YAI5DZ,cAAcE,SAASc,cAAgB,SAASJ,GAC9C,MAAO,IAAIZ,eAAcE,SAASO,cAAcG,IAQlDZ,cAAcC,MAAMQ,cAAgBD,KAAKP,MAAMgB,KAAKN,QAElDO,SAAUb,EAAEc,MAAMC,OAGlBC,UACAC,gBAEAC,WAAY,SAASX,GAEnBP,EAAEC,KAAKL,MAAMgB,KAAKO,UAAUD,WAAWE,KAAKV,KAAMH,GAG7CG,KAAKH,QAAQc,KA0BZX,KAAKH,QAAQe,SAAU,GAA6B,cAArBZ,KAAKH,QAAQc,OAC9CX,KAAKH,QAAQe,OAAQ,IAzBvBZ,KAAKH,QAAQe,OAAQ,EACrBZ,KAAKH,QAAQc,KAAO,UAGpBX,KAAKa,SAASC,SAAS,SAASC,EAAOC,GACrC,MAAKD,IAWHf,KAAKH,QAAQe,OAAQ,OACrBZ,KAAKH,QAAQc,KAAO,aAXU,iCAA1BK,EAAQC,eACVjB,KAAKH,QAAQe,OAAQ,EACrBZ,KAAKH,QAAQc,KAAO,YAEpBX,KAAKH,QAAQe,OAAQ,EACrBZ,KAAKH,QAAQc,KAAO,iBAEtBX,MAAKkB,KAAK,iBAOXlB,QAcPmB,SA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CL,GAAkBS,iBAAmBF,EAAW,QAAQxE,KAAKuD,cAI5D,GAAIS,EAAcnC,SAAU,CAC3B,GAAI8C,GAAoBrF,EAAEC,KAAKyC,KAAK4C,4BAA4BZ,EAChEC,GAAkBpC,SAAW8C,EAAkB9C,SAS/C,MALuB,eAAtBwB,EAASc,WACZF,EAAkBY,WAAaxB,EAASrC,QAAQ,IAIvCiD,KAKXhF,cAAcC,MAAMe,cAAgB,SAASK,GAC3C,MAAO,IAAIrB,eAAcC,MAAMQ,cAAcY","sourcesContent":["/*! esri-leaflet-gp - v1.0.0 - 2015-07-13\n* Copyright (c) 2015 Environmental Systems Research Institute, Inc.\n* Apache 2.0 License */\n\nvar EsriLeafletGP = {\n Tasks: {},\n Services: {},\n Controls: {}\n};\n\n// attach to the L.esri global if we can\nif(typeof window !== 'undefined' && window.L && window.L.esri) {\n window.L.esri.GP = EsriLeafletGP;\n}\n\n// We do not have an 'Esri' variable e.g loading this file directly from source define 'Esri'\nif(!Esri){\n var Esri = window.L.esri;\n}\n\nEsriLeafletGP.Services.Geoprocessing = Esri.Services.Service.extend({\n options: {\n asyncInterval: 1\n },\n\n createTask: function(){\n return new EsriLeafletGP.Tasks.Geoprocessing(this, this.options);\n }\n});\n\nEsriLeafletGP.Services.geoprocessing = function(options) {\n return new EsriLeafletGP.Services.Geoprocessing(options);\n};\n\n/*\nto do:\nsetParam([])\n*/\n\nEsriLeafletGP.Tasks.Geoprocessing = Esri.Tasks.Task.extend({\n\n includes: L.Mixin.Events,\n\n //setters: {}, we don't use these because we don't know the ParamName OR value of custom GP services\n params: {},\n resultParams: {},\n\n initialize: function(options) {\n //don't replace parent initialize\n L.esri.Tasks.Task.prototype.initialize.call(this, options);\n\n //if path isn't supplied in options, try and determine if its sync or async to set automatically\n if (!this.options.path) {\n //assume initially, that service is synchronous\n this.options.async = false;\n this.options.path = 'execute';\n\n //the parameters below seem wonky to me, but work for both CORS and JSONP requests\n this._service.metadata(function(error, results) {\n if (!error) {\n if (results.executionType === 'esriExecutionTypeSynchronous') {\n this.options.async = false;\n this.options.path = 'execute';\n } else {\n this.options.async = true;\n this.options.path = 'submitJob';\n }\n this.fire('initialized');\n } else {\n //if check fails, hopefully its synchronous\n this.options.async = false;\n this.options.path = 'execute';\n return;\n }\n }, this);\n }\n else {\n //if path is custom, hopefully its synchronous\n if (this.options.async !== true && this.options.path !=='submitJob') {\n this.options.async = false;\n }\n }\n },\n\n //doc for various GPInput types can be found here\n //http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/GP_Result/02r3000000q7000000/\n\n //set booleans, numbers, strings\n setParam: function(paramName, paramValue) {\n if (typeof paramValue === 'boolean') {\n this.params[paramName] = paramValue;\n return;\n }\n //strings, numbers\n else if (typeof paramValue !== 'object') {\n this.params[paramName] = paramValue;\n return;\n }\n else {\n //otherwise assume its latlng, marker, bounds or geojson\n this._setGeometry(paramName, paramValue);\n }\n },\n\n // not sure how best to handle passing more than one parameter at once\n // setParams: function(inputArray) {\n // if (L.Util.isArray(inputArray)) {\n // for (var i = 0; i < inputArray.length; i++) {\n // this.setParam(inputArray[i]);\n // }\n // }\n // },\n\n // give developer opportunity to point out where the output is going to be available\n setOutputParam: function(paramName) {\n this.params.outputParam = paramName;\n },\n\n /* necessary because of the design requirement that resultParams be specified\n for async elevation services in order to get Zs (unnecessarily confusing)*/\n gpAsyncResultParam: function(paramName, paramValue) {\n this.resultParams[paramName] = paramValue;\n },\n\n // we currently expect a single geometry or feature (ported from: Tasks.Query._setGeometry)\n _setGeometry: function(paramName, geometry) {\n var processedInput = {\n 'geometryType': '',\n 'features': []\n };\n\n // convert bounds to extent and finish\n if ( geometry instanceof L.LatLngBounds ) {\n // set geometry + type\n processedInput.features.push({'geometry': L.esri.Util.boundsToExtent(geometry)});\n processedInput.geometryType = L.esri.Util.geojsonTypeToArcGIS(geometry.type);\n }\n\n // convert L.Marker > L.LatLng\n if(geometry.getLatLng){\n geometry = geometry.getLatLng();\n }\n\n // convert L.LatLng to a geojson point and continue;\n if (geometry instanceof L.LatLng) {\n geometry = {\n type: 'Point',\n coordinates: [geometry.lng, geometry.lat]\n };\n }\n\n // handle L.GeoJSON, pull out the first geometry\n if ( geometry instanceof L.GeoJSON ) {\n //reassign geometry to the GeoJSON value (we are assuming that only one feature is present)\n geometry = geometry.getLayers()[0].feature.geometry;\n processedInput.features.push({'geometry': L.esri.Util.geojsonToArcGIS(geometry)});\n processedInput.geometryType = L.esri.Util.geojsonTypeToArcGIS(geometry.type);\n }\n\n // Handle L.Polyline and L.Polygon\n if (geometry.toGeoJSON) {\n geometry = geometry.toGeoJSON();\n }\n\n // handle GeoJSON feature by pulling out the geometry\n if ( geometry.type === 'Feature' ) {\n // get the geometry of the geojson feature\n geometry = geometry.geometry;\n }\n\n // confirm that our GeoJSON is a point, line or polygon\n if ( geometry.type === 'Point' || geometry.type === 'LineString' || geometry.type === 'Polygon') {\n processedInput.features.push({'geometry': L.esri.Util.geojsonToArcGIS(geometry)});\n processedInput.geometryType = L.esri.Util.geojsonTypeToArcGIS(geometry.type);\n }\n\n else {\n if(console && console.warn) {\n console.warn('invalid geometry passed as GP input. Should be an L.LatLng, L.LatLngBounds, L.Marker or GeoJSON Point Line or Polygon object');\n }\n }\n\n this.params[paramName] = processedInput;\n return;\n },\n\n run: function(callback, context) {\n this._done = false;\n\n if (this.options.async === true) {\n this._service.request(this.options.path, this.params, function(error, response) {\n this._currentJobId = response.jobId;\n this.checkJob(this._currentJobId, callback, context);\n }, this);\n } else {\n return this._service.request(this.options.path, this.params, function(error, response) {\n callback.call(context, error, (response && this.processGPOutput(response)), response);\n }, this);\n }\n },\n\n checkJob: function(jobId, callback, context) {\n var pollJob = function() {\n this._service.request('jobs/' + jobId, {}, function polledJob(error, response) {\n if (response.jobStatus === 'esriJobSucceeded') {\n if (!this._done){\n this._done = true;\n this._service.request('jobs/' + jobId + '/results/' + this.params.outputParam, this.resultParams, function processJobResult(error, response) {\n callback.call(context, error, (response && this.processGPOutput(response)), response);\n }, this);\n }\n window.clearInterval(counter);\n } else if (response.jobStatus === 'esriJobFailed') {\n callback.call(context, 'Job Failed', null);\n window.clearInterval(counter);\n }\n }, this);\n }.bind(this);\n\n var counter = window.setInterval(pollJob, this._service.options.asyncInterval*1000);\n\n },\n\n processGPOutput: function(response) {\n var processedResponse = {};\n var responseValue;\n\n\t// grab syncronous results\n\tif (this.options.async === false) {\n\t\tresponseValue = response.results[0].value;\n\t}\n\n\t//grab async results slightly differently\n\telse {\n\t\tprocessedResponse.jobId = this._currentJobId;\n\t responseValue = response.value;\n\t}\n\n\t// if output is a raster layer, we also need to stub out a MapService url using jobid\n\tif (this.options.async === true && response.dataType === 'GPRasterDataLayer') {\n\t\tvar baseURL = this.options.url;\n\t\tvar n = baseURL.indexOf('GPServer');\n\t\tvar serviceURL = baseURL.slice(0,n)+'MapServer/';\n\t\tprocessedResponse.outputMapService = serviceURL+'jobs/'+this._currentJobId;\n\t}\n\n\t// if output is GPFeatureRecordSetLayer, convert to GeoJSON\n \tif (responseValue.features) {\n \t\tvar featureCollection = L.esri.Util.responseToFeatureCollection(responseValue);\n \t\tprocessedResponse.features = featureCollection.features;\n \t}\n\n\t// if the output is a file, pass it along 'as is'\n\tif (response.dataType === 'GPDataFile') {\n\t\tprocessedResponse.outputFile = response.results[0];\n\t}\n\n //do we need to be able to pass back output booleans? strings? numbers?\n return processedResponse;\n }\n\n});\n\nEsriLeafletGP.Tasks.geoprocessing = function(params) {\n return new EsriLeafletGP.Tasks.Geoprocessing(params);\n};\n"]} \ No newline at end of file