Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.util.Pools;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.style.layers.Filter;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.commons.geojson.Feature;
import com.mapbox.services.commons.geojson.Geometry;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.List;
import timber.log.Timber;
/**
* The general class to interact with in the Android Mapbox SDK. It exposes the entry point for all
* methods related to the MapView. You cannot instantiate {@link MapboxMap} object directly, rather,
* you must obtain one from the getMapAsync() method on a MapFragment or MapView that you have
* added to your application.
*
* Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread.
*
*/
@UiThread
public final class MapboxMap {
private final NativeMapView nativeMapView;
private final UiSettings uiSettings;
private final TrackingSettings trackingSettings;
private final Projection projection;
private final Transform transform;
private final AnnotationManager annotationManager;
private final MyLocationViewSettings myLocationViewSettings;
private final CameraChangeDispatcher cameraChangeDispatcher;
private final OnRegisterTouchListener onRegisterTouchListener;
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
private PointF focalPoint;
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, TrackingSettings tracking,
MyLocationViewSettings myLocationView, Projection projection, OnRegisterTouchListener listener,
AnnotationManager annotations, CameraChangeDispatcher cameraChangeDispatcher) {
this.nativeMapView = map;
this.uiSettings = ui;
this.trackingSettings = tracking;
this.projection = projection;
this.myLocationViewSettings = myLocationView;
this.annotationManager = annotations.bind(this);
this.transform = transform;
this.onRegisterTouchListener = listener;
this.cameraChangeDispatcher = cameraChangeDispatcher;
}
void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
transform.initialise(this, options);
uiSettings.initialise(context, options);
myLocationViewSettings.initialise(options);
trackingSettings.initialise(options);
// Map configuration
setDebugActive(options.getDebugActive());
setApiBaseUrl(options);
setStyleUrl(options);
setPrefetchesTiles(options);
}
/**
* Called when the hosting Activity/Fragment onStart() method is called.
*/
void onStart() {
nativeMapView.update();
trackingSettings.onStart();
if (TextUtils.isEmpty(nativeMapView.getStyleUrl())) {
// if user hasn't loaded a Style yet
nativeMapView.setStyleUrl(Style.MAPBOX_STREETS);
}
}
/**
* Called when the hosting Activity/Fragment onStop() method is called.
*/
void onStop() {
trackingSettings.onStop();
}
/**
* Called when the hosting Activity/Fragment is going to be destroyed and map state needs to be saved.
*
* @param outState the bundle to save the state to.
*/
void onSaveInstanceState(Bundle outState) {
outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, transform.getCameraPosition());
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, nativeMapView.getDebug());
outState.putString(MapboxConstants.STATE_STYLE_URL, nativeMapView.getStyleUrl());
trackingSettings.onSaveInstanceState(outState);
uiSettings.onSaveInstanceState(outState);
}
/**
* Called when the hosting Activity/Fragment is recreated and map state needs to be restored.
*
* @param savedInstanceState the bundle containing the saved state
*/
void onRestoreInstanceState(Bundle savedInstanceState) {
final CameraPosition cameraPosition = savedInstanceState.getParcelable(MapboxConstants.STATE_CAMERA_POSITION);
uiSettings.onRestoreInstanceState(savedInstanceState);
trackingSettings.onRestoreInstanceState(savedInstanceState);
if (cameraPosition != null) {
moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder(cameraPosition).build())
);
}
nativeMapView.setDebug(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE));
final String styleUrl = savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL);
if (!TextUtils.isEmpty(styleUrl)) {
nativeMapView.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL));
}
}
/**
* Called before the OnMapReadyCallback is invoked.
*/
void onPreMapReady() {
annotationManager.reloadMarkers();
annotationManager.adjustTopOffsetPixels(this);
}
/**
* Called when the OnMapReadyCallback has finished executing.
*
* Invalidation of the camera position is required to update the added components in
* OnMapReadyCallback with the correct transformation.
*
*/
void onPostMapReady() {
invalidateCameraPosition();
}
/**
* Called when the region is changing or has changed.
*/
void onUpdateRegionChange() {
trackingSettings.update();
annotationManager.update();
}
/**
* Called when the map frame is fully rendered.
*/
void onUpdateFullyRendered() {
CameraPosition cameraPosition = transform.invalidateCameraPosition();
if (cameraPosition != null) {
uiSettings.update(cameraPosition);
}
}
// Style
/**
*
* Get the animation duration for style changes.
*
* The default value is zero, so any changes take effect without animation.
*
* @return Duration in milliseconds
*/
public long getTransitionDuration() {
return nativeMapView.getTransitionDuration();
}
/**
* Set the animation duration for style changes.
*
* @param durationMs Duration in milliseconds
*/
public void setTransitionDuration(long durationMs) {
nativeMapView.setTransitionDuration(durationMs);
}
/**
*
* Get the animation delay for style changes.
*
* The default value is zero, so any changes begin to animate immediately.
*
* @return Delay in milliseconds
*/
public long getTransitionDelay() {
return nativeMapView.getTransitionDelay();
}
/**
* Set the animation delay for style changes.
*
* @param delayMs Delay in milliseconds
*/
public void setTransitionDelay(long delayMs) {
nativeMapView.setTransitionDelay(delayMs);
}
/**
* Sets tile pre-fetching from MapboxOptions.
*
* @param options the options object
*/
private void setPrefetchesTiles(@NonNull MapboxMapOptions options) {
setPrefetchesTiles(options.getPrefetchesTiles());
}
/**
* Enable or disable tile pre-fetching. Pre-fetching makes sure that a low-resolution
* tile is rendered as soon as possible at the expense of a little bandwidth.
*
* @param enable true to enable
*/
public void setPrefetchesTiles(boolean enable) {
nativeMapView.setPrefetchesTiles(enable);
}
/**
* Check whether tile pre-fetching is enabled or not.
*
* @return true if enabled
* @see MapboxMap#setPrefetchesTiles(boolean)
*/
public boolean getPrefetchesTiles() {
return nativeMapView.getPrefetchesTiles();
}
/**
* Retrieve all the layers in the style
*
* @return all the layers in the current style
*/
public List getLayers() {
return nativeMapView.getLayers();
}
/**
* Get the layer by id
*
* @param layerId the layer's id
* @return the layer, if present in the style
*/
@Nullable
public Layer getLayer(@NonNull String layerId) {
return nativeMapView.getLayer(layerId);
}
/**
* Tries to cast the Layer to T, returns null if it's another type.
*
* @param layerId the layer id used to look up a layer
* @param the generic attribute of a Layer
* @return the casted Layer, null if another type
*/
@Nullable
public T getLayerAs(@NonNull String layerId) {
try {
// noinspection unchecked
return (T) nativeMapView.getLayer(layerId);
} catch (ClassCastException exception) {
Timber.e(exception, "Layer: %s is a different type: ", layerId);
return null;
}
}
/**
* Adds the layer to the map. The layer must be newly created and not added to the map before
*
* @param layer the layer to add
*/
public void addLayer(@NonNull Layer layer) {
nativeMapView.addLayer(layer);
}
/**
* Adds the layer to the map. The layer must be newly created and not added to the map before
*
* @param layer the layer to add
* @param below the layer id to add this layer before
*/
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
nativeMapView.addLayerBelow(layer, below);
}
/**
* Adds the layer to the map. The layer must be newly created and not added to the map before
*
* @param layer the layer to add
* @param above the layer id to add this layer above
*/
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
nativeMapView.addLayerAbove(layer, above);
}
/**
* Adds the layer to the map at the specified index. The layer must be newly
* created and not added to the map before
*
* @param layer the layer to add
* @param index the index to insert the layer at
*/
public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
nativeMapView.addLayerAt(layer, index);
}
/**
* Removes the layer. Any references to the layer become invalid and should not be used anymore
*
* @param layerId the layer to remove
* @return the removed layer or null if not found
*/
@Nullable
public Layer removeLayer(@NonNull String layerId) {
return nativeMapView.removeLayer(layerId);
}
/**
* Removes the layer. The reference is re-usable after this and can be re-added
*
* @param layer the layer to remove
* @return the layer
*/
@Nullable
public Layer removeLayer(@NonNull Layer layer) {
return nativeMapView.removeLayer(layer);
}
/**
* Removes the layer. Any other references to the layer become invalid and should not be used anymore
*
* @param index the layer index
* @return the removed layer or null if not found
*/
@Nullable
public Layer removeLayerAt(@IntRange(from = 0) int index) {
return nativeMapView.removeLayerAt(index);
}
/**
* Retrieve all the sources in the style
*
* @return all the sources in the current style
*/
public List