use of com.mapbox.mapboxsdk.maps.MapView 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.MapView 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.MapView in project collect by opendatakit.
the class MapBoxInitializationFragment method initMapBox.
private void initMapBox(View rootView) {
Settings metaSharedPreferences = settingsProvider.getMetaSettings();
if (!metaSharedPreferences.getBoolean(KEY_MAPBOX_INITIALIZED) && connectivityProvider.isDeviceOnline()) {
// most likely to be available. This is annoyingly needed for offline tiles to work.
try {
mapView = new MapView(getContext());
FrameLayout mapBoxContainer = rootView.findViewById(R.id.map_box_container);
mapBoxContainer.addView(mapView);
mapView.getMapAsync(mapBoxMap -> mapBoxMap.setStyle(Style.MAPBOX_STREETS, style -> {
metaSharedPreferences.save(KEY_MAPBOX_INITIALIZED, true);
}));
} catch (Exception | Error ignored) {
// This will crash on devices where the arch for MapBox is not included
}
}
}
use of com.mapbox.mapboxsdk.maps.MapView in project collect by opendatakit.
the class MapFragment method onCreateView.
/**
* Creates the fragment view hierarchy.
*
* @param inflater Inflater used to inflate content.
* @param container The parent layout for the map fragment.
* @param savedInstanceState The saved instance state for the map fragment.
* @return The view created
*/
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Context context = inflater.getContext();
map = new MapView(context, MapFragmentUtils.resolveArgs(context, getArguments()));
return map;
}
use of com.mapbox.mapboxsdk.maps.MapView in project androidApp by InspectorIncognito.
the class RouterVectorMapFragment method onCreateView.
@NonNull
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.activity_router_map_fragment, container, false);
mapView = view.findViewById(R.id.map_layout_id);
slidingPanel = view.findViewById(R.id.sliding_layout);
title = view.findViewById(R.id.header_title);
ListView listView = view.findViewById(R.id.list_view);
viewGroup = (LinearLayout) view.findViewById(R.id.dragView);
routerOptionAdapter = new RouterOptionAdapter(this.getContext(), new CustomArrayAdapter.ItemClickListener<Integer>() {
@Override
public void onItemClick(Integer item) {
if (slidingPanel.getPanelState().equals(SlidingUpPanelLayout.PanelState.COLLAPSED)) {
slidingPanel.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
} else {
slidingPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}
}
});
View defaultView = view.findViewById(R.id.subheader);
routerOptionAdapter.setDefaultView(defaultView);
View prevLayout = view.findViewById(R.id.prev_layout);
View nextLayout = view.findViewById(R.id.next_layout);
prevLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
contextListener.prevClicked();
}
});
nextLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
contextListener.nextClicked();
}
});
adapter = new StepAdapter(this.getContext(), this);
listView.setAdapter(adapter);
mapView.setVisibility(View.INVISIBLE);
return view;
}
Aggregations