Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Don't wrap LatLngBounds #13540

Merged
merged 3 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class GeometryConstants {
/**
* This constant represents the lowest longitude value available to represent a geolocation.
*/
public static final double MIN_LONGITUDE = Double.NEGATIVE_INFINITY;
public static final double MIN_LONGITUDE = Double.MIN_VALUE;

/**
* This constant represents the highest longitude value available to represent a geolocation.
*/
public static final double MAX_LONGITUDE = Double.POSITIVE_INFINITY;
public static final double MAX_LONGITUDE = Double.MAX_VALUE;

/**
* This constant represents the lowest latitude value available to represent a geolocation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public LatLng[] toLatLngs() {
* otherwise IllegalArgumentException will be thrown.
* latNorth should be greater or equal latSouth, otherwise IllegalArgumentException will be thrown.
* <p>
* This method doesn't recalculate most east or most west boundaries.
* Note @since 7.0.0 lonEast and lonWest will NOT be wrapped to be in the range of [-180, 180],
* see {@link GeometryConstants#MIN_LONGITUDE} and {@link GeometryConstants#MAX_LONGITUDE}
* lonEast should be greater or equal lonWest, otherwise IllegalArgumentException will be thrown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,20 @@ public void intersectSouthCheck() {
public void intersectSouthLessThanNorthCheck() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("latNorth cannot be less than latSouth");

LatLngBounds intersectLatLngBounds =
LatLngBounds.from(10, 10, 0, 0)
.intersect(0, 200, 20, 0);
}


@Test
public void intersectEastLessThanWestCheck() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("lonEast cannot be less than lonWest");
LatLngBounds intersectLatLngBounds =
LatLngBounds.from(10, -10, 0, 0)
.intersect(0, 200, 20, 0);
}

public void intersectEastDoesNotWrapCheck() {

LatLngBounds latLngBounds1 = LatLngBounds.from(10, 210, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.feature.QueryRenderedFeaturesBoxHighlightActivity;

import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;

import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
Expand All @@ -18,7 +19,7 @@
import com.mapbox.mapboxsdk.testapp.R;

/**
* Test activity showcasing restricting user gestures to a bounds around Iceland.
* Test activity showcasing restricting user gestures to a bounds around Iceland, almost worldview and IDL.
*/
public class LatLngBoundsForCameraActivity extends AppCompatActivity implements OnMapReadyCallback {

Expand All @@ -27,6 +28,16 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements
.include(new LatLng(62.985661, -12.626277))
.build();

private static final LatLngBounds ALMOST_WORLD_BOUNDS = new LatLngBounds.Builder()
.include(new LatLng(20.0, 170.0))
.include(new LatLng(-20, -170.0))
.build();

private static final LatLngBounds CROSS_IDL_BOUNDS = new LatLngBounds.Builder()
.include(new LatLng(20.0, 170.0))
.include(new LatLng(-20, 190.0))
.build();

private MapView mapView;
private MapboxMap mapboxMap;

Expand All @@ -35,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_restricted_bounds);

mapView = (MapView) findViewById(R.id.mapView);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
Expand All @@ -44,18 +55,43 @@ protected void onCreate(Bundle savedInstanceState) {
public void onMapReady(@NonNull MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.SATELLITE_STREETS);
mapboxMap.setLatLngBoundsForCameraTarget(ICELAND_BOUNDS);
mapboxMap.setMinZoomPreference(2);
showBoundsArea();
mapboxMap.getUiSettings().setFlingVelocityAnimationEnabled(false);
showCrosshair();
setupBounds(ICELAND_BOUNDS);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_bounds, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_action_allmost_world_bounds:
setupBounds(ALMOST_WORLD_BOUNDS);
return true;
case R.id.menu_action_cross_idl:
setupBounds(CROSS_IDL_BOUNDS);
return true;
}
return super.onOptionsItemSelected(item);
}

private void setupBounds(LatLngBounds bounds) {
mapboxMap.setLatLngBoundsForCameraTarget(bounds);
showBoundsArea(bounds);
}

private void showBoundsArea() {
private void showBoundsArea(LatLngBounds bounds) {
mapboxMap.clear();
PolygonOptions boundsArea = new PolygonOptions()
.add(ICELAND_BOUNDS.getNorthWest())
.add(ICELAND_BOUNDS.getNorthEast())
.add(ICELAND_BOUNDS.getSouthEast())
.add(ICELAND_BOUNDS.getSouthWest());
.add(bounds.getNorthWest())
.add(bounds.getNorthEast())
.add(bounds.getSouthEast())
.add(bounds.getSouthWest());
boundsArea.alpha(0.25f);
boundsArea.fillColor(Color.RED);
mapboxMap.addPolygon(boundsArea);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_action_allmost_world_bounds"
android:title="@string/restrict_almost_worldview"
app:showAsAction="never"/>
<item
android:id="@+id/menu_action_cross_idl"
android:title="@string/restrict_across_idl"
app:showAsAction="never"/>
</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@
<string name="zoom_by_2">Zoom by 2</string>
<string name="zoom_to_point">Zoom to point</string>
<string name="zoom_to_4">Zoom to 4</string>
<string name="restrict_almost_worldview">Restrict almost worldview</string>
<string name="restrict_across_idl">Restrict across IDL</string>
</resources>