来源:B站
1.任务
ArcGIS API for JavaScript中执行多种类型的任务。所有的任务都是通过esri/tasks资源进行访问的
ClosestFacilityTask ,ConfigurationTask ,FindTask ,GeometryService,Geoprocessor , ldentifyTask ,ImageServiceldentifyTask , JobTask,Locator,NotificationTask,PrintTask ,QueryTask,ReportTask ,RouteTask , ServiceAreaTask ,TokenTask ,WorkflowTask
2.什么是promise
一个promise代表一个操作完成的最终返回值的对象
promise有以下特点:
-可以为三个状态中的一个: pending、resolved、rejected
-可以从unfulfilled转变到resolved或者rejected
-实现了一个then()方法来注册回调函数
someAsyncFunction().then(callback, errback);
回调不能改变promise产生的值
-promise的then()方法可以返回一个新的promise,可进行链式操作
3.查询、定位、查找
3.1查询
模式:查询参数>查询任务>查询结果
Query>QueryTask>多种形式
查询类型:属性查询、空间查询、统计查询
3.1.1属性查询:
可以通过两个属性设置查询条件:Query.where和Query.text
var query = new Query ();
query.where = “STATENAME= ‘Washington’”;
query.text = “Washington”; 这个只能查询默认字段,不能查询其他字段
3.1.2空间查询:
通过Query.geometry + Query.spatialRelationship 指定查询条件
Geometry,Extent , Multipoint , Point , Polygon , Polyline,spatialRelationship,lntersects, contains, crosses, envelope-intersects, index-intersects, overlaps, touches, within, relation
var polygon = new Polygon({
rings: rings
});
var query = new Query ();
query. geometry = polygon;
query.spatialRelationship = “intersects” ;
可选参数:Query.distance和Query.units
3.1.3统计查询
通过Query.outStatistics定义参数
//query for the sum of the population in all features。查询所有要素的人口总数
var sumPopulation = {
onStatisticField:“POP_2015”,// service field for 2015 population //统计字段
outstatisticrieldName:“Pop_2015_sum”, //统计结果字段
statisticType: “sum” //统计类型
};
//Notice that you can pass a sLexpression as a field name to calculate statistics。请注意,您可以传递一个sLexpression作为字段名来计算统计信息
var populationchangeDefinition = {
onStatisticField:“POP_2015 - POP_2010”,// service field for 2015 population
outstatisticrieldName: “avg_pop_change_2015_2010” ,
statisticType: “avg”
};
var query = new Query ();
query.outstatistics = [sumPopulation,populationChangeDefinition]; //传入数组
3.2定位
输入>任务>输出
IdentifyParameters>IdentifyTask>IdentifyResult
定位-ldentifyParameter
IdentifyParameter对象可以为定位操作设置多个属性:
- geometry
- layerlds
- layerOption
- tolerance
- returnGeometry
…
//set the parameters for the Identify
params = new IdentifyParameters();
params.geometry = event.mapPoint;
params.layerIds = [o,1,2];
params.layeroption = “visible” ;
params.tolerance = 3;
params.mapExtent = view.extent;
3.3查找
查找-FindParameters
输入>任务>输出
FindParameters>FindTask>FindResult
FindParameters对象为查找操作指定搜索条件:
- layerlds
- searchFields
- searchText
- returnGeometry
- contains
var params = new FindParameters ();
params.layerIds = [0];
params.searchFields =[“areaname”];
params.searchText = document.getElementById(“inputTxt”).value;
创建FindTask对象
//create a FindTask pointing to a map service
var find = new FindTask({
url: “https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/Map”
});
Query,Identify 和Find比较
4地理处理任务
首先需要一个地理处理模型
地理处理模型:arcMap中Toolboxes工具箱,每个工具都可以称为地理处理模型。
发布地理处理模型及使用。
输入>任务>输出
对象>Geoprocessor>ParameterValue
对象:构建地理处理模型时指定都输出参数。
需要知道的三件事
①地理处理服务URL地址
②输入和输出参数
③任务是同步的还是异步的
同步任务
-任务执行时,使用者必须等待执行的结果;
-使用Geoprocessor.execute()方法提交作业;
-执行结果保存在ParameterValue数组中;
异步任务
-提交作业后,执行结果返回前其他功能还可以继续执行;
-使用Geoprocessor.submitJob()方法提交作业;
服务详情页面