package com.Myclass;
import com.esri.adf.web.faces.event.ClientActionArgs;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.adf.web.faces.event.MapToolAction;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.arcgisws.MapServerPort;
import com.esri.arcgisws.SpatialFilter;
import com.esri.arcgisws.EsriSearchOrder;
import com.esri.arcgisws.QueryFilter;
import com.esri.arcgisws.EsriSpatialRelEnum;
import com.esri.arcgisws.LayerDescription;
import com.esri.arcgisws.RecordSet;
import com.esri.arcgisws.Record;
import com.esri.adf.web.ags.util.AGSUtil;
import com.esri.arcgisws.PolygonN;
public class QueryPolygon implements MapToolAction //һ��ӿ�
{
private WebContext webContext = null;
private String pMsg ;
public QueryPolygon(){}
private void QueryFeature(WebGeometry pWebGeometry)
{
AGSMapResource pAGSMap = (AGSMapResource)webContext.getResources().get("ags1");
MapServerPort pMapServer = pAGSMap.getMapServer();
PolygonN pPolygonN = (PolygonN)AGSUtil.toAGSGeometry(pWebGeometry);
SpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects);
spatialFilter.setWhereClause("");//where
spatialFilter.setSearchOrder(EsriSearchOrder.esriSearchOrderSpatial);
spatialFilter.setSpatialRelDescription("");
spatialFilter.setGeometryFieldName("");//
spatialFilter.setFilterGeometry(pPolygonN);
AGSMapFunctionality pMapFunc = (AGSMapFunctionality)pAGSMap.getFunctionality("map");
LayerDescription[] pLayerDescs = pMapFunc.getLayerDescriptions();
QueryFilter pFilter = (QueryFilter)spatialFilter;
RecordSet pRSet = null;
Record[] pRs = null;
//WebQuery pWebQuery = this.webContext.getWebQuery();
WebQuery pWebQuery = (WebQuery)this.webContext.getAttribute("query");
pWebQuery.clearGraphics();
int pLayerCount = pLayerDescs.length;
for(int i=0; i<pLayerCount;i++)
{
LayerDescription pLayerDesc = pLayerDescs[i];
if(pLayerDesc.isVisible())
{
try
{
pRSet = pMapServer.queryFeatureData(pMapServer.getDefaultMapName(), i,pFilter);
}
catch(Exception pE)
{
return;
}
pRs = pRSet.getRecords();
int TheLayerQueryCount = pRs.length;
for(int j=0;j < TheLayerQueryCount;j++)
{
Record pItem = pRs[j];
int TheItemValuesCount = pItem.getValues().length;
for(int k=0; k<TheItemValuesCount;k++)
{
Object pOjb = pItem.getValues()[k];
if(pOjb instanceof com.esri.arcgisws.Geometry)
{
WebGeometry pGeo = null;
try
{
pGeo = AGSUtil.fromAGSGeometry((com.esri.arcgisws.Geometry)pOjb);
}
catch(Exception pE)
{
System.out.println(pE.getMessage());
break;
}
pWebQuery.addDisplayGeometry(pGeo);
break;
}
}
}
}
}
this.webContext.refresh();
}
public void execute(MapEvent arg0) throws Exception
{
ClientActionArgs clientarg = arg0.getClientActionArgs();
System.out.println( "---所有参数---" + clientarg.getRequestParameters());
this.webContext = arg0.getWebContext();
WebGeometry pWebGeometry = arg0.getWebGeometry();
pWebGeometry = pWebGeometry.toMapGeometry(arg0.getWebContext().getWebMap());
this.QueryFeature(pWebGeometry);
}
}
转载于: http://leo43.blog.hexun.com/p9/default.aspx