add setSetVisibleCoordinateBounds api as already in iOS

This commit is contained in:
Manabu-GT
2015-10-05 02:57:26 +09:00
committed by Manabu Shimobe
parent 927b4c6dbe
commit 84c8d1fd6e
9 changed files with 257 additions and 21 deletions

View File

@@ -0,0 +1,31 @@
package com.mapbox.mapboxsdk.geometry;
/**
* Implementation of iOS MGLCoordinateBounds
*/
public class CoordinateBounds {
private LatLng sw;
private LatLng ne;
public CoordinateBounds(LatLng sw, LatLng ne) {
this.sw = sw;
this.ne = ne;
}
public LatLng getSw() {
return sw;
}
public void setSw(LatLng sw) {
this.sw = sw;
}
public LatLng getNe() {
return ne;
}
public void setNe(LatLng ne) {
this.ne = ne;
}
}

View File

@@ -68,6 +68,7 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
import com.mapbox.mapboxsdk.exceptions.SpriteBitmapChangedException;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.utils.ApiAccess;
@@ -1981,6 +1982,42 @@ public final class MapView extends FrameLayout {
}
}
}
//
// Camera
//
public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds) {
setVisibleCoordinateBounds(bounds, false);
}
public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, boolean animated) {
setVisibleCoordinateBounds(bounds, new RectF(), animated);
}
public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, @NonNull RectF padding, boolean animated) {
LatLng[] coordinates = {
new LatLng(bounds.getNe().getLatitude(), bounds.getSw().getLongitude()),
bounds.getSw(),
new LatLng(bounds.getSw().getLatitude(), bounds.getNe().getLongitude()),
bounds.getNe()
};
setVisibleCoordinateBounds(coordinates, padding, animated);
}
public void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, boolean animated) {
setVisibleCoordinateBounds(coordinates, padding, getDirection(), animated);
}
private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, boolean animated) {
setVisibleCoordinateBounds(coordinates, padding, direction, animated ? ANIMATION_DURATION : 0l);
}
private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
mNativeMapView.setVisibleCoordinateBounds(coordinates, new RectF(padding.left / mScreenDensity,
padding.top / mScreenDensity, padding.right / mScreenDensity, padding.bottom / mScreenDensity),
direction, duration);
}
/**
* Gets the currently selected marker.

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.views;
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.Surface;
import com.mapbox.mapboxsdk.annotations.Marker;
@@ -384,6 +385,10 @@ final class NativeMapView {
nativeSetSprite(mNativeMapViewPtr, symbol, width, height, scale, pixels);
}
public void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
nativeSetVisibleCoordinateBounds(mNativeMapViewPtr, coordinates, padding, direction, duration);
}
public void onLowMemory() {
nativeOnLowMemory(mNativeMapViewPtr);
}
@@ -477,7 +482,7 @@ final class NativeMapView {
private native void nativeTerminateContext(long nativeMapViewPtr);
private native void nativeCreateSurface(long nativeMapViewPtr,
Surface surface);
Surface surface);
private native void nativeDestroySurface(long nativeMapViewPtr);
@@ -502,7 +507,7 @@ final class NativeMapView {
private native boolean nativeHasClass(long nativeMapViewPtr, String clazz);
private native void nativeSetClasses(long nativeMapViewPtr,
List<String> classes);
List<String> classes);
private native List<String> nativeGetClasses(long nativeMapViewPtr);
@@ -514,7 +519,7 @@ final class NativeMapView {
private native void nativeSetStyleUrl(long nativeMapViewPtr, String url);
private native void nativeSetStyleJson(long nativeMapViewPtr,
String newStyleJson, String base);
String newStyleJson, String base);
private native String nativeGetStyleJson(long nativeMapViewPtr);
@@ -527,7 +532,7 @@ final class NativeMapView {
private native void nativeSetGestureInProgress(long nativeMapViewPtr, boolean inProgress);
private native void nativeMoveBy(long nativeMapViewPtr, double dx,
double dy, long duration);
double dy, long duration);
private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng,
long duration);
@@ -537,10 +542,10 @@ final class NativeMapView {
private native void nativeResetPosition(long nativeMapViewPtr);
private native void nativeScaleBy(long nativeMapViewPtr, double ds,
double cx, double cy, long duration);
double cx, double cy, long duration);
private native void nativeSetScale(long nativeMapViewPtr, double scale,
double cx, double cy, long duration);
double cx, double cy, long duration);
private native double nativeGetScale(long nativeMapViewPtr);
@@ -550,7 +555,7 @@ final class NativeMapView {
private native double nativeGetZoom(long nativeMapViewPtr);
private native void nativeSetLatLngZoom(long nativeMapViewPtr,
LatLngZoom lonLatZoom, long duration);
LatLngZoom lonLatZoom, long duration);
private native LatLngZoom nativeGetLatLngZoom(long nativeMapViewPtr);
@@ -561,13 +566,13 @@ final class NativeMapView {
private native double nativeGetMaxZoom(long nativeMapViewPtr);
private native void nativeRotateBy(long nativeMapViewPtr, double sx,
double sy, double ex, double ey, long duration);
double sy, double ex, double ey, long duration);
private native void nativeSetBearing(long nativeMapViewPtr, double degrees,
long duration);
long duration);
private native void nativeSetBearing(long nativeMapViewPtr, double degrees,
double cx, double cy);
double cx, double cy);
private native double nativeGetBearing(long nativeMapViewPtr);
@@ -592,6 +597,8 @@ final class NativeMapView {
private native void nativeSetSprite(long nativeMapViewPtr, String symbol,
int width, int height, float scale, byte[] pixels);
private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, LatLng[] coordinates, RectF padding, double direction, long duration);
private native void nativeOnLowMemory(long nativeMapViewPtr);
private native void nativeSetDebug(long nativeMapViewPtr, boolean debug);

View File

@@ -4,6 +4,7 @@ import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.RectF;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
@@ -21,10 +22,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.crashlytics.android.Crashlytics;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
@@ -32,6 +31,7 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.annotations.Sprite;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
@@ -196,7 +196,6 @@ public class MainActivity extends AppCompatActivity {
mSelectedStyle = savedInstanceState.getInt(STATE_SELECTED_STYLE);
}
// Set default UI state
mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mMapView.isCompassEnabled());
mNavigationView.getMenu().findItem(R.id.action_debug).setChecked(mMapView.isDebugActive());
@@ -333,6 +332,13 @@ public class MainActivity extends AppCompatActivity {
startActivity(new Intent(getApplicationContext(), InfoWindowActivity.class));
return true;
case R.id.action_visible_bounds:
// Set visible bounds to Moscone Center West (37.783703, -122.403589) and Union Square (37.7874436,-122.4072359)
mMapView.setVisibleCoordinateBounds(
new CoordinateBounds(new LatLng(37.783703, -122.403589), new LatLng(37.7874436,-122.4072359)),
new RectF(100, 350, 100, 300), true);
return true;
default:
return changeMapStyle(menuItem.getItemId());
}
@@ -389,9 +395,13 @@ public class MainActivity extends AppCompatActivity {
*/
private void toggleGps(boolean enableGps) {
if (enableGps) {
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_LOCATION);
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) ||
(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED)) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSIONS_LOCATION);
} else {
enableGps();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

View File

@@ -92,11 +92,15 @@
android:icon="@drawable/ic_filter_none_white_24dp"
android:title="@string/action_info_window_adapter" />
<item
android:id="@+id/action_press_for_marker"
<item android:id="@+id/action_press_for_marker"
android:checkable="false"
android:icon="@drawable/ic_pin_drop_white_24dp"
android:title="@string/action_press_for_marker"/>
<item android:id="@+id/action_visible_bounds"
android:checkable="false"
android:icon="@drawable/ic_pin_drop_white_24dp"
android:title="@string/action_press_for_marker"/>
android:icon="@drawable/ic_action_crop"
android:title="@string/action_visible_bounds"/>
</menu>
</item>

View File

@@ -23,6 +23,7 @@
<string name="action_map_fragment">MapFragment</string>
<string name="action_press_for_marker">Press For Marker</string>
<string name="action_info_window">InfoWindow</string>
<string name="action_visible_bounds">Set Visible Bounds</string>
<string name="label_fps">FPS:</string>