Search in sources :

Example 1 with MapboxMap

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));
    }
}
Also used : MapboxMapOptions(com.mapbox.mapboxsdk.maps.MapboxMapOptions) GsonBuilder(com.google.gson.GsonBuilder) NonNull(android.support.annotation.NonNull) MapView(com.mapbox.mapboxsdk.maps.MapView) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Marker(com.mapbox.mapboxsdk.annotations.Marker) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 2 with MapboxMap

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;
        }
    });
}
Also used : WayMarker(io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarker) Marker(com.mapbox.mapboxsdk.annotations.Marker) ValueAnimator(android.animation.ValueAnimator) ZoomAnimationGestureDetector(io.jawg.osmcontributor.ui.utils.ZoomAnimationGestureDetector) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) MapView(com.mapbox.mapboxsdk.maps.MapView) View(android.view.View) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) MotionEvent(android.view.MotionEvent) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ScaleGestureDetector(android.view.ScaleGestureDetector) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) WayMarker(io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarker)

Example 3 with MapboxMap

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);
        }
    });
}
Also used : OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 4 with MapboxMap

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);
        }
    });
}
Also used : RouterPlugin(cl.smartcities.isci.transportinspector.map.plugin.routerPlugin.RouterPlugin) MultiLocationEngine(cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine) UserPlugin(cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 5 with MapboxMap

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()));
        }
    });
}
Also used : MultiLocationEngine(cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) SearchPlugin(cl.smartcities.isci.transportinspector.map.plugin.searchPlugin.SearchPlugin) NonNull(android.support.annotation.NonNull) UserPlugin(cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) Location(android.location.Location)

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