这里只是自己发布的buffer point地理处理服务http://localhost:8399/rest/services/buffer/GPServer/BufferPoints,具体的实现代码参照官网的demo,只是换了几行代码,实现的小例子,关键是弄清楚过程。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>ArcGIS Geoprocessing and ArcGIS Server JavaScript API</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css" />
<script type="text/javascript">
djConfig = {
parseOnLoad:true
}
</script>
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
</style>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2"></script>
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.gp");
dojo.require("esri.toolbars.draw");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
var map, gp, toolbar;
function init() {
var initExtent = new esri.geometry.Extent({"xmin":-12689769,"ymin":-1937220,"xmax":2964533,"ymax":9725235,"spatialReference":{"wkid":102100}});
map = new esri.Map("map",{extent:initExtent});
var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
map.addLayer(streetMap);
//setup the geoprocessor teask
gp = new esri.tasks.Geoprocessor("http://localhost:8399/rest/services/buffer/GPServer/Buffer Points");
gp.setOutSpatialReference({wkid:102100});
toolbar = new esri.toolbars.Draw(map);
dojo.connect(toolbar, "onDrawEnd", executeParticleTrack);
//resize the map when the browser resizes - view the 'Resizing and repositioning the map' section in
//the following help topic for more details http://help.esri.com/EN/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/inside_guidelines.htm
var resizeTimer;
dojo.connect(map, 'onLoad', function(theMap) {
//resize the map when the browser resizes
dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
});
}
function executeParticleTrack(geometry) {
map.graphics.clear();
var graphic = new esri.Graphic(geometry);
map.graphics.add(graphic);
toolbar.deactivate();
var features= [];
features.push(graphic);
var featureSet = new esri.tasks.FeatureSet();
featureSet.features = features;
//客户端输入参数
var vsDistance = new esri.tasks.LinearUnit();
vsDistance.distance = dojo.byId("distance").value;
vsDistance.units = "esriMiles";
var params = { "Input_Points":featureSet, "Distance": vsDistance };
gp.execute(params, displayTrack);
}
function displayTrack(results, messages) {
//客户端渲染
var polySymbol = new esri.symbol.SimpleFillSymbol();
polySymbol.setOutline(new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,0,0.5]), 1));
polySymbol.setColor(new dojo.Color([255,127,0,0.7]));
var features = results[0].value.features;
for (var f=0, fl=features.length; f<fl; f++) {
var feature = features[f];
feature.setSymbol(polySymbol);
map.graphics.add(feature);
}
}
dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
<div dojotype="dijit.layout.BorderContainer" design="sidebar" style="width:100%;height:100%;margin:0px;" gutters="true">
<div dojotype="dijit.layout.ContentPane" region="left" style="width:300px;">
<ol>
<li>Enter the number of days to track:<input type="text" id="distance"
value="5" size="3"/></li>
<li>Click the <button οnclick="toolbar.activate(esri.toolbars.Draw.POINT);"> Execute</button> button. </li>
<li>Click the map to specify the start point.</li>
</ol>
* Note that the start season is spring.
</div>
<div dojotype="dijit.layout.ContentPane" id="map" region="center"></div>
</div>
</body>
</html>