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

📄 webgeometryoffsetter.java

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

import java.util.List;

import org.apache.log4j.Logger;

import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.GeometryUtil;
import com.esri.adf.web.data.geometry.WebCircle;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebOval;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPointCollection;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.data.geometry.WebRing;
import com.esri.solutions.jitk.web.data.geometry.WebArc;

@SuppressWarnings("deprecation")
public class WebGeometryOffsetter {
	private static final Logger _logger = Logger.getLogger(WebGeometryOffsetter.class);
	
	public WebGeometryOffsetter() {}
	
	public WebGeometry move(WebMap webMap, WebGeometry webGeo, WebPoint newCentroid) throws Exception {
		
		WebExtent webExtMap = GeometryUtil.computeWebExtent(webGeo);
		double xOffset, yOffset;
		
		if(webExtMap.getWidth() == 0)
			xOffset = newCentroid.getX() - ((WebPoint)webGeo).getX();
		else
			xOffset = newCentroid.getX() - (webExtMap.getMaxX() + webExtMap.getMinX()) / 2;
		
		if(webExtMap.getHeight() == 0)
			yOffset = newCentroid.getY() - ((WebPoint)webGeo).getY();
		else
			yOffset = newCentroid.getY() - (webExtMap.getMaxY() + webExtMap.getMinY()) / 2;
		
		if (webGeo instanceof WebPoint) {
			_logger.debug("Moving WebPoint");
			move((WebPoint) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebPath) {
			_logger.debug("Moving WebPath");
			move((WebPath) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebPolyline) {
			_logger.debug("Moving WebPolyline");
			move((WebPolyline) webGeo, xOffset, yOffset);
		}					
		else if (webGeo instanceof WebPolygon) {
			_logger.debug("Moving WebPolygon");
			move((WebPolygon) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebCircle) {
			_logger.debug("Moving WebCircle");
			move((WebCircle) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebOval) {
			_logger.debug("Moving WebOval");
			move((WebOval) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebPointCollection) {
			_logger.debug("Moving WebPointCollection");
			move((WebPointCollection) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebExtent) {
			_logger.debug("Moving WebExtent");
			move((WebExtent) webGeo, xOffset, yOffset);
		}
		else if (webGeo instanceof WebRing) {
			_logger.debug("Moving WebRing");
			move((WebRing) webGeo, xOffset, yOffset);
		}	
		else if (webGeo instanceof WebArc) {
			_logger.debug("Moving WebArc");
			move((WebArc) webGeo, xOffset, yOffset);
		}		
		else {
			_logger.warn("Unsupported geometry type encountered");
			throw new Exception("Unsupported geomtry type encountered");
		}
		
		return webGeo;
	}
	
	public void move(WebArc arc, double xOffset, double yOffset) {
		move(arc.getCenter(), xOffset, yOffset);
		move((WebPolyline) arc, xOffset, yOffset);
	}	
	
	public void move(WebOval oval, double xOffset, double yOffset) {
		move(oval.getCenter(), xOffset, yOffset);
	}		
	
	public void move(WebCircle circle, double xOffset, double yOffset) {
		move(circle.getCenter(), xOffset, yOffset);
	}	
	
	public void move(WebExtent ext, double xOffset, double yOffset) {
		ext.setMaxX(ext.getMaxX() + xOffset);
		ext.setMinX(ext.getMinX() + xOffset);
		ext.setMaxY(ext.getMaxY() + yOffset);
		ext.setMinY(ext.getMinY() + yOffset);
	}
	
	public void move(WebPointCollection pointCol, double xOffset, double yOffset) {
		List<WebPoint> points = pointCol.getPoints();
	
		for (WebPoint point : points) {
			move(point, xOffset, yOffset);
		}
	}	
	
	public void move(WebPolygon polygon, double xOffset, double yOffset) {
		List<WebRing> rings = polygon.getRings();
		
		for (WebRing ring : rings) {
			move(ring, xOffset, yOffset);
		}
	}
	
	public void move(WebRing ring, double xOffset, double yOffset) {
		List<WebPoint> points = ring.getPoints();
		
		//If the first vertex is the same object as the last vertex, do 
		//not move it twice
		boolean lastVertexEqualToFirst = isLastVertexEqualToFirst(ring);
		int vertexCount = ring.getPoints().size();
		int stopVertexIndex = lastVertexEqualToFirst ? vertexCount - 2 : vertexCount - 1;
		
		if (lastVertexEqualToFirst) {
			_logger.debug("First vertex of WebRing equals the last vertex");
		}
		else {
			_logger.debug("First vertex of WebRing does not equal the last vertex");
		}
		
		for (int vertexIdx = 0; vertexIdx <= stopVertexIndex; vertexIdx++) {
			move(points.get(vertexIdx), xOffset, yOffset);
		}
	}	
	
	public boolean isLastVertexEqualToFirst(WebRing ring) {
		int vertexCount = ring.getPoints().size();
		WebPoint first = ring.getPoints().get(0);
		WebPoint last = ring.getPoints().get(vertexCount - 1);
		
		return first == last;
	}
	
	public void move(WebPolyline line, double xOffset, double yOffset) {
		List<WebPath> paths = line.getPaths();
		
		for (WebPath path : paths) {
			move(path, xOffset, yOffset);
		}
	}
	
	public void move(WebPath path, double xOffset, double yOffset) {
		List<WebPoint> points = path.getPoints();
		
		for (WebPoint point : points) {
			move(point, xOffset, yOffset);
		}
	}
	
	public void move(WebPoint point, double xOffset, double yOffset) {
		point.setX(point.getX() + xOffset);
		point.setY(point.getY() + yOffset);
	}
}

⌨️ 快捷键说明

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