Search in sources :

Example 1 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition in project apps-android-wikipedia by wikimedia.

the class NearbyFragment method goToLocation.

private void goToLocation(@NonNull Location location) {
    if (mapboxMap == null) {
        return;
    }
    CameraPosition pos = new CameraPosition.Builder().target(new LatLng(location)).zoom(getResources().getInteger(R.integer.map_default_zoom)).build();
    mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(pos));
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 2 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition in project mapbox-plugins-android by mapbox.

the class LocationLayerPlugin method updateLocation.

/**
 * Updates the user location icon.
 *
 * @param location the latest user location
 * @since 0.1.0
 */
private void updateLocation(final Location location) {
    if (location == null) {
        return;
    }
    staleStateManager.updateLatestLocationTime();
    CameraPosition currentCameraPosition = mapboxMap.getCameraPosition();
    boolean isGpsNorth = getCameraMode() == CameraMode.TRACKING_GPS_NORTH;
    locationLayerAnimator.feedNewLocation(location, currentCameraPosition, isGpsNorth);
    locationLayer.updateAccuracyRadius(location);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition)

Example 3 with CameraPosition

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

use of com.mapbox.mapboxsdk.camera.CameraPosition in project androidApp by InspectorIncognito.

the class MapboxUtil method animateCameraToNewCameraPosition.

public static void animateCameraToNewCameraPosition(CameraPosition newCameraPosition, MapboxMap mapboxMap) {
    CameraPosition cameraPosition = mapboxMap.getCameraPosition();
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(createLatLngAnimator(cameraPosition.target, newCameraPosition.target, mapboxMap), createZoomAnimator(cameraPosition.zoom, Math.min(newCameraPosition.zoom, 16), mapboxMap));
    animatorSet.start();
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) AnimatorSet(android.animation.AnimatorSet)

Example 5 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition in project androidApp by InspectorIncognito.

the class RouterVectorMapFragment method zoomBound.

private void zoomBound(LatLng northEastPoint, LatLng southWestPoint) {
    LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
    latLngBoundsBuilder.include(northEastPoint);
    latLngBoundsBuilder.include(southWestPoint);
    CameraUpdate update = CameraUpdateFactory.newLatLngBounds(latLngBoundsBuilder.build(), 100, 100, 100, 100);
    CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
    if (cameraPosition == null) {
        return;
    }
    mapboxMap.setCameraPosition(cameraPosition);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) CameraUpdate(com.mapbox.mapboxsdk.camera.CameraUpdate)

Aggregations

CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)19 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)8 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)4 AnimatorSet (android.animation.AnimatorSet)3 Point (com.mapbox.geojson.Point)3 CameraUpdate (com.mapbox.mapboxsdk.camera.CameraUpdate)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Camera (com.mapbox.services.android.navigation.v5.navigation.camera.Camera)2 ValueAnimator (android.animation.ValueAnimator)1 Intent (android.content.Intent)1 Handler (android.os.Handler)1 Parcel (android.os.Parcel)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 View (android.view.View)1 LocationEngine (com.mapbox.android.core.location.LocationEngine)1 LocationEngineProvider (com.mapbox.android.core.location.LocationEngineProvider)1 LegStep (com.mapbox.api.directions.v5.models.LegStep)1 Marker (com.mapbox.mapboxsdk.annotations.Marker)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1