Search in sources :

Example 6 with MapboxMap

use of com.mapbox.mapboxsdk.maps.MapboxMap in project mapbox-plugins-android by mapbox.

the class OfflineRegionDetailActivity method setupUI.

private void setupUI(final OfflineTilePyramidRegionDefinition definition) {
    // update map
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            // correct style
            mapboxMap.setStyle(definition.getStyleURL());
            // position map on top of offline region
            CameraPosition cameraPosition = OfflineUtils.getCameraPosition(definition);
            mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
            // restrict camera movement
            mapboxMap.setMinZoomPreference(definition.getMinZoom());
            mapboxMap.setMaxZoomPreference(definition.getMaxZoom());
            mapboxMap.setLatLngBoundsForCameraTarget(definition.getBounds());
        }
    });
    // update textview data
    nameView.setText(OfflineUtils.convertRegionName(offlineRegion.getMetadata()));
    styleView.setText(definition.getStyleURL());
    latLngBoundsView.setText(definition.getBounds().toString());
    minZoomView.setText(String.valueOf(definition.getMinZoom()));
    maxZoomView.setText(String.valueOf(definition.getMaxZoom()));
    offlineRegion.getStatus(offlineRegionStatusCallback);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 7 with MapboxMap

use of com.mapbox.mapboxsdk.maps.MapboxMap in project osm-contributor by jawg.

the class MapFragment method instantiateMapView.

private void instantiateMapView(final Bundle savedInstanceState) {
    if (mapView != null) {
        mapMode = MapMode.DEFAULT;
        mapView.onCreate(savedInstanceState);
        mapView.setStyleUrl(BuildConfig.MAP_STYLE);
        mapView.getMapAsync(new OnMapReadyCallback() {

            @Override
            public void onMapReady(MapboxMap mapboxMap) {
                MapFragment.this.mapboxMap = mapboxMap;
                instantiateMapBox(savedInstanceState);
            }
        });
    }
}
Also used : OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 8 with MapboxMap

use of com.mapbox.mapboxsdk.maps.MapboxMap in project osm-contributor by jawg.

the class MapFragment method changeMapZoomSmooth.

public void changeMapZoomSmooth(final double zoom, final OnZoomAnimationFinishedListener onZoomAnimationFinishedListener) {
    mapboxMap.easeCamera(new CameraUpdate() {

        @Override
        public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) {
            return new CameraPosition.Builder().target(mapboxMap.getCameraPosition().target).zoom(zoom).build();
        }
    }, 700);
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            onZoomAnimationFinishedListener.onZoomAnimationFinished();
        }
    }, 750);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Handler(android.os.Handler) BitmapHandler(io.jawg.osmcontributor.ui.utils.BitmapHandler) CameraUpdate(com.mapbox.mapboxsdk.camera.CameraUpdate) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 9 with MapboxMap

use of com.mapbox.mapboxsdk.maps.MapboxMap in project apps-android-wikipedia by wikimedia.

the class NearbyFragment method initializeMap.

private void initializeMap() {
    mapView.getMapAsync((@NonNull MapboxMap mapboxMap) -> {
        if (!isAdded()) {
            return;
        }
        NearbyFragment.this.mapboxMap = mapboxMap;
        enableUserLocationMarker();
        mapboxMap.getTrackingSettings().setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
        mapboxMap.setOnScrollListener(this::fetchNearbyPages);
        mapboxMap.setOnMarkerClickListener((@NonNull Marker marker) -> {
            NearbyPage page = findNearbyPageFromMarker(marker);
            if (page != null) {
                PageTitle title = new PageTitle(page.getTitle(), lastResult.getWiki(), page.getThumbUrl());
                onLoadPage(title, HistoryEntry.SOURCE_NEARBY, page.getLocation());
                return true;
            } else {
                return false;
            }
        });
        if (lastCameraPos != null) {
            mapboxMap.setCameraPosition(lastCameraPos);
        } else {
            goToUserLocationOrPromptPermissions();
        }
        if (lastResult != null) {
            showNearbyPages(lastResult);
        }
    });
}
Also used : NonNull(android.support.annotation.NonNull) PageTitle(org.wikipedia.page.PageTitle) Marker(com.mapbox.mapboxsdk.annotations.Marker) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 10 with MapboxMap

use of com.mapbox.mapboxsdk.maps.MapboxMap in project androidApp by InspectorIncognito.

the class VectorMapFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    Log.d("VectorMapFragment", "onViewCreated");
    super.onViewCreated(view, savedInstanceState);
    getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap resMapboxMap) {
            mapboxMap = resMapboxMap;
            clickListeners = new ArrayList<>();
            // mapboxMap.getUiSettings().setCompassImage(ContextCompat.getDrawable(getContext(), R.drawable.direction_arrow));
            mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {

                @Override
                public void onMapClick(@NonNull LatLng point) {
                    for (MultiLayerOnMapClickListener listener : clickListeners) {
                        if (listener.onMapClick(point)) {
                            return;
                        }
                    }
                }
            });
            locationEngine = new MultiLocationEngine();
            mapboxMap.getUiSettings().setCompassMargins(0, 27 * getResources().getDisplayMetrics().heightPixels / 100, 4 * getResources().getDisplayMetrics().widthPixels / 100, 0);
            onBusEngine = new OnBusEngine(mapboxMap);
            busStopPlugin = new BusStopPlugin(mapboxMap, getContext(), VectorMapFragment.this, onBusEngine);
            busUserPlugin = new BusUserPlugin(mapView, mapboxMap, locationEngine, VectorMapFragment.this, onBusEngine);
            clickListeners.add(busUserPlugin.getOnMapClickListener());
            clickListeners.add(busStopPlugin.getOnMapClickListener());
            outOfBusStopStackFrame = new MainActivity.OnBackButtonStack() {

                @Override
                public void onPressBackButton() {
                    busStopPlugin.clearSelectedFeature();
                }
            };
            mapboxMap.addOnScrollListener(new MapboxMap.OnScrollListener() {

                @Override
                public void onScroll() {
                    centerButton.deselectButton();
                    busUserPlugin.setTrackingEnabled(false);
                }
            });
            centerButton = new LocationToggleButton((ImageButton) getActivity().findViewById(R.id.floating_button_center), new LocationToggleButton.OnToggleButtonCheck() {

                @Override
                public void onButtonSelected() {
                    Log.d("VectorMapFragment", "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));
                    busUserPlugin.setTrackingEnabled(true);
                }

                @Override
                public void onButtonUnselected() {
                    busUserPlugin.setTrackingEnabled(false);
                }
            }, true);
            enableLocationPlugin();
            if (savedBus != null) {
                changeToOnBus(savedBus);
                savedBus = null;
            }
        }
    });
}
Also used : BusUserPlugin(cl.smartcities.isci.transportinspector.map.plugin.userPlugin.BusUserPlugin) MultiLocationEngine(cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine) ArrayList(java.util.ArrayList) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) MultiLayerOnMapClickListener(cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener) MultiLayerOnMapClickListener(cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener) NonNull(android.support.annotation.NonNull) OnBusEngine(cl.smartcities.isci.transportinspector.map.engine.OnBusEngine) BusStopPlugin(cl.smartcities.isci.transportinspector.map.plugin.busStopPlugin.BusStopPlugin) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Aggregations

MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)11 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)7 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)6 NonNull (android.support.annotation.NonNull)4 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)4 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 Marker (com.mapbox.mapboxsdk.annotations.Marker)3 UserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin)2 MapView (com.mapbox.mapboxsdk.maps.MapView)2 ValueAnimator (android.animation.ValueAnimator)1 Location (android.location.Location)1 Handler (android.os.Handler)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 View (android.view.View)1 OnBusEngine (cl.smartcities.isci.transportinspector.map.engine.OnBusEngine)1 BusStopPlugin (cl.smartcities.isci.transportinspector.map.plugin.busStopPlugin.BusStopPlugin)1 RouterPlugin (cl.smartcities.isci.transportinspector.map.plugin.routerPlugin.RouterPlugin)1 SearchPlugin (cl.smartcities.isci.transportinspector.map.plugin.searchPlugin.SearchPlugin)1 BusUserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.BusUserPlugin)1