Search in sources :

Example 1 with MapView

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));
    }
}
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 MapView

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;
        }
    });
}
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 MapView

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
        }
    }
}
Also used : Bundle(android.os.Bundle) SettingsProvider(org.odk.collect.settings.SettingsProvider) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) MapView(com.mapbox.mapboxsdk.maps.MapView) ViewGroup(android.view.ViewGroup) Inject(javax.inject.Inject) KEY_MAPBOX_INITIALIZED(org.odk.collect.settings.keys.MetaKeys.KEY_MAPBOX_INITIALIZED) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) NetworkStateProvider(org.odk.collect.android.network.NetworkStateProvider) Style(com.mapbox.mapboxsdk.maps.Style) Fragment(androidx.fragment.app.Fragment) R(org.odk.collect.android.R) View(android.view.View) Settings(org.odk.collect.shared.settings.Settings) FrameLayout(android.widget.FrameLayout) MapView(com.mapbox.mapboxsdk.maps.MapView) Settings(org.odk.collect.shared.settings.Settings)

Example 4 with MapView

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;
}
Also used : Context(android.content.Context) MapView(com.mapbox.mapboxsdk.maps.MapView)

Example 5 with MapView

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;
}
Also used : ListView(android.widget.ListView) StepAdapter(cl.smartcities.isci.transportinspector.adapters.StepAdapter) MapView(com.mapbox.mapboxsdk.maps.MapView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) RouterOptionAdapter(cl.smartcities.isci.transportinspector.adapters.RouterOptionAdapter) NonNull(android.support.annotation.NonNull)

Aggregations

MapView (com.mapbox.mapboxsdk.maps.MapView)5 View (android.view.View)3 NonNull (android.support.annotation.NonNull)2 Marker (com.mapbox.mapboxsdk.annotations.Marker)2 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)2 ValueAnimator (android.animation.ValueAnimator)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 Fragment (androidx.fragment.app.Fragment)1 RouterOptionAdapter (cl.smartcities.isci.transportinspector.adapters.RouterOptionAdapter)1 StepAdapter (cl.smartcities.isci.transportinspector.adapters.StepAdapter)1