1 |
alfonx |
773 |
package skrueger.openlayers; |
2 |
|
|
|
3 |
alfonx |
934 |
import java.util.regex.Matcher; |
4 |
alfonx |
773 |
import java.util.regex.Pattern; |
5 |
|
|
|
6 |
alfonx |
934 |
import org.geotools.resources.geometry.XRectangle2D; |
7 |
|
|
|
8 |
alfonx |
773 |
final public class OpenLayersUtil { |
9 |
|
|
|
10 |
alfonx |
934 |
/** |
11 |
|
|
* A REGEX pattern to interpret the string representation of an |
12 |
|
|
* Openlayer.Bounds object |
13 |
|
|
**/ |
14 |
alfonx |
773 |
public final static Pattern OPENLAYERS_BOUNDS_FROM_STRING_REGEX = Pattern |
15 |
|
|
.compile("left-bottom=\\((.*)?,(.*)?\\) right-top=\\((.*)?,(.*)?\\).*"); |
16 |
alfonx |
934 |
|
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 |
alfonx |
773 |
} |