Search in sources :

Example 1 with RouterPlugin

use of cl.smartcities.isci.transportinspector.map.plugin.routerPlugin.RouterPlugin 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)

Aggregations

MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)1 RouterPlugin (cl.smartcities.isci.transportinspector.map.plugin.routerPlugin.RouterPlugin)1 UserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)1 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)1