use of com.mapbox.mapboxsdk.maps.MapboxMap in project apps-android-commons by commons-app.
the class NearbyMapFragment method setupMapView.
private void setupMapView(Bundle savedInstanceState) {
MapboxMapOptions options = new MapboxMapOptions().styleUrl(Style.OUTDOORS).camera(new CameraPosition.Builder().target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())).zoom(11).build());
// create map
mapView = new MapView(getActivity(), options);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
mapboxMap.addMarkers(baseMarkerOptions);
mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
if (marker instanceof NearbyMarker) {
NearbyMarker nearbyMarker = (NearbyMarker) marker;
Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
NearbyInfoDialog.showYourself(getActivity(), place);
}
return false;
}
});
addCurrentLocationMarker(mapboxMap);
}
});
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme", true)) {
mapView.setStyleUrl(getResources().getString(R.string.map_theme_dark));
} else {
mapView.setStyleUrl(getResources().getString(R.string.map_theme_light));
}
}
use of com.mapbox.mapboxsdk.maps.MapboxMap in project osm-contributor by jawg.
the class MapboxListener method listen.
/**
* Register the listener for the map
* @param mapboxMap
*/
public void listen(final MapboxMap mapboxMap, final MapView mapView) {
this.mapboxMap = mapboxMap;
// Listen on map click
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
MapboxListener.this.onMapClick();
}
});
// Listen on marker click
mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
if (marker instanceof WayMarker) {
WayMarker wayMarker = (WayMarker) marker;
MapboxListener.this.onWayMarkerClick(wayMarker);
}
return false;
}
});
// Listen on location and zoom change
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
// Location change, call the listener method
if (MapboxListener.this.position != null) {
if (!MapboxListener.this.position.target.equals(position.target)) {
onCameraPositionChange();
}
// Zoom change, call the listener method
if (MapboxListener.this.position.zoom != position.zoom) {
onCameraZoomChange(position.zoom);
}
}
MapboxListener.this.position = position;
}
});
final ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(mapFragment.getActivity(), new ZoomAnimationGestureDetector() {
@Override
public void onZoomAnimationEnd(ValueAnimator animator) {
if (zoomValueAnimator != null && zoomValueAnimator.isRunning()) {
zoomValueAnimator.cancel();
}
zoomValueAnimator = animator;
zoomValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
CameraPosition position = mapboxMap.getCameraPosition();
mapboxMap.setCameraPosition(new CameraPosition.Builder().target(position.target).bearing(position.bearing).zoom(position.zoom + (Float) valueAnimator.getAnimatedValue()).build());
}
});
zoomValueAnimator.start();
}
});
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
scaleGestureDetector.onTouchEvent(motionEvent);
return false;
}
});
// Listen on marker view click
mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
if (marker instanceof LocationMarkerView) {
LocationMarkerView locationMarker = (LocationMarkerView) marker;
MapboxListener.this.onLocationMarkerClick(locationMarker);
return false;
}
return false;
}
});
}
use of com.mapbox.mapboxsdk.maps.MapboxMap in project osm-contributor by jawg.
the class OfflineRegionsActivity method initMapView.
private void initMapView(Bundle savedInstanceState) {
mapView.onCreate(savedInstanceState);
mapView.setStyleUrl(BuildConfig.MAP_STYLE);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
OfflineRegionsActivity.this.mapboxMap = mapboxMap;
mapboxMap.getUiSettings().setCompassEnabled(false);
mapboxMap.getUiSettings().setRotateGesturesEnabled(false);
mapboxMap.getUiSettings().setTiltGesturesEnabled(false);
enableMapGestures(false);
}
});
}
use of com.mapbox.mapboxsdk.maps.MapboxMap in project androidApp by InspectorIncognito.
the class RouterVectorMapFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap aMapboxMap) {
mapboxMap = aMapboxMap;
mapboxMap.getUiSettings().setCompassMargins(0, 14 * getResources().getDisplayMetrics().heightPixels / 100, 4 * getResources().getDisplayMetrics().widthPixels / 100, 0);
routerPlugin = new RouterPlugin(mapboxMap, new RedirectionListener(getActivity()));
if (selectedRoute != null) {
innerSetRoute(selectedRoute);
selectedRoute = null;
}
locationEngine = new MultiLocationEngine();
locationPlugin = new UserPlugin(mapView, mapboxMap, locationEngine);
mapboxMap.addOnScrollListener(new MapboxMap.OnScrollListener() {
@Override
public void onScroll() {
centerButton.deselectButton();
locationPlugin.setTrackingEnabled(false);
}
});
centerButton = new LocationToggleButton((ImageButton) getActivity().findViewById(R.id.floating_button_center), new LocationToggleButton.OnToggleButtonCheck() {
@Override
public void onButtonSelected() {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationEngine.getLastLocation().getLatitude(), locationEngine.getLastLocation().getLongitude()), 16));
locationPlugin.setTrackingEnabled(true);
}
@Override
public void onButtonUnselected() {
locationPlugin.setTrackingEnabled(false);
}
}, false);
enableLocationPlugin();
mapView.setVisibility(View.VISIBLE);
}
});
}
use of com.mapbox.mapboxsdk.maps.MapboxMap in project androidApp by InspectorIncognito.
the class VectorSearchMapFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap resMapboxMap) {
mapboxMap = resMapboxMap;
// mapboxMap.getUiSettings().setCompassImage(ContextCompat.getDrawable(getContext(), R.drawable.direction_arrow));
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
}
});
mapboxMap.getUiSettings().setCompassMargins(0, 14 * getResources().getDisplayMetrics().heightPixels / 100, 4 * getResources().getDisplayMetrics().widthPixels / 100, 0);
searchPlugin = new SearchPlugin(redirectionListener, service, routeHelper, mapboxMap);
locationEngine = new MultiLocationEngine();
locationPlugin = new UserPlugin(mapView, mapboxMap, locationEngine);
mapboxMap.addOnScrollListener(new MapboxMap.OnScrollListener() {
@Override
public void onScroll() {
centerButton.deselectButton();
locationPlugin.setTrackingEnabled(false);
}
});
centerButton = new LocationToggleButton((ImageButton) getActivity().findViewById(R.id.floating_button_center), new LocationToggleButton.OnToggleButtonCheck() {
@Override
public void onButtonSelected() {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationEngine.getLastLocation().getLatitude(), locationEngine.getLastLocation().getLongitude()), 16));
locationPlugin.setTrackingEnabled(true);
}
@Override
public void onButtonUnselected() {
locationPlugin.setTrackingEnabled(false);
}
}, false);
enableLocationPlugin();
Location lastLocation = locationEngine.getLastLocation();
zoomBound(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()));
}
});
}
Aggregations