diff --git a/dist/esri-leaflet-gp.js b/dist/esri-leaflet-gp.js new file mode 100644 index 0000000..8220ef6 --- /dev/null +++ b/dist/esri-leaflet-gp.js @@ -0,0 +1,5 @@ +/* esri-leaflet-gp - v2.0.0 - Mon Sep 14 2015 12:02:08 GMT-0700 (PDT) + * Copyright (c) 2015 Environmental Systems Research Institute, Inc. + * Apache-2.0 */ +(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports,require("esri-leaflet"),require("leaflet")):typeof define==="function"&&define.amd?define(["exports","esri-leaflet","leaflet"],factory):factory(global.L.esri.GP={},L.esri,L)})(this,function(exports,esri_leaflet,L){"use strict";exports.Task=esri_leaflet.Task.extend({includes:L.Mixin.Events,params:{},resultParams:{},initialize:function(options){esri_leaflet.Task.prototype.initialize.call(this,options);if(!this.options.path){this.options.async=false;this.options.path="execute";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{this.options.async=false;this.options.path="execute";return}},this)}else{if(this.options.async!==true&&this.options.path!=="submitJob"){this.options.async=false}}},setParam:function(paramName,paramValue){if(typeof paramValue==="boolean"){this.params[paramName]=paramValue;return}else if(typeof paramValue!=="object"){this.params[paramName]=paramValue;return}else{this._setGeometry(paramName,paramValue)}},setOutputParam:function(paramName){this.params.outputParam=paramName},gpAsyncResultParam:function(paramName,paramValue){this.resultParams[paramName]=paramValue},_setGeometry:function(paramName,geometry){var processedInput={geometryType:"",features:[]};if(geometry instanceof L.LatLngBounds){processedInput.features.push({geometry:L.esri.Util.boundsToExtent(geometry)});processedInput.geometryType=L.esri.Util.geojsonTypeToArcGIS(geometry.type)}if(geometry.getLatLng){geometry=geometry.getLatLng()}if(geometry instanceof L.LatLng){geometry={type:"Point",coordinates:[geometry.lng,geometry.lat]}}if(geometry instanceof L.GeoJSON){geometry=geometry.getLayers()[0].feature.geometry;processedInput.features.push({geometry:esri_leaflet.Util.geojsonToArcGIS(geometry)});processedInput.geometryType=esri_leaflet.Util.geojsonTypeToArcGIS(geometry.type)}if(geometry.toGeoJSON){geometry=geometry.toGeoJSON()}if(geometry.type==="Feature"){geometry=geometry.geometry}if(geometry.type==="Point"||geometry.type==="LineString"||geometry.type==="Polygon"){processedInput.features.push({geometry:esri_leaflet.Util.geojsonToArcGIS(geometry)});processedInput.geometryType=esri_leaflet.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.processAsyncOutput(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*1e3)},processGPOutput:function(response){var processedResponse={};if(this.options.async===false){for(var i=0;i 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': Util.geojsonToArcGIS(geometry)});\n processedInput.geometryType = 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': Util.geojsonToArcGIS(geometry)});\n processedInput.geometryType = Util.geojsonTypeToArcGIS(geometry.type);\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 /* eslint-disable */\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 /* eslint-enable */\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 /* eslint-disable */\n this._service.request('jobs/' + jobId, {}, function polledJob (error, response) {\n if (response.jobStatus === 'esriJobSucceeded') {\n if (!this._done) {\n this._done = true;\n // to do:\n // refactor to make an array of async requests for output\n this._service.request('jobs/' + jobId + '/results/' + this.params.outputParam, this.resultParams, function processJobResult (error, response) {\n callback.call(context, error, (response && this.processAsyncOutput(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 /* eslint-enable */\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\n // grab syncronous results\n if (this.options.async === false) {\n // loop through results and pass back, parsing esri json\n for (var i = 0; i < response.results.length; i++) {\n /* jshint ignore:start */\n processedResponse[response.results[i].paramName];\n /* jshint ignore:end */\n if (response.results[i].dataType === 'GPFeatureRecordSetLayer') {\n var featureCollection = Util.responseToFeatureCollection(response.results[i].value);\n processedResponse[response.results[i].paramName] = featureCollection;\n } else {\n processedResponse[response.results[i].paramName] = response.results[i].value;\n }\n }\n } else { // grab async results slightly differently\n processedResponse.jobId = this._currentJobId;\n // var responseValue = response.value;\n }\n\n // if output is a raster layer, we also need to stub out a MapService url using jobid\n if (this.options.async === true && response.dataType === 'GPRasterDataLayer') {\n var baseURL = this.options.url;\n var n = baseURL.indexOf('GPServer');\n var serviceURL = baseURL.slice(0, n) + 'MapServer/';\n processedResponse.outputMapService = serviceURL + 'jobs/' + this._currentJobId;\n }\n\n return processedResponse;\n },\n\n processAsyncOutput: function (response) {\n var processedResponse = {};\n processedResponse.jobId = this._currentJobId;\n\n // if output is a raster layer, we also need to stub out a MapService url using jobid\n if (this.options.async === true && response.dataType === 'GPRasterDataLayer') {\n var baseURL = this.options.url;\n var n = baseURL.indexOf('GPServer');\n var serviceURL = baseURL.slice(0, n) + 'MapServer/';\n processedResponse.outputMapService = serviceURL + 'jobs/' + this._currentJobId;\n }\n\n // if output is GPFeatureRecordSetLayer, convert to GeoJSON\n if (response.dataType === 'GPFeatureRecordSetLayer') {\n var featureCollection = Util.responseToFeatureCollection(response.value);\n processedResponse[response.paramName] = featureCollection;\n } else {\n processedResponse[response.paramName] = response.value;\n }\n\n return processedResponse;\n }\n\n});\n\nexport function task (options) {\n return new Task(options);\n}\n\nexport default task;\n","import { Service as BaseService } from 'esri-leaflet';\nimport { Task } from '../Tasks/Geoprocessing';\n\nexport var Service = BaseService.extend({\n options: {\n asyncInterval: 1\n },\n\n createTask: function () {\n return new Task(this, this.options);\n }\n\n});\n\nexport function service (options) {\n return new Service(options);\n}\n\nexport default service;\n","export var VERSION = '2.0.0';\n\nexport { Task, task } from './Tasks/Geoprocessing.js';\nexport { Service , service } from './Services/Geoprocessing.js';"]} \ No newline at end of file