/[schmitzm]/trunk/src/skrueger/openlayers/OpenLayersUtil.java
ViewVC logotype

Contents of /trunk/src/skrueger/openlayers/OpenLayersUtil.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 934 - (show annotations)
Thu Jul 8 10:27:59 2010 UTC (14 years, 7 months ago) by alfonx
File MIME type: text/plain
File size: 1194 byte(s)
Added a method to OpenLayersUtil to convert a OpenLayers String representation of a OpenLayers.Bounds to a Java Rectangle2D
1 package skrueger.openlayers;
2
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
5
6 import org.geotools.resources.geometry.XRectangle2D;
7
8 final public class OpenLayersUtil {
9
10 /**
11 * A REGEX pattern to interpret the string representation of an
12 * Openlayer.Bounds object
13 **/
14 public final static Pattern OPENLAYERS_BOUNDS_FROM_STRING_REGEX = Pattern
15 .compile("left-bottom=\\((.*)?,(.*)?\\) right-top=\\((.*)?,(.*)?\\).*");
16
17 /**
18 * Ein OpenLayers.Bounds-Object welches als String übergeben wurde, kann mit
19 * dieser Methode geparsed und in Double-Koordinaten umgewandelt werden. Die
20 * Methode liefert <code>null</code> wenn das REGEX Muster nicht auf den
21 * String passt.
22 */
23 public static XRectangle2D parseBounds(String olBoundsString) {
24 Matcher matcher = OpenLayersUtil.OPENLAYERS_BOUNDS_FROM_STRING_REGEX
25 .matcher(olBoundsString);
26 if (matcher.find()) {
27 double x1 = Double.parseDouble(matcher.group(1));
28 double y1 = Double.parseDouble(matcher.group(2));
29 double x2 = Double.parseDouble(matcher.group(3));
30 double y2 = Double.parseDouble(matcher.group(4));
31
32 return new XRectangle2D(x1, y1, x2 - x1, y2 - y1);
33 } else {
34 return null;
35 }
36 }
37 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26