CameraUpdateHandler { public void moveCamera(CameraUpdate cameraUpdate) { final OsmCameraUpdate osmCameraUpdate = (OsmCameraUpdate) cameraUpdate; final IMapController controller = map.getController(); if (osmCameraUpdate.bounds != null) { final LatLng center = osmCameraUpdate.bounds.getCenter(); controller.setZoom(map.getMaxZoomLevel()); controller.zoomToSpan( (int) ((osmCameraUpdate.bounds.northeast.latitude - osmCameraUpdate.bounds.southwest.latitude) * 1e6), (int) ((osmCameraUpdate.bounds.northeast.longitude - osmCameraUpdate.bounds.southwest.longitude) * 1e6) ); controller.setCenter( toGeoPoint(center) ); return; } if (osmCameraUpdate.zoom != null) { controller.setZoom(osmCameraUpdate.zoom.intValue()); } if (osmCameraUpdate.center != null) { controller.setCenter( toGeoPoint(osmCameraUpdate.center) ); } } CameraUpdateHandler(MapView map); void moveCamera(CameraUpdate cameraUpdate); void animateCamera(CameraUpdate cameraUpdate); void animateCamera(CameraUpdate cameraUpdate, AnyMap.CancelableCallback callback); void animateCamera(CameraUpdate cameraUpdate, int duration, AnyMap.CancelableCallback callback);  }
@Test public void testMoveCameraToPosition() throws Exception { CameraUpdateHandler handler = new CameraUpdateHandler(map); final LatLng center = new LatLng(10, 10); OsmCameraUpdate cameraUpdate = new OsmCameraUpdate.Builder() .center(center) .build(); handler.moveCamera(cameraUpdate); verify(mapController).setCenter(eq(toGeoPoint(center))); verifyNoMoreInteractions(mapController); }
@Test public void testMoveCameraToPositionWithZoom() throws Exception { CameraUpdateHandler handler = new CameraUpdateHandler(map); final LatLng center = new LatLng(10, 10); final int zoomLevel = 10; OsmCameraUpdate cameraUpdate = new OsmCameraUpdate.Builder() .center(center) .zoom((float) zoomLevel) .build(); handler.moveCamera(cameraUpdate); verify(mapController).setCenter(eq(toGeoPoint(center))); verify(mapController).setZoom(zoomLevel); verifyNoMoreInteractions(mapController); }
@Test public void testMoveCameraToBounds() throws Exception { CameraUpdateHandler handler = new CameraUpdateHandler(map); final LatLngBounds bounds = new LatLngBounds( new LatLng(10, 10), new LatLng(20, 20) ); OsmCameraUpdate cameraUpdate = new OsmCameraUpdate.Builder() .bounds(bounds) .build(); handler.moveCamera(cameraUpdate); verify(mapController).setCenter(eq( toGeoPoint(bounds.getCenter()) )); verify(mapController).zoomToSpan( eq((int) (10 * 1e6)), eq((int) (10 * 1e6)) ); }