ArcGIS API For JavaScript(四)调用GP服务--简单缓冲区分析
DOCTYPE html>
lang="en">
charset="UTF-8">
rel="stylesheet"href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/tundra/tundra.css"/>
rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css" />
#mapDiv {
height: 600px;
width: 900px;
border:1px solid red;
}
require(["esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"dojo/dom",
"esri/tasks/Geoprocessor",
"esri/tasks/FeatureSet",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/toolbars/draw",
"esri/symbols/SimpleFillSymbol",
"dojo/on","esri/graphic",
"esri/tasks/LinearUnit",
"dojo/domReady!"],
function (Map,
ArcGISDynamicMapServiceLayer,
dom,
Geoprocessor,
FeatureSet,
SimpleMarkerSymbol,
SimpleLineSymbol,
Draw,
SimpleFillSymbol,on,Graphic,LinearUnit) {
var MyMap = new Map("mapDiv");
var layer = new ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/%E5%90%88%E5%B7%A5%E5%A4%A7%E5%B9%B3%E9%9D%A2%E7%AE%80%E5%9B%BE/MapServer");
MyMap.addLayer(layer);
//定义点几何对象
var pointSet = new FeatureSet();
//新建简单点符号,样式为十字交叉,颜色红色,线宽2
var psymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 20,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2));
//添加按钮点击事件
on(dom.byId("Btn"),"click",function(e){
//定义绘图对象
var toolBar= new Draw(MyMap, { showTooltips: true });
//激活绘图对象
toolBar.activate(Draw.POINT);
on(toolBar, "draw-complete", function(result){
//获得绘图结束的点对象
var geometry = result.geometry;
//根据点对象生成相应的图形
var graphic = new Graphic(geometry,psymbol);
//将点对象存储在点几何中
pointSet.features.push(graphic);
//将图形存放在地图中,然后得以显示
MyMap.graphics.add(graphic);
});
});
on(dom.byId("buffer"),"click",function(e){
//定义GP服务对象
var buffer = new Geoprocessor("http://localhost:6080/arcgis/rest/services/test/easybuffer/GPServer/easybuffer");
//构建GP服务参数
var gpParams={};
//添加fields字段,为了和后台服务字段匹配
pointSet.fields = []; //很重要,为了和参数 一 一匹配
//GP服务的Input参数
gpParams.Input = pointSet;
//GP服务的dis参数
var dis = new LinearUnit({
"distance": 100,
"units": "esriMeters"
});
gpParams.dis=dis;
//执行GP服务
buffer.execute(gpParams, showResult);
});
function showResult(results, messages)
{
var features = results[0].value.features;
for (var i = 0; i < features.length; i++) {
var graphic = features[i];
//定义线符号
var lineSymbol=new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 1);
//定义面符号
var PolygonSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, lineSymbol, new dojo.Color([255, 255, 0, 0.25]));
//设置面符号
graphic.setSymbol(PolygonSymbol);
MyMap.graphics.add(graphic);
}
}
});
class="tundra">
id="Btn" type="button" value="画点" />
id="buffer" type="button" value="缓冲区分析" />
参考资料:(八)ArcGIS API For Javascript调用GP服务
https://blog.csdn.net/lovecarpenter/article/details/52673406
地理信息科学
Writed By NX
QQ:1051926720