相比较于QueryTask,FindTask和IdentifyTask支持多个图层查询。FindTask支持属性查询,IdentifyTask支持图形查询。
1、FindTask
FindTask通过FindParameters类来设置查询参数,执行search.execute(FindParameters,function (result))
先设置查询参数:
returnGeometry:是否返回Geometry;
layerIds:要查询图层的ID;
searchFields:通过哪个字段来查询;
searchText:查询字段匹配值
var params = new FindParameters();
params.returnGeometry=true;
params.layerIds=[0,1,2];
params.searchFields=["name"];
params.searchText=$("#searchParam").val();
执行查询
将查询结果通过表格形式展示,再给表格每行添加点击设置地图中心事件
search.execute(params,function (result) {
if(result.length==0){
alert("俺没找到哦")
}else {
$("#result table").html("");
$("#result table").append(" <tr> <th>名字</th> <th>价格</th> <th>容积率</th> <th>绿化率</th> <th>户数</th> <th>区域</th> <th>商圈</th> <th>类型</th> </tr>");
for(var a=0;a<result.length;a++){
var html="<tr>"+
"<td>" +result[a]