Commits

Giuseppe La Scaleia committed c0a88da Merge

Merged in jonbritton3/gwt-openlayers (pull request #12)

  • Participants
  • Parent commits e8e07a7, 91f309c

Comments (0)

Files changed (3)

File gwt-openlayers-client/src/main/java/org/gwtopenmaps/openlayers/client/Bounds.java

  * @author Erdem Gunay
  * @author Curtis Jensen
  * @author Edwin Commandeur
+ * @author Jon Britton, SpiffyMap Ltd.
  */
 public class Bounds extends OpenLayersObjectWrapper {
 
 				upperRightX,
 				upperRightY));
 	}
+    
+    /**
+     * Create an empty Bounds object with coordinates set to null
+     */
+    public Bounds() {
+        this(BoundsImpl.create());
+    }
 
 	public double[] toArray(){
 		JSObject boundsOpaque = BoundsImpl.toArray(getJSObject());
 	public float getHeight() {
 		return BoundsImpl.getHeight(getJSObject());
 	}
+    
+    /**
+     * @return the size of the box
+     */
+    public Size getSize() {
+        return Size.narrowToSize(BoundsImpl.getSize(getJSObject()));
+    }
+    
 	/**
 	 * @param significantDigits - Number of significant digits in the bbox coordinates,
 	 *  	pass null to use the default of 6.
 		return BoundsImpl.toString(getJSObject());
 	}
 
+    /**
+     * 
+     * @return the center of the bounds in map space
+     */
 	public LonLat getCenterLonLat() {
 		return LonLat.narrowToLonLat(BoundsImpl.getCenterLonLat(this.getJSObject()));
 	}
+    
+    /**
+     * @return the center of the bounds in pixel space
+     */
+    public Pixel getCenterPixel() {
+        return Pixel.narrowToPixel(BoundsImpl.getCenterPixel(this.getJSObject()));
+    }
 
 	public Geometry toGeometry() {
 		return Geometry.narrowToGeometry(BoundsImpl.toGeometry(this.getJSObject()));
 		return Bounds.narrowToBounds(BoundsImpl.transform(getJSObject(),
 				source.getJSObject(), dest.getJSObject()));
 	}
+    
+    /**
+     * Scales the bounds.
+     * @param ratio
+     * @return a new bounds that is scaled by ratio
+     */
+    public Bounds scale(float ratio) {
+        return Bounds.narrowToBounds(BoundsImpl.scale(this.getJSObject(), ratio, null));
+    }
+    
+    /**
+     * Scales the bounds around a pixel. Note that the new bounds may return non-integer properties.
+     * @param ratio
+     * @param origin default is center
+     * @return a new bounds that is scaled by ratio from origin
+     */
+    public Bounds scale(float ratio, Pixel origin) {
+        JSObject originJsObj = (origin == null) ? null : origin.getJSObject();
+        return Bounds.narrowToBounds(BoundsImpl.scale(this.getJSObject(), ratio, originJsObj));
+    }
+    
+    /**
+     * @param x
+     * @param y
+     * @return A new bounds whose coordinates are the same as this, but shifted by the passed-in 
+     * x and y values.
+     */
+    public Bounds add(float x, float y) {
+        return Bounds.narrowToBounds(BoundsImpl.add(this.getJSObject(), x, y));
+    }
+    
+    /**
+     * Scales the bounds around a LonLat.
+     * @param ratio
+     * @param origin default is center
+     * @return a new bounds that is scaled by ratio from origin
+     */
+    public Bounds scale(float ratio, LonLat origin) {
+        JSObject originJsObj = (origin == null) ? null : origin.getJSObject();
+        return Bounds.narrowToBounds(BoundsImpl.scale(this.getJSObject(), ratio, originJsObj));
+    }
 
 	/**
 	 * APIMethod: containsLonLat
 		return BoundsImpl.containsLonLat(getJSObject(), ll.getJSObject(),
 				inclusive);
 	}
+    
+    /**
+     * Determine whether the target bounds intersects this bounds.  Bounds are considered intersecting if any of 
+     * their edges intersect or if one bounds contains the other.
+     * @param bounds the target bounds
+     * @return whether the passed-in bounds object intersects this bounds
+     */
+    public boolean intersectsBounds(Bounds bounds) {
+        return BoundsImpl.intersectsBounds(this.getJSObject(), bounds.getJSObject());
+    }
 }

File gwt-openlayers-client/src/main/java/org/gwtopenmaps/openlayers/client/BoundsImpl.java

 /**
  *
  * @author Erdem Gunay
- *
+ * @author Jon Britton, SpiffyMap Ltd.
  */
 class BoundsImpl {
 
 	public static native JSObject create(double lllon, double lllat, double urlon, double urlat)/*-{
 		return new $wnd.OpenLayers.Bounds(lllon, lllat, urlon, urlat);
 	}-*/;
+    
+    public static native JSObject create()/*-{
+		return new $wnd.OpenLayers.Bounds();
+	}-*/;
 
 	public static native JSObject toArray(JSObject bounds)/*-{
 		return bounds.toArray();
 	public static native JSObject getCenterLonLat(JSObject bounds)/*-{
     	return bounds.getCenterLonLat();
     }-*/;
+    
+    public static native JSObject getCenterPixel(JSObject bounds)/*-{
+    	return bounds.getCenterPixel();
+    }-*/;
 
 	public static native JSObject toGeometry(JSObject bounds)/*-{
 	   return bounds.toGeometry();
     public static native boolean containsLonLat(JSObject bounds, JSObject ll, boolean inclusive)/*-{
         return bounds.containsLonLat(ll, inclusive);
     }-*/;
+
+    public static native JSObject getSize(JSObject bounds)/*-{
+        return bounds.getSize();
+    }-*/;
+    
+    public static native JSObject scale(JSObject bounds, float ratio, JSObject origin)/*-{
+        return bounds.scale(ratio, origin);
+    }-*/;
+    
+    public static native JSObject add(JSObject bounds, float x, float y)/*-{
+        return bounds.add(x, y);
+    }-*/;
+    
+    public static native boolean intersectsBounds(JSObject bounds, JSObject otherBounds)/*-{
+        return bounds.intersectsBounds(otherBounds);
+    }-*/;
+
 }

File gwt-openlayers-client/src/test/java/org/gwtopenmaps/test/openlayers/client/basetypes/BoundsTest.java

 public class BoundsTest extends BaseTestCase
 {
 
-    public void testBounds()
-    {
+    public void testBounds() {
         Bounds bounds = new Bounds(0, 0, 4, 4);
         assertEquals("OpenLayers.Bounds", bounds.getClassName());