ArcGIS API for JS 中,三种查询方式

1、QueryTask:这种查询方式只能针对一个图层进行空间或属性查询。返回结果是一个FeatureSet,其中FeatureSet.features[i]加入图层显示。(QueryTask进行查询的地图服务并不必项加载到Map中进行显示。)

QueryTask in 3.22api、Query in 3.22api

例如:

var queryTask = new QueryTask("http://localhost/ArcGIS/rest/services/XX/ZhouShi/MapServer/0");//实例化QueryTask
var query = new Query();//定义Query
//设置Query参数
query.returnGeometry = true;//是否返回几何
query.outFields=["*"],//要查询的字段
query.where = "name = '李'"; //查询条件  
queryTask.execute(query, showResults);//回调
function showResults (results) {  
	var resultCount = results.features.length;  
	var features = results.features;  
	for (var i = 0; i < resultCount; i++) {//输出对象编译形式  
	}  
	map.centerAndZoom(features[0].geometry,11);  
}

2、FindTask:对一个地图服务的多个图层对象(全部或指定几个ID索引)做属性查询。返回的是一个FindResults数组,其中FindResults[i].feature加入图层显示。
FindTask in 3.22api、 FindParameters in 3.22api
例如:

var find = new FindTask("http://localhost/ArcGIS/rest/services/XX/ZhouShi/MapServer");//实例化FindTask
var params = new FindParameters();//定义FindParameters
params.layerIds = [2,3];//设置查询的图层id
params.searchFields = ["STATE_NAME","STATE_FIPS"];//设置查询字段
params.searchText = dom.byId("searchText").value;//设置字段值
find.execute(params, showResults);//回调
function showResults(results) {  
	var result, attribs;  
	var s = [""];  
	dojo.forEach(results,function(result){  
		attribs = result.feature.attributes;  
		s.push("");  
	});  
	s.push("
State NameFIPSPopulation (1990)Population (1999)
" + attribs.STATE_NAME + "" + attribs.STATE_FIPS + "" + attribs.POP1990 + "" + attribs.POP1999 + "
"); dojo.byId("tbl").innerHTML = s.join(""); }


3、IdentifyTask:对一个地图服务的多个图层对象(全部或指定几个ID索引)做空间查询。返回一个identifyResults数组,其中identifyResults[i].feature加入图层显示。
IdentifyTask in 3.22api、 IdentifyParameters in 3.22api
例如:
identifyTask = new IdentifyTask(dynamicLayerUrl);//查询  
identifyParams = new IdentifyParameters();//查询参数  
identifyParams.tolerance = 10;//容差范围  
identifyParams.returnGeometry = true;//是否返回图形  
identifyParams.layerIds = [ 0 ];//查询图层   
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;//设置查询的图层
//查询范围  
identifyParams.width = map.width;  
identifyParams.height = map.height; 
identifyParams.geometry = event.mapPoint;  
identifyParams.mapExtent = map.extent;
identifyTask.execute(identifyParams,showResults);
function showResults (results) {
	var feature;
	var sGeometry;  
	if (results.length > 0) {  
		for ( var i = 0; i < results.length; i++) {  
			feature = results[i].feature;  
			map.infoWindow.setTitle("标注信息");  
                	map.infoWindow.setContent("地区:"  
                                                + feature.attributes.NAME_  
                                                + "
" + "机构:" + feature.attributes.TYPENAME_ + "
" + "站点:" + feature.attributes.NOTES_ + "
" + "地址:" + feature.attributes.LOCATION_); map.infoWindow.show(feature.geometry,map.getInfoWindowAnchor(feature.geometry)); map.infoWindow.show(); } } }


你可能感兴趣的:(arcgis,api,for,js)