[Schmitzm-commits] r934 - trunk/src/skrueger/openlayers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jul 8 12:27:59 CEST 2010


Author: alfonx
Date: 2010-07-08 12:27:59 +0200 (Thu, 08 Jul 2010)
New Revision: 934

Modified:
   trunk/src/skrueger/openlayers/OpenLayersUtil.java
Log:
Added a method to OpenLayersUtil to convert a OpenLayers String representation of a OpenLayers.Bounds to a Java Rectangle2D

Modified: trunk/src/skrueger/openlayers/OpenLayersUtil.java
===================================================================
--- trunk/src/skrueger/openlayers/OpenLayersUtil.java	2010-07-08 09:37:25 UTC (rev 933)
+++ trunk/src/skrueger/openlayers/OpenLayersUtil.java	2010-07-08 10:27:59 UTC (rev 934)
@@ -1,10 +1,37 @@
 package skrueger.openlayers;
 
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.geotools.resources.geometry.XRectangle2D;
+
 final public class OpenLayersUtil {
 
-	/** A REGEX pattern to interpret the string representation of an Openlayer.Bounds object **/
+	/**
+	 * A REGEX pattern to interpret the string representation of an
+	 * Openlayer.Bounds object
+	 **/
 	public final static Pattern OPENLAYERS_BOUNDS_FROM_STRING_REGEX = Pattern
 			.compile("left-bottom=\\((.*)?,(.*)?\\) right-top=\\((.*)?,(.*)?\\).*");
+
+	/**
+	 * Ein OpenLayers.Bounds-Object welches als String übergeben wurde, kann mit
+	 * dieser Methode geparsed und in Double-Koordinaten umgewandelt werden. Die
+	 * Methode liefert <code>null</code> wenn das REGEX Muster nicht auf den
+	 * String passt.
+	 */
+	public static XRectangle2D parseBounds(String olBoundsString) {
+		Matcher matcher = OpenLayersUtil.OPENLAYERS_BOUNDS_FROM_STRING_REGEX
+				.matcher(olBoundsString);
+		if (matcher.find()) {
+			double x1 = Double.parseDouble(matcher.group(1));
+			double y1 = Double.parseDouble(matcher.group(2));
+			double x2 = Double.parseDouble(matcher.group(3));
+			double y2 = Double.parseDouble(matcher.group(4));
+
+			return new XRectangle2D(x1, y1, x2 - x1, y2 - y1);
+		} else {
+			return null;
+		}
+	}
 }



More information about the Schmitzm-commits mailing list