Search in sources :

Example 1 with OnMapReadyCallback

use of com.mapbox.mapboxsdk.maps.OnMapReadyCallback 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 OnMapReadyCallback

use of com.mapbox.mapboxsdk.maps.OnMapReadyCallback 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 3 with OnMapReadyCallback

use of com.mapbox.mapboxsdk.maps.OnMapReadyCallback 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 4 with OnMapReadyCallback

use of com.mapbox.mapboxsdk.maps.OnMapReadyCallback 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)

Example 5 with OnMapReadyCallback

use of com.mapbox.mapboxsdk.maps.OnMapReadyCallback 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)

Aggregations

MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)7 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)7 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)4 NonNull (android.support.annotation.NonNull)3 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 UserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin)2 Location (android.location.Location)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 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)1 GsonBuilder (com.google.gson.GsonBuilder)1 Marker (com.mapbox.mapboxsdk.annotations.Marker)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1 MapboxMapOptions (com.mapbox.mapboxsdk.maps.MapboxMapOptions)1 ArrayList (java.util.ArrayList)1