⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filtertaskutil.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.tasks.filter;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.LinkedHashMap;
import com.esri.adf.web.aims.data.AIMSMapResource;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebRing;
import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol;
import com.esri.adf.web.data.symbol.WebSimpleLineSymbol;
import com.esri.adf.web.data.symbol.WebSimplePolygonSymbol;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.GraphicElement;
import com.esri.adf.web.data.WebLayerInfo;

/**
 * MVS-045: Filter Task support class. This utility class creates filter graphics. 
 */
public class FilterTaskUtil {
	private static Logger logger = Logger.getLogger(FilterTaskUtil.class.getName());

	static final int SHAPE_WIDTH = 3;
	static final String COLOR = "255,0,0";

	public FilterTaskUtil(){}

	public static GraphicElement setSymbol(WebGeometry webGeom, String color){
		if (color == null) color = COLOR;
		try{
			if (webGeom instanceof WebPoint){
				WebSimpleMarkerSymbol pSymbol = new WebSimpleMarkerSymbol();
				pSymbol.setColor(color);
				pSymbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE);
				pSymbol.setWidth(SHAPE_WIDTH * SHAPE_WIDTH);

				GraphicElement graphicElem = new GraphicElement();
				graphicElem.setGeometry(webGeom);
				graphicElem.setSymbol(pSymbol);
				return graphicElem;
			}
			if (webGeom instanceof WebPolyline){
				WebSimpleLineSymbol pSymbol = new WebSimpleLineSymbol();
				pSymbol.setColor(color);
				pSymbol.setJoinType(WebSimpleLineSymbol.MITER);
				pSymbol.setLineType(WebSimpleLineSymbol.SOLID);
				pSymbol.setWidth(SHAPE_WIDTH);
				GraphicElement graphicElem = new GraphicElement();
				graphicElem.setGeometry(graphicElem.getGeometry());
				graphicElem.setSymbol(pSymbol);
				return graphicElem;
			}
			if (webGeom instanceof WebPolygon){
				WebSimplePolygonSymbol pSymbol = new WebSimplePolygonSymbol();
				pSymbol.setFillColor(color);
				pSymbol.setColor(color);
				pSymbol.setWidth(SHAPE_WIDTH);
				GraphicElement graphicElem = new GraphicElement();
				graphicElem.setGeometry(graphicElem.getGeometry());
				graphicElem.setSymbol(pSymbol);
				return graphicElem;
			}
		}
		catch (Exception e){
			logger.log(Priority.ERROR, "Unable to set symbol", e);
		}
		return null;
	}


	private static WebExtent getPointEnvelope(WebGeometry webGeom){
		try{
			WebPoint webPoint = (WebPoint)webGeom;
			return new WebExtent(webPoint.getX(), webPoint.getY(), webPoint.getX(), webPoint.getY());
		}catch(Exception e){
			logger.log(Priority.ERROR, "Unable to get point envelope", e);
		}
		return null;
	}

	private static WebExtent getLineEnvelope(WebGeometry webGeom){
		try{
			WebPolyline webLine = (WebPolyline)webGeom;
			@SuppressWarnings("unchecked")
			Iterator rit = webLine.getPaths().iterator();
			WebExtent webExt = new WebExtent() ;
			boolean firstElm = false;
			while (rit.hasNext()){
				WebPath path = (WebPath)rit.next();
				Iterator<WebPoint> pit = path.getPoints().iterator();
				while (pit.hasNext()){
					WebPoint webPoint = (WebPoint)pit.next();
					if (!firstElm){
						webExt.setMinX(webPoint.getX());
						webExt.setMaxX(webPoint.getX());
						webExt.setMinY(webPoint.getY());
						webExt.setMaxY(webPoint.getY());
						firstElm = true;
					}
					if (webPoint.getX() < webExt.getMinX()) webExt.setMinX(webPoint.getX());
					if (webPoint.getX() > webExt.getMaxX()) webExt.setMaxX(webPoint.getX());
					if (webPoint.getY() < webExt.getMinY()) webExt.setMinY(webPoint.getY());
					if (webPoint.getY() > webExt.getMaxY()) webExt.setMaxY(webPoint.getY());
				}
			}
			return webExt;
		}catch(Exception e){
			logger.log(Priority.ERROR, "Unable to get line envelope", e);
		}
		return null;
	}

	private static WebExtent getPolyEnvelope(WebGeometry webGeom){
		try{
			WebPolygon webPoly = (WebPolygon)webGeom;
			@SuppressWarnings("unchecked")
			Iterator rit = webPoly.getRings().iterator();
			WebExtent webExt = new WebExtent();
			boolean firstElm = false;
			while (rit.hasNext())
			{
				WebRing ring = (WebRing)rit.next();
				@SuppressWarnings("unchecked")
				Iterator pit = ring.getPoints().iterator();
				while (pit.hasNext()){
					WebPoint webPoint = (WebPoint)pit.next();
					if (!firstElm){
						webExt.setMinX(webPoint.getX());
						webExt.setMaxX(webPoint.getX());
						webExt.setMinY(webPoint.getY());
						webExt.setMaxY(webPoint.getY());
						firstElm = true;
					}
					if (webPoint.getX() < webExt.getMinX()) webExt.setMinX(webPoint.getX());
					if (webPoint.getX() > webExt.getMaxX()) webExt.setMaxX(webPoint.getX());
					if (webPoint.getY() < webExt.getMinY()) webExt.setMinY(webPoint.getY());
					if (webPoint.getY() > webExt.getMaxY()) webExt.setMaxY(webPoint.getY());
				}
			}
			return webExt;
		}catch(Exception e){
			logger.log(Priority.ERROR, "Unable to get polygon envelope", e);
		}
		return null;
	}

	public static WebExtent getGeometryEnvelope(WebGeometry webGeom){
		try{
			if (webGeom instanceof WebPoint) return getPointEnvelope(webGeom);
			if (webGeom instanceof WebPolyline) return getLineEnvelope(webGeom);
			if (webGeom instanceof WebPolygon) return getPolyEnvelope(webGeom);
		}catch(Exception e){
			logger.log(Priority.ERROR, "Unable to get geometry envelope", e);
		}
		return null;
	}

	public static List<WebLayerInfo> getWebLayerInfoList(List<WebLayerInfo> layerList, String webLayerName){
	    List<WebLayerInfo> list = null;
		if(layerList!=null && layerList.size()>0) {
			list = new ArrayList<WebLayerInfo>(1);
			int index = 0;
			for(Iterator<WebLayerInfo> iter = layerList.iterator(); iter.hasNext();index++) {
				WebLayerInfo layer = (WebLayerInfo)iter.next();	        
				if(layer.getName().equalsIgnoreCase(webLayerName)) {
	        		list.add(layer);
					return list;
				}
			}
		}
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public static LinkedHashMap<String, String> getLayerList(WebContext context){
		try{
			LinkedHashMap<String, String> newLayerList = new LinkedHashMap<String, String>();		
			if(context != null){	
				Map<String, GISResource> resources = context.getResources();				
				Object resource;
							
				for(Iterator iter = resources.keySet().iterator(); iter.hasNext();){
	            	String id = (String)iter.next();
	            	resource = resources.get(id);

					if (resource instanceof AGSMapResource){
						AGSMapResource tempAgsResource = (AGSMapResource)resource;
						LinkedHashMap<String, String> layerList = FilterTaskAgsUtil.getServiceLayerList(tempAgsResource, id);
						newLayerList.putAll(layerList);
					}
/*
					if (resource instanceof AWSMapResource){
						AWSMapResource tempAwsResource = (AWSMapResource)resource;
						LinkedHashMap<String, String> layerList = FilterTaskAwsUtil.getServiceLayerList(tempAwsResource, id);
						newLayerList.putAll(layerList);
					}
					if (resource instanceof WMSMapResource){
						WMSMapResource tmpWmsResource = (WMSMapResource)resource;
						LinkedHashMap<String, String> layerList = FilterTaskWmsUtil.getServiceLayerList(tmpWmsResource, id);
						newLayerList.putAll(layerList);
					}
 */
	            }
			}			
			return newLayerList;
		}
		catch(Exception e){
			logger.log(Priority.ERROR, "Unable to get layer list", e);
		}
		return null;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -