/[schmitzm]/branches/2.3.x/src/skrueger/openlayers/OpenLayersUtil.java
ViewVC logotype

Diff of /branches/2.3.x/src/skrueger/openlayers/OpenLayersUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 933 by alfonx, Tue Mar 23 16:56:54 2010 UTC revision 934 by alfonx, Thu Jul 8 10:27:59 2010 UTC
# Line 1  Line 1 
1  package skrueger.openlayers;  package skrueger.openlayers;
2    
3    import java.util.regex.Matcher;
4  import java.util.regex.Pattern;  import java.util.regex.Pattern;
5    
6    import org.geotools.resources.geometry.XRectangle2D;
7    
8  final public class OpenLayersUtil {  final public class OpenLayersUtil {
9    
10          /** A REGEX pattern to interpret the string representation of an Openlayer.Bounds object **/          /**
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          public final static Pattern OPENLAYERS_BOUNDS_FROM_STRING_REGEX = Pattern
15                          .compile("left-bottom=\\((.*)?,(.*)?\\) right-top=\\((.*)?,(.*)?\\).*");                          .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  }  }

Legend:
Removed from v.933  
changed lines
  Added in v.934

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26