WebQuery webQuery = (WebQuery) webMap.getWebContext().getAttribute("query");
//定义线类型的高亮样式
WebSimpleLineSymbol markers1 = new WebSimpleLineSymbol();
markers1.setAntialiasing(true);
markers1.setColor("255,0,0");
webQuery.setLineGraphicSymbol(markers1);
//定义点类型的高亮样式
WebSimpleMarkerSymbol markers2 = new WebSimpleMarkerSymbol();
markers2.setAntialiasing(true);
markers2.setColor("0,255,0");
webQuery.setPointGraphicSymbol(markers2);
//定义面类型的高亮样式
WebSimplePolygonSymbol markers3 = new WebSimplePolygonSymbol();
markers3.setAntialiasing(true);
markers3.setColor("0,0,255");
webQuery.setPolygonGraphicSymbol(markers3);
List<SelectItem> layers= new ArrayList();
List<WebLayerInfo> layerList = webQuery.getQueryLayers();//获得所有图层信息
WebLayerInfo layerInfo = null;
for(Iterator iter = layerList.iterator(); iter.hasNext(); ) {
Object item = (Object) iter.next();
if(item instanceof WebLayerInfo){
layerInfo = (WebLayerInfo)item;
layers.add(new SelectItem(layerInfo, layerInfo.getName()));
System.out.println(layerInfo.getName());//图层名字,可以根据它指定查询某层
}
}
TextCriteria tc = new TextCriteria();
List<String> searchFields = new ArrayList<String>();
searchFields.add("type");
searchFields.add("sun");
tc.setSearchFields(searchFields);//添加需要查询的字段名
tc.setSearchText("1");//模糊查询的关键字
List results=webQuery.query(tc,layerList);//执行查询
System.out.println(results.size());//查询结果数量
for(int ii=0;ii<results.size();ii++){
QueryResult result = (QueryResult) results.get(ii);
result.highlight();//执行高亮操作
System.out.println(result.getDetails());//result.getDetails()可以获得所有字段
}
webMap.getWebContext().refresh();//刷新所有控件
转载于: http://leo43.blog.hexun.com/p9/default.aspx