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

📄 georsstaskutil.java

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

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.text.NumberFormat;
import java.util.Iterator;
import java.util.Random;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.esri.adf.web.data.GraphicElement;
import com.esri.adf.web.data.symbol.WebPictureMarkerSymbol;
import com.esri.adf.web.data.symbol.WebSimpleLineSymbol;
import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol;
import com.esri.adf.web.data.symbol.WebSimplePolygonSymbol;
import com.esri.adf.web.data.symbol.WebTrueTypeMarkerSymbol;
import com.esri.adf.web.util.WebUtil;

public class GeorssTaskUtil {
	
	private static final Logger log = LogManager.getLogger(GeorssTaskUtil.class);
	
	private static final String DEFAULT_COLOR = "255,0,0";
	//private static final String DEFAULT_SELECTED_COLOR = "255,255,0";
	private static final int DEFAULT_MARKER_WIDTH = 8;
	private static final int DEFAULT_LINE_WIDTH = 3;
	private static final byte[] marker_selected;
	public static final WebPictureMarkerSymbol selectedWebPictureMarkerSymbol;
	
	static {
		marker_selected = loadPictureMarkerFromFile("/images/tasks/georss/markers/selected.png");
		selectedWebPictureMarkerSymbol = new WebPictureMarkerSymbol();
		selectedWebPictureMarkerSymbol.setPicture(marker_selected);
		selectedWebPictureMarkerSymbol.setWidth(12); 
	}
	
	public static WebSimpleMarkerSymbol newWebSimpleMarkerSymbol() {
		WebSimpleMarkerSymbol symbol = new WebSimpleMarkerSymbol();
		symbol.setColor(DEFAULT_COLOR);
		symbol.setOutlineColor(DEFAULT_COLOR);
		symbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE);
		symbol.setWidth(DEFAULT_MARKER_WIDTH);
		return symbol;
	}
	
	public static byte[] loadPictureMarkerFromFile(String fn) {
		byte[] data = null;
		
		try {
			InputStream is = WebUtil.getExternalContext().getResourceAsStream(fn);
			ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
			
			byte[] buffer = new byte[512];
			int count = 0;
			int num = 0;

			while ((num = is.read(buffer)) != -1) {
				bytestream.write(buffer, 0, num);
				count += num;
			}
			
			data = bytestream.toByteArray();		
		} catch (Exception e) { e.printStackTrace(); }
		
		return data;
	}
	
	public static WebPictureMarkerSymbol newWebPictureMarkerSymbol() {		
		Random generator = new Random();
		int index = generator.nextInt(48) + 1;
		
		NumberFormat nf = NumberFormat.getIntegerInstance();
		nf.setMinimumIntegerDigits(2);
		nf.setMaximumIntegerDigits(2);
		byte[] marker = loadPictureMarkerFromFile("/images/tasks/georss/markers/" + nf.format(index) + ".png");
		
		WebPictureMarkerSymbol symbol = new WebPictureMarkerSymbol();
		symbol.setPicture(marker);
		symbol.setWidth(12); 
		return symbol;
	}
	
	public static GraphicElement newTrueMarkerElement(GraphicElement element, String color) {
		try{
			GraphicElement newElement = new GraphicElement();
			newElement.setGeometry(element.getGeometry());
			
			WebTrueTypeMarkerSymbol pSymbol = new WebTrueTypeMarkerSymbol();
			pSymbol.setFontColor(((WebTrueTypeMarkerSymbol)element.getSymbol()).getFontColor());
			pSymbol.setFontName(((WebTrueTypeMarkerSymbol)element.getSymbol()).getFontName());
			pSymbol.setFontSize((int)((WebTrueTypeMarkerSymbol)element.getSymbol()).getFontSize());
			
			for(Iterator<String> txtValues = ((WebTrueTypeMarkerSymbol)element.getSymbol()).getTextValues().iterator(); txtValues.hasNext();) {
				pSymbol.addTextValue(txtValues.next());
			}
			
			pSymbol.setGlowingColor(color);
			newElement.setSymbol(pSymbol);
			
			return newElement;
			
		} catch(Exception ex) {
			log.error("Exception caught creating true marker element, returning null to caller", ex);
		}
		
		return null;
	}
	
	public static GraphicElement newSimpleMarkerElement(GraphicElement element, int markerType, int width, String color) {		
		try{
			GraphicElement newElement = new GraphicElement();
			newElement.setGeometry(element.getGeometry());
			
			WebSimpleMarkerSymbol pSymbol = new WebSimpleMarkerSymbol();
			pSymbol.setColor(color);
			pSymbol.setOutlineColor(color);
			pSymbol.setMarkerType(markerType);
			pSymbol.setWidth(width);
			newElement.setSymbol(pSymbol);
			
			return newElement;
			
		} catch(Exception ex) {
			log.error("Exception caught creating new simple marker element, returning null to caller.", ex);
		}
		
		return null;
	}

	public static GraphicElement newSimpleLineElement(GraphicElement element, String color) {
		try {
			GraphicElement newElement = new GraphicElement();
			newElement.setGeometry(element.getGeometry());
			
			WebSimpleLineSymbol pSymbol = new WebSimpleLineSymbol();
			pSymbol.setColor(color);
			pSymbol.setJoinType(WebSimpleLineSymbol.MITER);
			pSymbol.setLineType(((WebSimpleLineSymbol)element.getSymbol()).getLineType());
			pSymbol.setWidth(DEFAULT_LINE_WIDTH);
			newElement.setSymbol(pSymbol);
			
			return newElement;
			
		} catch(Exception ex) {
			log.error("Exception caught creating new simple line element, returning null to caller", ex);
		}
		
		return null;
	}

	public static GraphicElement newSimplePolygonElement(GraphicElement element, String color) {
		try {
			GraphicElement newElement = new GraphicElement();
			newElement.setGeometry(element.getGeometry());
			
			WebSimplePolygonSymbol pSymbol = new WebSimplePolygonSymbol();
			pSymbol.setFillColor(color);
			pSymbol.setFillInterval(((WebSimplePolygonSymbol)element.getSymbol()).getFillInterval());
			pSymbol.setColor(color);
			pSymbol.setWidth(DEFAULT_LINE_WIDTH);
			newElement.setSymbol(pSymbol);
			
			return newElement;
		}
		catch (Exception ex){
			log.error("Exception caught creating  new simple polygon element, returning null to caller", ex);
		}
		
		return null;
	}
}

⌨️ 快捷键说明

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