[android] #3145 - MapboxMap

This commit is contained in:
Tobrun
2016-01-11 11:32:00 +01:00
parent 710398b780
commit 8ed1dc9f74
87 changed files with 4587 additions and 3037 deletions

View File

@@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.annotations;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Annotation is a overlay on top of a {@link MapView},
@@ -21,7 +22,7 @@ public abstract class Annotation implements Comparable<Annotation> {
* Internal C++ id is stored as unsigned int.
*/
private long id = -1; // -1 unless added to a MapView
private MapView mapView;
private MapboxMap mapboxMap;
protected Annotation() {
}
@@ -38,10 +39,10 @@ public abstract class Annotation implements Comparable<Annotation> {
}
public void remove() {
if (mapView == null) {
if (mapboxMap == null) {
return;
}
mapView.removeAnnotation(this);
mapboxMap.removeAnnotation(this);
}
/**
@@ -54,15 +55,12 @@ public abstract class Annotation implements Comparable<Annotation> {
/**
* Do not use this method. Used internally by the SDK.
*/
public void setMapView(MapView mapView) {
this.mapView = mapView;
public void setMapboxMap(MapboxMap mapView) {
this.mapboxMap = mapView;
}
protected MapView getMapView() {
if (mapView == null) {
return null;
}
return mapView;
protected MapboxMap getMapboxMap() {
return mapboxMap;
}
@Override

View File

@@ -2,8 +2,10 @@ package com.mapbox.mapboxsdk.annotations;
import android.graphics.Bitmap;
import com.mapbox.mapboxsdk.maps.MapView;
/**
* Icon is the visual representation of a {@link Marker} on a {@link com.mapbox.mapboxsdk.views.MapView}.
* Icon is the visual representation of a {@link Marker} on a {@link MapView}.
* @see Marker
*/
public final class Icon {

View File

@@ -9,9 +9,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.lang.ref.WeakReference;
@@ -26,7 +27,7 @@ import java.lang.ref.WeakReference;
public class InfoWindow {
private WeakReference<Marker> mBoundMarker;
private WeakReference<MapView> mMapView;
private WeakReference<MapboxMap> mMapboxMap;
protected WeakReference<View> mView;
private float mMarkerHeightOffset;
@@ -37,18 +38,18 @@ public class InfoWindow {
@LayoutRes
private int mLayoutRes;
InfoWindow(int layoutResId, MapView mapView) {
InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) {
mLayoutRes = layoutResId;
View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false);
initialize(view, mapView);
initialize(view, mapboxMap);
}
InfoWindow(View view, MapView mapView) {
initialize(view, mapView);
InfoWindow(View view, MapboxMap mapboxMap) {
initialize(view, mapboxMap);
}
private void initialize(View view, MapView mapView) {
mMapView = new WeakReference<>(mapView);
private void initialize(View view, MapboxMap mapboxMap) {
mMapboxMap = new WeakReference<>(mapboxMap);
mIsVisible = false;
mView = new WeakReference<>(view);
@@ -58,8 +59,8 @@ public class InfoWindow {
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_UP) {
boolean handledDefaultClick = false;
MapView.OnInfoWindowClickListener onInfoWindowClickListener =
mMapView.get().getOnInfoWindowClickListener();
MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener =
mMapboxMap.get().getOnInfoWindowClickListener();
if (onInfoWindowClickListener != null) {
handledDefaultClick = onInfoWindowClickListener.onMarkerClick(getBoundMarker());
}
@@ -88,15 +89,17 @@ public class InfoWindow {
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT);
MapboxMap mapboxMap = mMapboxMap.get();
View view = mView.get();
if (view != null) {
if (view != null && mapboxMap != null) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// Calculate y-offset for update method
mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY;
// Calculate default Android x,y coordinate
mCoordinates = mapView.toScreenLocation(position);
mCoordinates = mapboxMap.toScreenLocation(position);
float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - view.getMeasuredHeight() + offsetY;
@@ -191,13 +194,13 @@ public class InfoWindow {
*
* @param overlayItem the tapped overlay item
*/
void adaptDefaultMarker(Marker overlayItem, MapView mapView) {
void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) {
View view = mView.get();
if (view == null) {
view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false);
initialize(view, mapView);
initialize(view, mapboxMap);
}
mMapView = new WeakReference<>(mapView);
mMapboxMap = new WeakReference<>(mapboxMap);
String title = overlayItem.getTitle();
((TextView) view.findViewById(R.id.infowindow_title)).setText(title);
String snippet = overlayItem.getSnippet();
@@ -205,7 +208,10 @@ public class InfoWindow {
}
private void onClose() {
mMapView.get().deselectMarker(getBoundMarker());
MapboxMap mapboxMap = mMapboxMap.get();
if (mapboxMap != null) {
mapboxMap.deselectMarker(getBoundMarker());
}
}
InfoWindow setBoundMarker(Marker boundMarker) {
@@ -221,11 +227,11 @@ public class InfoWindow {
}
public void update() {
MapView mapView = mMapView.get();
MapboxMap mapboxMap = mMapboxMap.get();
Marker marker = mBoundMarker.get();
View view = mView.get();
if (mapView != null && marker != null && view != null) {
mCoordinates = mapView.toScreenLocation(marker.getPosition());
if (mapboxMap != null && marker != null && view != null) {
mCoordinates = mapboxMap.toScreenLocation(marker.getPosition());
view.setX(mCoordinates.x + mViewWidthOffset);
view.setY(mCoordinates.y + mMarkerHeightOffset);
}

View File

@@ -4,15 +4,16 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
/**
* Marker is an annotation that shows an icon image at a geographical location.
* </p>
* An {@link InfoWindow} can be shown when a Marker is pressed
* <p>
* <p/>
*/
public final class Marker extends Annotation {
@@ -55,8 +56,6 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
*
* @return boolean State of a InfoWindow
*/
public boolean isInfoWindowShown() {
return infoWindowShown;
@@ -72,8 +71,6 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
*
* @param icon The icon to be used as Marker image
*/
public void setIcon(@Nullable Icon icon) {
this.icon = icon;
@@ -89,25 +86,25 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
*
* @param mapView The MapView to show the InfoWindow on.
* @return infoWindow The infoWindow to show
*/
public InfoWindow showInfoWindow(@NonNull MapView mapView) {
setMapView(mapView);
MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter();
public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) {
setMapboxMap(mapboxMap);
MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter();
if (infoWindowAdapter != null) {
// end developer is using a custom InfoWindowAdapter
View content = infoWindowAdapter.getInfoWindow(this);
if (content != null) {
infoWindow = new InfoWindow(content, getMapView());
infoWindow = new InfoWindow(content, mapboxMap);
showInfoWindow(infoWindow, mapView);
return infoWindow;
}
}
getInfoWindow().adaptDefaultMarker(this, mapView);
return showInfoWindow(getInfoWindow(), mapView);
InfoWindow infoWindow = getInfoWindow(mapView);
if (mapView.getContext() != null) {
infoWindow.adaptDefaultMarker(this, mapboxMap, mapView);
}
return showInfoWindow(infoWindow, mapView);
}
private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) {
@@ -116,27 +113,15 @@ public final class Marker extends Annotation {
return iw;
}
private InfoWindow getInfoWindow() {
if (infoWindow == null) {
infoWindow = new InfoWindow(R.layout.infowindow_view, getMapView());
private InfoWindow getInfoWindow(@NonNull MapView mapView) {
if (infoWindow == null && mapView.getContext() != null) {
infoWindow = new InfoWindow(mapView, R.layout.infowindow_view, getMapboxMap());
}
return infoWindow;
}
/*
@Override
void setVisible(boolean visible) {
super.setVisible(visible);
if (!visible && infoWindowShown) {
hideInfoWindow();
}
}
*/
/**
* Do not use this method. Used internally by the SDK.
*
* @param topOffsetPixels the pixels to have as offset
*/
public void setTopOffsetPixels(int topOffsetPixels) {
this.topOffsetPixels = topOffsetPixels;

View File

@@ -1,9 +1,17 @@
package com.mapbox.mapboxsdk.camera;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MathConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.utils.MathUtils;
public final class CameraPosition implements Parcelable {
@@ -44,35 +52,22 @@ public final class CameraPosition implements Parcelable {
public final float zoom;
/**
*
* Constructs a CameraPosition.
* @param target The target location to align with the center of the screen.
* @param zoom Zoom level at target. See zoom(float) for details of restrictions.
* @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
*
* @param target The target location to align with the center of the screen.
* @param zoom Zoom level at target. See zoom(float) for details of restrictions.
* @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
* @param bearing Direction that the camera is pointing in, in degrees clockwise from north. This value will be normalized to be within 0 degrees inclusive and 360 degrees exclusive.
* @throws NullPointerException if target is null
* @throws NullPointerException if target is null
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
*/
public CameraPosition (LatLng target, float zoom, float tilt, float bearing) throws NullPointerException, IllegalArgumentException{
super();
if (target == null) {
throw new NullPointerException("target is NULL");
}
CameraPosition(LatLng target, float zoom, float tilt, float bearing) {
this.target = target;
// Allow for default value of -1
if (tilt != -1) {
if (tilt < 0.0f || tilt > 90.0f) {
throw new IllegalArgumentException("tilt is outside of 0 to 90 degrees range");
}
}
this.tilt = tilt;
this.bearing = bearing;
this.tilt = tilt;
this.zoom = zoom;
}
@Override
public int describeContents() {
return 0;
@@ -86,6 +81,36 @@ public final class CameraPosition implements Parcelable {
out.writeFloat(zoom);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CameraPosition cameraPosition = (CameraPosition) o;
if (!target.equals(cameraPosition.target)) {
return false;
} else if (zoom != cameraPosition.zoom) {
return false;
} else if (tilt != cameraPosition.tilt) {
return false;
} else if (bearing != cameraPosition.bearing) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = 1;
result = 31 * result + (target != null ? target.hashCode() : 0);
return result;
}
/**
* Builds camera position.
*/
@@ -105,6 +130,7 @@ public final class CameraPosition implements Parcelable {
/**
* Create Builder with an existing CameraPosition data.
*
* @param previous Existing CameraPosition values to use
*/
public Builder(CameraPosition previous) {
@@ -117,18 +143,65 @@ public final class CameraPosition implements Parcelable {
}
}
/**
* Create Builder with an existing CameraPosition data.
*
* @param typedArray TypedArray containgin attribute values
*/
public Builder(TypedArray typedArray){
super();
if(typedArray!=null) {
this.bearing = typedArray.getFloat(R.styleable.MapView_direction, 0.0f);
double lat = typedArray.getFloat(R.styleable.MapView_center_latitude, 0.0f);
double lng = typedArray.getFloat(R.styleable.MapView_center_longitude, 0.0f);
this.target= new LatLng(lat, lng);
this.tilt = typedArray.getFloat(R.styleable.MapView_tilt, 0.0f);
this.zoom = typedArray.getFloat(R.styleable.MapView_zoom, 0.0f);
}
}
/**
* Create Builder from an existing PositionCameraUpdate update.
*
* @param update Update containing camera options
*/
public Builder(CameraUpdateFactory.PositionCameraUpdate update) {
super();
if (update != null) {
this.bearing = update.getBearing();
this.target = update.getTarget();
this.tilt = update.getTilt();
this.zoom = update.getZoom();
}
}
/**
* Create Builder from an existing PositionCameraUpdate update.
*
* @param update Update containing camera options
*/
public Builder(CameraUpdateFactory.ZoomUpdate update){
super();
if(update!=null){
this.zoom = update.getZoom();
}
}
/**
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
*
* @param bearing Bearing
* @return Builder
*/
public Builder bearing (float bearing) {
this.bearing = bearing;
public Builder bearing(float bearing) {
this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
return this;
}
/**
* Builds a CameraPosition.
*
* @return CameraPosition
*/
public CameraPosition build() {
@@ -137,6 +210,7 @@ public final class CameraPosition implements Parcelable {
/**
* Sets the location that the camera is pointing at.
*
* @param location Location
* @return Builder
*/
@@ -147,17 +221,19 @@ public final class CameraPosition implements Parcelable {
/**
* Set the tilt
*
* @param tilt Tilt value
* @return Builder
*/
@FloatRange(from = 0.0, to = 60.0)
public Builder tilt(float tilt) {
this.tilt = tilt;
this.tilt = (float) (MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT) * MathConstants.DEG2RAD);
return this;
}
/**
* Set the zoom
*
* @param zoom Zoom value
* @return Builder
*/

View File

@@ -1,56 +1,5 @@
package com.mapbox.mapboxsdk.camera;
import com.mapbox.mapboxsdk.geometry.LatLng;
public interface CameraUpdate {
public final class CameraUpdate {
/**
* Direction that the camera is pointing in, in degrees clockwise from north.
*/
private final float bearing;
/**
* The location that the camera is pointing at.
*/
private final LatLng target;
/**
* The angle, in degrees, of the camera angle from the nadir (directly facing the Earth). See tilt(float) for details of restrictions on the range of values.
*/
private final float tilt;
/**
* Zoom level near the center of the screen. See zoom(float) for the definition of the camera's zoom level.
*/
private final float zoom;
/**
* Package Private Constructor to only be used CameraUpdateFactory
* @param bearing Final Bearing
* @param target Final Target
* @param tilt Final Tilt
* @param zoom Final Zoom
*/
CameraUpdate(float bearing, LatLng target, float tilt, float zoom) {
this.bearing = bearing;
this.target = target;
this.tilt = tilt;
this.zoom = zoom;
}
public float getBearing() {
return bearing;
}
public LatLng getTarget() {
return target;
}
public float getTilt() {
return tilt;
}
public float getZoom() {
return zoom;
}
}

View File

@@ -1,15 +1,225 @@
package com.mapbox.mapboxsdk.camera;
import android.graphics.Point;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class CameraUpdateFactory {
/**
* Returns a CameraUpdate that moves the camera to a specified CameraPosition.
*
* @param cameraPosition Camera Position to change to
* @return CameraUpdate Final Camera Position data
*/
public static CameraUpdate newCameraPosition (@NonNull CameraPosition cameraPosition) {
return new CameraUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
public static CameraUpdate newCameraPosition(@NonNull CameraPosition cameraPosition) {
return new PositionCameraUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
}
/**
* Returns a CameraUpdate that moves the center of the screen to a latitude and longitude
* specified by a LatLng object. This centers the camera on the LatLng object.
*
* @param latLng
* @return
*/
public static CameraUpdate newLatLng(@NonNull LatLng latLng) {
return new PositionCameraUpdate(-1, latLng, -1, -1);
}
/**
* Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
* bounds are centered on screen at the greatest possible zoom level.
* You can specify padding, in order to inset the bounding box from the map view's edges.
* The returned CameraUpdate has a bearing of 0 and a tilt of 0.
*
* @param bounds
* @param padding
* @return
*/
public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int padding) {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
* bounds are centered on screen within a bounding box of specified dimensions at the greatest
* possible zoom level. You can specify additional padding, to further restrict the size of
* the bounding box. The returned CameraUpdate has a bearing of 0 and a tilt of 0.
*
* @param bounds
* @param width
* @param height
* @param padding
* @return
*/
public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int width, int height, int padding) {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.
*
* @param latLng
* @param zoom
* @return
*/
public static CameraUpdate newLatLngZoom(@NonNull LatLng latLng, float zoom) {
return new PositionCameraUpdate(-1, latLng, -1, zoom);
}
/**
* Returns a CameraUpdate that scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y directions.
*
* @param xPixel
* @param yPixel
* @return
*/
public static CameraUpdate scrollBy(float xPixel, float yPixel) {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
*
* @param amount
* @param focus
* @return
*/
public static CameraUpdate zoomBy(float amount, Point focus) {
return new ZoomUpdate(ZoomUpdate.ZOOM_TO_POINT, focus.x, focus.y);
}
/**
* Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
*
* @param amount
* @return
*/
public static CameraUpdate zoomBy(float amount) {
return new ZoomUpdate(ZoomUpdate.ZOOM_BY, amount);
}
/**
* Returns a CameraUpdate that zooms in on the map by moving the viewpoint's height closer to the Earth's surface. The zoom increment is 1.0.
*
* @return
*/
public static CameraUpdate zoomIn() {
return new ZoomUpdate(ZoomUpdate.ZOOM_IN);
}
/**
* Returns a CameraUpdate that zooms out on the map by moving the viewpoint's height farther away from the Earth's surface. The zoom increment is -1.0.
*
* @return
*/
public static CameraUpdate zoomOut() {
return new ZoomUpdate(ZoomUpdate.ZOOM_OUT);
}
/**
* Returns a CameraUpdate that moves the camera viewpoint to a particular zoom level.
*
* @param zoom
* @return
*/
public static CameraUpdate zoomTo(float zoom) {
return new ZoomUpdate(ZoomUpdate.ZOOM_TO, zoom);
}
//
// CameraUpdate types
//
public static class PositionCameraUpdate implements CameraUpdate {
private final float bearing;
private final LatLng target;
private final float tilt;
private final float zoom;
PositionCameraUpdate(float bearing, LatLng target, float tilt, float zoom) {
this.bearing = bearing;
this.target = target;
this.tilt = tilt;
this.zoom = zoom;
}
public LatLng getTarget() {
return target;
}
public float getBearing() {
return bearing;
}
public float getTilt() {
return tilt;
}
public float getZoom() {
return zoom;
}
}
public static class ZoomUpdate implements CameraUpdate {
@IntDef({ZOOM_IN, ZOOM_OUT, ZOOM_BY, ZOOM_TO, ZOOM_TO_POINT})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
}
public static final int ZOOM_IN = 0;
public static final int ZOOM_OUT = 1;
public static final int ZOOM_BY = 2;
public static final int ZOOM_TO = 3;
public static final int ZOOM_TO_POINT = 4;
@Type
private final int type;
private final float zoom;
private float x;
private float y;
ZoomUpdate(@Type int type) {
this.type = type;
this.zoom = 0;
}
ZoomUpdate(@Type int type, float zoom) {
this.type = type;
this.zoom = zoom;
}
ZoomUpdate(float zoom, float x, float y) {
this.type = ZOOM_TO_POINT;
this.zoom = zoom;
this.x = x;
this.y = y;
}
public float getZoom() {
return zoom;
}
@Type
public int getType() {
return type;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
}
}

View File

@@ -17,4 +17,73 @@ public class MapboxConstants {
*/
public static final String KEY_META_DATA_MANIFEST = "com.mapbox.AccessToken";
/**
* Default animation time
*/
public static final int ANIMATION_DURATION = 300;
/**
* The currently supported minimum zoom level.
*/
public static final double MINIMUM_ZOOM = 0f;
/**
* The currently supported maximum zoom level.
*/
public static final double MAXIMUM_ZOOM = 25.0;
/**
* The currently supported maximum tilt value.
*/
public static final double MAXIMUM_TILT = 60;
/**
* The currently supported minimum tilt value.
*/
public static final double MINIMUM_TILT = 0;
/**
* The currently supported maximum direction
*/
public static final double MAXIMUM_DIRECTION = 360;
/**
* The currently supported minimum direction
*/
public static final double MINIMUM_DIRECTION = 0;
// Save instance state keys
public static final String STATE_CAMERA_POSITION = "cameraPosition";
public static final String STATE_ZOOM_ENABLED = "zoomEnabled";
public static final String STATE_SCROLL_ENABLED = "scrollEnabled";
public static final String STATE_ROTATE_ENABLED = "rotateEnabled";
public static final String STATE_TILT_ENABLED = "tiltEnabled";
public static final String STATE_ZOOM_CONTROLS_ENABLED = "zoomControlsEnabled";
public static final String STATE_DEBUG_ACTIVE = "debugActive";
public static final String STATE_STYLE_URL = "styleUrl";
public static final String STATE_ACCESS_TOKEN = "accessToken";
public static final String STATE_DEFAULT_TRANSITION_DURATION = "defaultTransitionDuration";
public static final String STATE_MY_LOCATION_ENABLED = "myLocationEnabled";
public static final String STATE_MY_LOCATION_TRACKING_MODE = "myLocationTracking";
public static final String STATE_MY_BEARING_TRACKING_MODE = "myBearingTracking";
public static final String STATE_COMPASS_ENABLED = "compassEnabled";
public static final String STATE_COMPASS_GRAVITY = "compassGravity";
public static final String STATE_COMPASS_MARGIN_LEFT = "compassMarginLeft";
public static final String STATE_COMPASS_MARGIN_TOP = "compassMarginTop";
public static final String STATE_COMPASS_MARGIN_RIGHT = "compassMarginRight";
public static final String STATE_COMPASS_MARGIN_BOTTOM = "compassMarginBottom";
public static final String STATE_LOGO_GRAVITY = "logoGravity";
public static final String STATE_LOGO_MARGIN_LEFT = "logoMarginLeft";
public static final String STATE_LOGO_MARGIN_TOP = "logoMarginTop";
public static final String STATE_LOGO_MARGIN_RIGHT = "logoMarginRight";
public static final String STATE_LOGO_MARGIN_BOTTOM = "logoMarginBottom";
public static final String STATE_LOGO_VISIBILITY = "logoVisibility";
public static final String STATE_ATTRIBUTION_GRAVITY = "attrGravity";
public static final String STATE_ATTRIBUTION_MARGIN_LEFT = "attrMarginLeft";
public static final String STATE_ATTRIBUTION_MARGIN_TOP = "attrMarginTop";
public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "attrMarginRight";
public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "atrrMarginBottom";
public static final String STATE_ATTRIBUTION_VISIBILITY = "atrrVisibility";
public static final String TAG = "MapboxMap";
}

View File

@@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.UserLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -11,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
* MyBearingTracking exposes different types bearing tracking modes.
*
* @see MapView#setMyBearingTrackingMode(int)
* @see com.mapbox.mapboxsdk.views.UserLocationView#setMyBearingTrackingMode(int)
* @see UserLocationView#setMyBearingTrackingMode(int)
*/
public class MyBearingTracking {

View File

@@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.UserLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -11,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
* MyLocationTracking exposes different types of locational tracking modes.
*
* @see MapView#setMyLocationTrackingMode(int)
* @see com.mapbox.mapboxsdk.views.UserLocationView#setMyLocationTrackingMode(int)
* @see UserLocationView#setMyLocationTrackingMode(int)
*/
public class MyLocationTracking {
@@ -29,7 +30,7 @@ public class MyLocationTracking {
public static final int TRACKING_NONE = 0x00000000;
/**
* Tracking the location of the user, {@link MapView} will reposition to center of {@link com.mapbox.mapboxsdk.views.UserLocationView}
* Tracking the location of the user, {@link MapView} will reposition to center of {@link UserLocationView}
*/
public static final int TRACKING_FOLLOW = 0x00000004;

View File

@@ -2,7 +2,7 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.StringDef;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View File

@@ -4,7 +4,7 @@ import android.graphics.Bitmap;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
/**
* <p>

View File

@@ -1,7 +1,7 @@
package com.mapbox.mapboxsdk.exceptions;
import android.os.Bundle;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
/**
* A {@code InvalidAccessTokenException} is thrown by {@link MapView} when there is either no access

View File

@@ -0,0 +1,296 @@
package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
/**
* An immutable class representing a latitude/longitude aligned rectangle.
*/
public class LatLngBounds implements Parcelable {
private final double mLatNorth;
private final double mLatSouth;
private final double mLonEast;
private final double mLonWest;
private final boolean mIsValid;
/**
* Construct a new LatLngBounds based on its corners, given in NESW
* order.
*
* @param northLatitude Northern Latitude
* @param eastLongitude Eastern Longitude
* @param southLatitude Southern Latitude
* @param westLongitude Western Longitude
*/
public LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
this.mLatNorth = northLatitude;
this.mLonEast = eastLongitude;
this.mLatSouth = southLatitude;
this.mLonWest = westLongitude;
this.mIsValid = ((this.mLonWest < this.mLonEast) && (this.mLatNorth > this.mLatSouth));
}
/**
* Construct a new LatLngBounds based on its corners, given in NESW order.
*
* @param northEast Coordinate
* @param southWest Coordinate
*/
public LatLngBounds(final LatLng northEast, final LatLng southWest) {
this(northEast.getLatitude(), northEast.getLongitude(), southWest.getLatitude(), southWest.getLongitude());
}
/**
* Create a LatLngBounds box from another LatLngBounds
*
* @param other the other LatLngBounds
*/
public LatLngBounds(final LatLngBounds other) {
this.mLatNorth = other.getLatNorth();
this.mLonEast = other.getLonEast();
this.mLatSouth = other.getLatSouth();
this.mLonWest = other.getLonWest();
this.mIsValid = other.isValid();
}
/**
* Calculates the centerpoint of this LatLngBounds by simple interpolation and returns
* it as a point. This is a non-geodesic calculation which is not the geographic center.
*
* @return LatLng center of this LatLngBounds
*/
public LatLng getCenter() {
return new LatLng((this.mLatNorth + this.mLatSouth) / 2,
(this.mLonEast + this.mLonWest) / 2);
}
public double getLatNorth() {
return this.mLatNorth;
}
public double getLatSouth() {
return this.mLatSouth;
}
public double getLonEast() {
return this.mLonEast;
}
public double getLonWest() {
return this.mLonWest;
}
public boolean isValid() {
return this.mIsValid;
}
/**
* Get the area spanned by this LatLngBounds
*
* @return CoordinateSpan area
*/
public CoordinateSpan getSpan() {
return new CoordinateSpan(getLatitudeSpan(), getLongitudeSpan());
}
/**
* Get the absolute distance, in degrees, between the north and
* south boundaries of this LatLngBounds
*
* @return Span distance
*/
public double getLatitudeSpan() {
return Math.abs(this.mLatNorth - this.mLatSouth);
}
/**
* Get the absolute distance, in degrees, between the west and
* east boundaries of this LatLngBounds
*
* @return Span distance
*/
public double getLongitudeSpan() {
return Math.abs(this.mLonEast - this.mLonWest);
}
/**
* Validate if LatLngBounds is empty, determined if absolute distance is
*
* @return boolean indicating if span is empty
*/
public boolean isEmpty() {
return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
}
@Override
public String toString() {
return "N:" + this.mLatNorth + "; E:" + this.mLonEast + "; S:" + this.mLatSouth + "; W:" + this.mLonWest;
}
/**
* Constructs a LatLngBounds that contains all of a list of LatLng
* objects. Empty lists will yield invalid LatLngBounds.
*
* @param latLngs List of LatLng objects
* @return LatLngBounds
*/
public static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
double minLat = 90,
minLon = 180,
maxLat = -90,
maxLon = -180;
for (final ILatLng gp : latLngs) {
final double latitude = gp.getLatitude();
final double longitude = gp.getLongitude();
minLat = Math.min(minLat, latitude);
minLon = Math.min(minLon, longitude);
maxLat = Math.max(maxLat, latitude);
maxLon = Math.max(maxLon, longitude);
}
return new LatLngBounds(maxLat, maxLon, minLat, minLon);
}
/**
* Determines whether this LatLngBounds matches another one via LatLng.
*
* @param o another object
* @return a boolean indicating whether the LatLngBounds are equal
*/
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o instanceof BoundingBox) {
BoundingBox other = (BoundingBox) o;
return mLatNorth == other.getLatNorth()
&& mLatSouth == other.getLatSouth()
&& mLonEast == other.getLonEast()
&& mLonWest == other.getLonWest();
}
return false;
}
/**
* Determines whether this LatLngBounds contains a point and the point
* does not touch its boundary.
*
* @param latLng the point which may be contained
* @return true, if the point is contained within the box.
*/
public boolean contains(final ILatLng latLng) {
final double latitude = latLng.getLatitude();
final double longitude = latLng.getLongitude();
return ((latitude < this.mLatNorth)
&& (latitude > this.mLatSouth))
&& ((longitude < this.mLonEast)
&& (longitude > this.mLonWest));
}
/**
* Returns a new LatLngBounds that stretches to contain both this and another LatLngBounds.
*
* @param bounds LatLngBounds to add
* @return LatLngBounds
*/
public LatLngBounds union(LatLngBounds bounds) {
return union(bounds.getLatNorth(), bounds.getLonEast(), bounds.getLatSouth(), bounds.getLonWest());
}
/**
* Returns a new LatLngBounds that stretches to include another LatLngBounds,
* given by corner points.
*
* @param lonNorth Northern Longitude
* @param latEast Eastern Latitude
* @param lonSouth Southern Longitude
* @param latWest Western Longitude
* @return BoundingBox
*/
public LatLngBounds union(final double lonNorth, final double latEast, final double lonSouth, final double latWest) {
return new LatLngBounds((this.mLatNorth < lonNorth) ? lonNorth : this.mLatNorth,
(this.mLonEast < latEast) ? latEast : this.mLonEast,
(this.mLatSouth > lonSouth) ? lonSouth : this.mLatSouth,
(this.mLonWest > latWest) ? latWest : this.mLonWest);
}
/**
* Returns a new LatLngBounds that is the intersection of this with another box
*
* @param box LatLngBounds to intersect with
* @return LatLngBounds
*/
public LatLngBounds intersect(LatLngBounds box) {
double minLatWest = Math.max(getLonWest(), box.getLonWest());
double maxLatEast = Math.min(getLonEast(), box.getLonEast());
if (maxLatEast > minLatWest) {
double minLonSouth = Math.max(getLatSouth(), box.getLatSouth());
double maxLonNorth = Math.min(getLatNorth(), box.getLatNorth());
if (maxLonNorth > minLonSouth) {
return new LatLngBounds(maxLonNorth, maxLatEast, minLonSouth, minLatWest);
}
}
return null;
}
/**
* Returns a new LatLngBounds that is the intersection of this with another LatLngBounds
*
* @param northLongitude Northern Longitude
* @param eastLatitude Eastern Latitude
* @param southLongitude Southern Longitude
* @param westLatitude Western Latitude
* @return LatLngBounds
*/
public LatLngBounds intersect(double northLongitude, double eastLatitude, double southLongitude, double westLatitude) {
return intersect(new LatLngBounds(northLongitude, eastLatitude, southLongitude, westLatitude));
}
public static final Parcelable.Creator<LatLngBounds> CREATOR =
new Parcelable.Creator<LatLngBounds>() {
@Override
public LatLngBounds createFromParcel(final Parcel in) {
return readFromParcel(in);
}
@Override
public LatLngBounds[] newArray(final int size) {
return new LatLngBounds[size];
}
};
@Override
public int hashCode() {
return (int) ((mLatNorth + 90)
+ ((mLatSouth + 90) * 1000)
+ ((mLonEast + 180) * 1000000)
+ ((mLonEast + 180) * 1000000000));
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(final Parcel out, final int arg1) {
out.writeDouble(this.mLatNorth);
out.writeDouble(this.mLonEast);
out.writeDouble(this.mLatSouth);
out.writeDouble(this.mLonWest);
}
private static LatLngBounds readFromParcel(final Parcel in) {
final double lonNorth = in.readDouble();
final double latEast = in.readDouble();
final double lonSouth = in.readDouble();
final double latWest = in.readDouble();
return new LatLngBounds(lonNorth, latEast, lonSouth, latWest);
}
}

View File

@@ -1,96 +0,0 @@
package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
import java.io.Serializable;
/**
* A geographical location which contains a {@link LatLng}, zoom pair.
*/
public class LatLngZoom extends LatLng implements Parcelable {
public static final Parcelable.Creator<LatLngZoom> CREATOR = new Parcelable.Creator<LatLngZoom>() {
public LatLngZoom createFromParcel(Parcel in) {
return new LatLngZoom(in);
}
public LatLngZoom[] newArray(int size) {
return new LatLngZoom[size];
}
};
private double zoom;
public LatLngZoom() {
super();
this.zoom = 0.0;
}
public LatLngZoom(double latitude, double longitude, double zoom) {
super(latitude, longitude);
this.zoom = zoom;
}
public LatLngZoom(LatLng latLng, double zoom) {
super(latLng.getLatitude(), latLng.getLongitude());
this.zoom = zoom;
}
private LatLngZoom(Parcel in) {
super(in);
zoom = in.readDouble();
}
public double getZoom() {
return zoom;
}
public void setZoom(double zoom) {
this.zoom = zoom;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
LatLngZoom that = (LatLngZoom) o;
return Double.compare(that.zoom, zoom) == 0;
}
@Override
public int hashCode() {
int result = super.hashCode();
long temp;
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
return "LatLngZoom [latitude=" + super.getLatitude() + ", longitude=" + super.getLongitude() + ", altitude=" + super.getAltitude() + ", zoom=" + zoom + "]";
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeDouble(zoom);
}
}

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.views;
package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.support.v4.content.ContextCompat;
@@ -21,7 +21,7 @@ import java.util.TimerTask;
* when it isn't true north (0.0). Tapping the compass resets the bearing to true
* north and hides the compass.
*/
final class CompassView extends ImageView {
public class CompassView extends ImageView {
private Timer mNorthTimer;
private double mDirection = 0.0f;

View File

@@ -1,14 +1,16 @@
package com.mapbox.mapboxsdk;
package com.mapbox.mapboxsdk.maps;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
/**
* Fragment wrapper around a {@link MapView}.
@@ -19,10 +21,10 @@ import com.mapbox.mapboxsdk.views.MapView;
* using a FragmentManager.
* </p>
* <p>
* To get a reference to the MapView, use {@link #getMap()}
* To get a reference to the MapView, use {@link #getMapAsync(OnMapReadyCallback)}}
* </p>
*
* @see #getMap()
* @see #getMapAsync(OnMapReadyCallback)
*/
public class MapFragment extends Fragment {
@@ -33,111 +35,86 @@ public class MapFragment extends Fragment {
// Tag used for logging
private static final String TAG = "MapFragment";
// Argument used for configuration
private static final String ARGS_MAPBOXMAP_OPTIONS = "MapboxMapOptions";
//
// Instance members
//
// The map
private MapView mMap;
private OnMapReadyCallback mMapReadyCallback;
//
// Lifecycle events
//
public static MapFragment newInstance(){
return new MapFragment();
}
public static MapFragment newInstance(MapboxMapOptions mapboxMapOptions) {
final MapFragment mapFragment = new MapFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ARGS_MAPBOXMAP_OPTIONS, mapboxMapOptions);
mapFragment.setArguments(bundle);
return mapFragment;
}
// Called when the fragment is created
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Log.v(TAG, "onCreateView");
// Create the map
mMap = (MapView) inflater.inflate(R.layout.fragment_mapview, container, false);
// Set accessToken
mMap.setAccessToken(ApiAccess.getToken(inflater.getContext()));
// Need to pass on any saved state to the map
mMap.onCreate(savedInstanceState);
// Return the map as the root view
return mMap;
}
// Called when the fragment is destroyed
@Override
public void onDestroyView() {
super.onDestroyView();
Log.v(TAG, "onDestroyView");
// Need to pass on to view
mMap.onDestroy();
mMap = null;
}
// Called when the fragment is visible
@Override
public void onStart() {
super.onStart();
Log.v(TAG, "onStart");
// Need to pass on to view
mMap.onStart();
}
// Called when the fragment is invisible
@Override
public void onStop() {
super.onStop();
Log.v(TAG, "onStop");
// Need to pass on to view
mMap.onStop();
}
// Called when the fragment is in the background
@Override
public void onPause() {
super.onPause();
Log.v(TAG, "onPause");
// Need to pass on to view
mMap.onPause();
}
// Called when the fragment is no longer in the background
@Override
public void onResume() {
super.onResume();
Log.v(TAG, "onResume");
// Need to pass on to view
mMap.onResume();
if(mMapReadyCallback!=null){
mMapReadyCallback.onMapReady(mMap.getMapboxMap());
}
}
// Called before fragment is destroyed
@Override
public void onSaveInstanceState(Bundle outState) {
Log.v(TAG, "onSaveInstanceState");
public void onPause() {
super.onPause();
mMap.onPause();
}
// Need to retrieve any saved state from the map
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
mMap.onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
}
@Override
public void onLowMemory() {
Log.v(TAG, "OnLowMemory");
public void onStop() {
super.onStop();
mMap.onStop();
}
// Need to pass on to view
@Override
public void onLowMemory() {
mMap.onLowMemory();
super.onLowMemory();
}
//
// Property methods
//
@Override
public void onDestroyView() {
super.onDestroyView();
mMap.onDestroy();
mMap = null;
}
public MapView getMap() {
return mMap;
@NonNull
public void getMapAsync(@NonNull OnMapReadyCallback onMapReadyCallback){
mMapReadyCallback = onMapReadyCallback;
}
}

View File

@@ -0,0 +1,114 @@
package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import com.mapbox.mapboxsdk.camera.CameraPosition;
/**
* Builder for composing {@link MapboxMap} objects. These options can be used when adding a
* map to your application programmatically (as opposed to via XML). If you are using a MapFragment,
* you can pass these options in using the static factory method newInstance(MapboxMapOptions).
* If you are using a MapView, you can pass these options in using the constructor MapView(Context, MapboxMapOptions).
*/
public class MapboxMapOptions implements Parcelable {
public MapboxMap mMapboxMap;
public MapboxMapOptions(MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
}
public MapboxMapOptions(Parcel in) {
throw new UnsupportedOperationException();
}
public MapboxMapOptions camera(CameraPosition camera) {
mMapboxMap.setCameraPosition(camera);
return this;
}
public CameraPosition getCamera() {
return mMapboxMap.getCameraPosition();
}
public MapboxMapOptions compassEnabled(boolean enabled) {
mMapboxMap.setCompassEnabled(enabled);
return this;
}
public boolean getCompassEnabled() {
return mMapboxMap.isCompassEnabled();
}
public MapboxMapOptions rotateEnabled(boolean rotateEnabled) {
mMapboxMap.setRotateEnabled(rotateEnabled);
return this;
}
public MapboxMapOptions rotateGesturesEnabled(boolean enabled) {
mMapboxMap.setRotateEnabled(enabled);
return this;
}
public boolean getRotateGesturesEnabled() {
return mMapboxMap.isRotateEnabled();
}
public MapboxMapOptions scrollGesturesEnabled(boolean enabled) {
mMapboxMap.setScrollEnabled(enabled);
return this;
}
public boolean getScrollGesturesEnabled() {
return mMapboxMap.isScrollEnabled();
}
public MapboxMapOptions tiltGesturesEnabled(boolean enabled) {
mMapboxMap.setTiltEnabled(enabled);
return this;
}
public boolean getTiltGesturesEnabled() {
return mMapboxMap.isTiltEnabled();
}
public MapboxMapOptions zoomControlsEnabled(boolean enabled) {
mMapboxMap.setZoomControlsEnabled(enabled);
return this;
}
public boolean getZoomControlsEnabled() {
return mMapboxMap.isZoomControlsEnabled();
}
public boolean getZoomGesturesEnabled() {
return mMapboxMap.isZoomEnabled();
}
public MapboxMapOptions createFromAttributes(Context context, AttributeSet attrs) {
throw new UnsupportedOperationException();
}
public static final Parcelable.Creator<MapboxMapOptions> CREATOR = new Parcelable.Creator<MapboxMapOptions>() {
public MapboxMapOptions createFromParcel(Parcel in) {
return new MapboxMapOptions(in);
}
public MapboxMapOptions[] newArray(int size) {
return new MapboxMapOptions[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
throw new UnsupportedOperationException();
}
}

View File

@@ -1,16 +1,20 @@
package com.mapbox.mapboxsdk.views;
package com.mapbox.mapboxsdk.maps;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
import android.view.Surface;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import java.lang.ref.WeakReference;
import java.util.List;
@@ -31,7 +35,7 @@ final class NativeMapView {
private long mNativeMapViewPtr = 0;
// Used for callbacks
private WeakReference<MapView> mMapView;
private MapView mMapView;
//
// Static methods
@@ -45,7 +49,21 @@ final class NativeMapView {
// Constructors
//
public NativeMapView(MapView mapView, String cachePath, String dataPath, String apkPath, float pixelRatio, int availableProcessors, long totalMemory) {
public NativeMapView(MapView mapView) {
Context context = mapView.getContext();
String cachePath = context.getCacheDir().getAbsolutePath();
String dataPath = context.getFilesDir().getAbsolutePath();
float pixelRatio = context.getResources().getDisplayMetrics().density;
String apkPath = context.getPackageCodePath();
int availableProcessors = Runtime.getRuntime().availableProcessors();
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(memoryInfo);
long totalMemory = memoryInfo.availMem;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
totalMemory = memoryInfo.totalMem;
}
if (availableProcessors < 0) {
throw new IllegalArgumentException("availableProcessors cannot be negative.");
}
@@ -54,9 +72,7 @@ final class NativeMapView {
throw new IllegalArgumentException("totalMemory cannot be negative.");
}
mMapView = new WeakReference<>(mapView);
// Create the NativeMapView
mMapView = mapView;
mNativeMapViewPtr = nativeCreate(cachePath, dataPath, apkPath, pixelRatio, availableProcessors, totalMemory);
}
@@ -303,18 +319,6 @@ final class NativeMapView {
return nativeGetZoom(mNativeMapViewPtr);
}
public void setLatLngZoom(LatLngZoom latLngZoom) {
setLatLngZoom(latLngZoom, 0);
}
public void setLatLngZoom(LatLngZoom latLngZoom, long duration) {
nativeSetLatLngZoom(mNativeMapViewPtr, latLngZoom, duration);
}
public LatLngZoom getLatLngZoom() {
return nativeGetLatLngZoom(mNativeMapViewPtr);
}
public void resetZoom() {
nativeResetZoom(mNativeMapViewPtr);
}
@@ -460,7 +464,7 @@ final class NativeMapView {
return nativeGetTopOffsetPixelsForAnnotationSymbol(mNativeMapViewPtr, symbolName);
}
public void jumpTo(double angle, LatLng center, double pitch, double zoom) {
public void jumpTo(double angle, LatLng center, double pitch, double zoom) {
nativeJumpTo(mNativeMapViewPtr, angle, center, pitch, zoom);
}
@@ -485,15 +489,15 @@ final class NativeMapView {
//
protected void onInvalidate() {
mMapView.get().onInvalidate();
mMapView.onInvalidate();
}
protected void onMapChanged(int rawChange) {
mMapView.get().onMapChanged(rawChange);
mMapView.onMapChanged(rawChange);
}
protected void onFpsChanged(double fps) {
mMapView.get().onFpsChanged(fps);
mMapView.onFpsChanged(fps);
}
//
@@ -589,11 +593,6 @@ final class NativeMapView {
private native double nativeGetZoom(long nativeMapViewPtr);
private native void nativeSetLatLngZoom(long nativeMapViewPtr,
LatLngZoom lonLatZoom, long duration);
private native LatLngZoom nativeGetLatLngZoom(long nativeMapViewPtr);
private native void nativeResetZoom(long nativeMapViewPtr);
private native void nativeSetMinZoom(long nativeMapViewPtr, double zoom);
@@ -638,7 +637,7 @@ final class NativeMapView {
private native long[] nativeGetAnnotationsInBounds(long mNativeMapViewPtr, BoundingBox bbox);
private native void nativeAddAnnotationIcon(long nativeMapViewPtr, String symbol,
int width, int height, float scale, byte[] pixels);
int width, int height, float scale, byte[] pixels);
private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, LatLng[] coordinates,
RectF padding, double direction, long duration);

View File

@@ -0,0 +1,26 @@
package com.mapbox.mapboxsdk.maps;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.maps.MapFragment;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Callback interface for when the map is ready to be used.
* <p>
* Once an instance of this interface is set on a {@link MapFragment} or {@link MapView} object,
* the onMapReady(MapboxMap) method is triggered when the map is ready to be used and provides a non-null instance of {@link MapboxMap}.
* </p>
*/
public interface OnMapReadyCallback {
/**
* Called when the map is ready to be used.
*
* @param mapboxMap A non-null instance of a MapboxMap associated with the {@link MapFragment}
* or {@link MapView} that defines the callback.
*/
void onMapReady(@NonNull MapboxMap mapboxMap);
}

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.views;
package com.mapbox.mapboxsdk.maps;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
@@ -40,7 +40,8 @@ import java.lang.ref.WeakReference;
* This view shows the user's location, as determined from GPS, on the map
* as a dot annotation.
*/
final class UserLocationView extends View {
public final class UserLocationView extends View {
private MapView mMapView;
@@ -89,7 +90,7 @@ final class UserLocationView extends View {
private Location mUserLocation;
private UserLocationListener mUserLocationListener;
MapView.OnMyLocationChangeListener mOnMyLocationChangeListener;
private MapboxMap.OnMyLocationChangeListener mOnMyLocationChangeListener;
@MyLocationTracking.Mode
private int mMyLocationTrackingMode;
@@ -247,7 +248,7 @@ final class UserLocationView extends View {
if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && mUserLocation != null) {
// center map directly if we have a location fix
mMarkerCoordinate = new LatLng(mUserLocation.getLatitude(), mUserLocation.getLongitude());
mMapView.setLatLng(new LatLng(mUserLocation));
mMapView.getMapboxMap().moveCamera(CameraUpdateFactory.newLatLng(new LatLng(mUserLocation)));
// center view directly
mMarkerScreenMatrix.reset();
@@ -293,7 +294,7 @@ final class UserLocationView extends View {
}
if (mCurrentMapViewCoordinate == null) {
mCurrentMapViewCoordinate = mMapView.getLatLng();
mCurrentMapViewCoordinate = mMapView.getMapboxMap().getCameraPosition().target;
}
// only update if there is an actual change
@@ -302,7 +303,7 @@ final class UserLocationView extends View {
.target(mMarkerCoordinate)
.bearing(bearing)
.build();
mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
mMapView.getMapboxMap().animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
mMarkerScreenMatrix.reset();
mMarkerScreenMatrix.setTranslate(
getMeasuredWidth() / 2,
@@ -691,7 +692,7 @@ final class UserLocationView extends View {
}
}
public void setOnMyLocationChangeListener(@Nullable MapView.OnMyLocationChangeListener listener) {
public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
mOnMyLocationChangeListener = listener;
}

View File

@@ -0,0 +1,4 @@
/**
* This package contains the {@link com.mapbox.mapboxsdk.maps.MapboxMap}, {@link com.mapbox.mapboxsdk.maps.MapView}, {@link com.mapbox.mapboxsdk.maps.NativeMapView} and {@link com.mapbox.mapboxsdk.maps.MapFragment} classes
*/
package com.mapbox.mapboxsdk.maps;

View File

@@ -1,5 +1,4 @@
/**
* This package contains the {@link com.mapbox.mapboxsdk.MapFragment} class. {@code MapFragment}
* provides a quick and easy way to add a map to your app.
* This package is the base package of the Mapbox GL SDK for Android
*/
package com.mapbox.mapboxsdk;

View File

@@ -25,7 +25,6 @@ public final class ApiAccess {
* @return The Mapbox access token or null if not found.
* @see MapboxConstants#KEY_META_DATA_MANIFEST
*/
@Nullable
public static String getToken(@NonNull Context context) {
try {
// read out AndroidManifest

View File

@@ -1,5 +0,0 @@
/**
* This package contains the {@link com.mapbox.mapboxsdk.views.MapView} and related classes.
* {@code MapView} is the core component of this SDK and adds a map to your app.
*/
package com.mapbox.mapboxsdk.views;