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

📄 webarc.java

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

import java.util.List;

import org.apache.log4j.Logger;

import com.esri.adf.web.data.geometry.WebCircle;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.solutions.jitk.common.math.DegreeConverter;

@SuppressWarnings("deprecation")
public class WebArc extends WebPolyline {
	private static final long serialVersionUID = 6369298249564665026L;
	private static final Logger _logger = Logger.getLogger(WebArc.class);
	
	protected WebPoint _center;
	protected double _radius;
	protected double  _startAngle;
	protected double _endAngle;
	
	public WebArc(WebPoint center, double radius, double startAngle, double endAngle) {
		super();
		_center = center;
		_radius = radius;
		_startAngle = startAngle;
		_endAngle = endAngle;	
	}
	
	
	public WebArc(WebCircle circle, double startAngle, double endAngle) {
		super();
		_center = circle.getCenter();
		_radius = circle.getRadius();
		_startAngle = startAngle;
		_endAngle = endAngle;	
	}	

	public WebPoint getCenter() {
		return _center;
	}

	public void setCenter(WebPoint _center) {
		this._center = _center;
	}

	public double getRadius() {
		return _radius;
	}

	public void setRadius(double _radius) {
		this._radius = _radius;
	}

	public double getStartAngle() {
		return _startAngle;
	}

	public void setStartAngle(double angle) {
		_startAngle = angle;
	}

	public double getEndAngle() {
		return _endAngle;
	}

	public void setEndAngle(double angle) {
		_endAngle = angle;
	}
	
	public void densify() {
		densify(_startAngle, _endAngle, true);
	}
	
	public boolean isDensified() {		
		List<WebPath> paths = this.getPaths();
		
		if (paths == null) {
			return false;
		}
		
		if (paths.size() < 1) {
			return false;
		}
		
		WebPath path = paths.get(0);
		List<WebPoint> points = path.getPoints();
		
		if (points == null) {			
			return false;
		}
		
		if (points.size() < 1) {	
			return false;
		}
		
		return true;
	}
	
	public WebPoint getStartPoint() {
		if (!isDensified()) {
			_logger.warn("Arc not densified and start point requested, densifying");
			densify();
		}
		
		List<WebPath> paths = this.getPaths();
		WebPath path = paths.get(0);
		List<WebPoint> points = path.getPoints();
		
		return points.get(0);
	}
	
	public WebPoint getEndPoint() {
		if (!isDensified()) {
			_logger.warn("Arc not densified and end point requested, densifying");
			densify();
		}		
		
		WebPath path = this.getPaths().get(0);
		int lastIndex = path.getPoints().size() - 1;
		
		return path.getPoints().get(lastIndex);
	}
	
	public void densify(double startAngle, double endAngle, boolean clearPreviousPaths) {
        final double dMaxEndAngle = 360;
        final double dMinStartAngle = 0;
		
        if (clearPreviousPaths) {
        	this.getPaths().clear();
        }
		
        if (endAngle < startAngle) {
        	this.densify(startAngle, dMaxEndAngle);
        	this.densify(dMinStartAngle, endAngle);
        }
        else {
        	this.densify(startAngle, endAngle);
        }
	}	
	
	protected void densify(double startAngle, double endAngle) {
		WebPath webPath = new WebPath();
		WebPoint webPoint = this.getCenter();
		int step = 360;
		
		double angleStep = (2*Math.PI)/step;
		double startRadian = DegreeConverter.toRadians(startAngle);
		double endRadian = DegreeConverter.toRadians(endAngle);
		
		for(double angle = startRadian; angle <= endRadian; angle+=angleStep) {
            double x = webPoint.getX() + this.getRadius()*Math.cos(angle);
            double y = webPoint.getY() + this.getRadius()*Math.sin(angle);
            
            webPath.addPoint(new WebPoint(x, y, this.getSpatialReference()));
		}
		
		this.addPath(webPath);	
	}	
	
	/**
	 * Flips the arc from the middle x-axis of the circle or the arc.
	 */
	public void flip() {
		double shiftY = getYAxisZeroShift();
			
		List<WebPath> paths = this.getPaths();
		
		for (WebPath path : paths) {
			List<WebPoint> points = path.getPoints();
			
			for (WebPoint point : points) {
				double flippedY = flipY(point.getY(), shiftY);
				point.setY(flippedY);
			}
		}
	}
	
	/**
	 * Flips a y value on the middle x-axis of the circle of the arc.
	 * @param orignialY Y value to flip
	 * @param zeroAxisShift Units of measure to bring the center axis of the 
	 * circle on the 0 Y axis.
	 * @return new y value.
	 */
	protected double flipY(double orignialY, double zeroAxisShift) {
		double y = orignialY + zeroAxisShift;
		y *= -1;
		y += (-1) * zeroAxisShift;		
		
		return y;
	}
	
	protected double getYAxisZeroShift() {
		double maxY = getCircleMaxY();
		return (((-1.0) * maxY) + this._radius);
	}
	
	protected void shiftY(double shift) {
		List<WebPath> paths = this.getPaths();
		
		for (WebPath path : paths) {
			List<WebPoint> points = path.getPoints();
			
			for (WebPoint point : points) {				
				point.setY(point.getY() + shift);
			}
		}			
	}
	
	protected double getCircleMaxY() {
		return this.getCenter().getY() + this._radius;
	}
	
	protected double getArcMaxY() {
		double maxY = 0.0;
		
		List<WebPath> paths = this.getPaths();
		
		for (WebPath path : paths) {
			List<WebPoint> points = path.getPoints();
			
			for (WebPoint point : points) {				
				if (maxY < point.getY()) {
					maxY = point.getY();
				}
			}
		}	
		
		return maxY;
	}
}

⌨️ 快捷键说明

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