public static Projection convert(LatLngBounds bound) { return new BaiduProjection( new VisibleRegion( new com.car2go.maps.model.LatLngBounds( BaiduToModelConverter.convert(bound.southwest), BaiduToModelConverter.convert(bound.northeast) ) ) ); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof VisibleRegion)) { return false; } VisibleRegion that = (VisibleRegion) o; return latLngBounds.equals(that.latLngBounds); }
@Override public int hashCode() { return latLngBounds.hashCode(); }
@Test public void testMoveCameraToBounds() throws Exception { // Given 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(); // When handler.moveCamera(cameraUpdate); // Then verify(mapController).setCenter(eq( toGeoPoint(bounds.getCenter()) )); verify(mapController).zoomToSpan( eq((int) (10 * 1e6)), eq((int) (10 * 1e6)) ); }
/** * @see AnyMap#moveCamera(CameraUpdate) */ 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) ); } }
@Override public com.car2go.maps.model.LatLngBounds map(LatLngBounds input) { LatLng southWest = AnyMapAdapter.adapt(input.southwest); LatLng northEast = AnyMapAdapter.adapt(input.northeast); return new com.car2go.maps.model.LatLngBounds(southWest, northEast); }
/** * @return new instance of {@link LatLngBounds} * @throws IllegalStateException if less than 2 unique points were specified */ public LatLngBounds build() { if (Double.isNaN(southWestLongitude)) { throw new IllegalStateException("No included points"); } return new LatLngBounds( new LatLng(southWestLattitude, southWestLongitude), new LatLng(northEastLattitude, northEastLongitude) ); }
@Override public Projection getProjection() { org.osmdroid.views.Projection projection = map.getProjection(); return new OsmProjection( new VisibleRegion( new LatLngBounds( new LatLng( projection.getSouthWest().getLatitude(), projection.getSouthWest().getLongitude() ), new LatLng( projection.getNorthEast().getLatitude(), projection.getNorthEast().getLongitude() ) ) ) ); }
@Test public void testMap() throws Exception { // Given LatLngBoundsMapper mapper = new LatLngBoundsMapper(); LatLngBounds input = new LatLngBounds( new LatLng(10, 10), new LatLng(20, 20) ); // When com.google.android.gms.maps.model.LatLngBounds output = mapper.map(input); // Then TestUtil.assertEquals( input.southwest, output.southwest ); TestUtil.assertEquals( input.northeast, output.northeast ); }