Search in sources :

Example 11 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project osm-contributor by jawg.

the class MapFragment method onPause.

@Override
public void onPause() {
    super.onPause();
    mapView.onPause();
    if (mapboxMap != null) {
        LatLng location = mapboxMap.getCameraPosition().target;
        sharedPreferences.edit().putFloat("latitude", (float) location.getLatitude()).apply();
        sharedPreferences.edit().putFloat("longitude", (float) location.getLongitude()).apply();
        mapboxMap.setMyLocationEnabled(false);
    }
    if (valueAnimator != null) {
        valueAnimator.cancel();
        valueAnimator.removeAllListeners();
        valueAnimator.removeAllUpdateListeners();
    }
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 12 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project osm-contributor by jawg.

the class MapFragment method onCameraChangeUpdatePolyline.

public void onCameraChangeUpdatePolyline() {
    if (editionPolyline != null) {
        List<LatLng> points = editionPolyline.getPoints();
        points.set(1, mapboxMap.getCameraPosition().target);
        removePolyline(editionPolyline);
        editionPolyline = new PolylineOptions().addAll(points).alpha(0.4f).width(1.8f).color(Color.parseColor("#F57C00"));
        mapboxMap.addPolyline(editionPolyline);
    }
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Example 13 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project osm-contributor by jawg.

the class MapFragment method onPleaseDuplicatePoiFromMapEvent.

/*-----------------------------------------------------------
    * POI DUPLICATION
    *---------------------------------------------------------*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseDuplicatePoiFromMapEvent(PleaseDuplicatePoiEvent event) {
    Poi poi = (Poi) markerSelected.getRelatedObject();
    poiTypeSelected(poi.getType());
    mapboxMap.setCameraPosition(new CameraPosition.Builder().target(new LatLng(poi.getLatitude(), poi.getLongitude())).build());
    switchMode(MapMode.POI_CREATION);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Poi(io.jawg.osmcontributor.model.entities.Poi) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 14 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project osm-contributor by jawg.

the class MapboxListener method onCameraZoomChange.

/**
 * The zoom change
 * @param zoom
 */
private void onCameraZoomChange(double zoom) {
    // For testing purpose
    mapFragment.setZoomLevelText(df.format(zoom));
    boolean isVectorial = mapFragment.isVectorial();
    if (zoom < mapFragment.getZoomVectorial()) {
        mapFragment.getLevelBar().setVisibility(View.INVISIBLE);
        mapFragment.getAddressView().setVisibility(View.INVISIBLE);
        if (isVectorial) {
            mapFragment.setVectorial(false);
            mapFragment.applyPoiFilter();
        }
    } else {
        LatLng center = mapboxMap.getCameraPosition().target;
        mapFragment.getGeocoder().delayedReverseGeocoding(center.getLatitude(), center.getLongitude());
        if (mapFragment.getLevelBar().getLevels().length > 1) {
            mapFragment.getLevelBar().setVisibility(View.VISIBLE);
        }
        if (!isVectorial) {
            mapFragment.setVectorial(true);
            mapFragment.applyPoiFilter();
        }
    }
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 15 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng 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)

Aggregations

LatLng (com.mapbox.mapboxsdk.geometry.LatLng)56 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)12 ArrayList (java.util.ArrayList)10 Point (com.mapbox.geojson.Point)7 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)6 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)6 NonNull (android.support.annotation.NonNull)5 PointF (android.graphics.PointF)4 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)4 ValueAnimator (android.animation.ValueAnimator)3 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)3 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)3 Poi (io.jawg.osmcontributor.model.entities.Poi)3 Subscribe (org.greenrobot.eventbus.Subscribe)3 Intent (android.content.Intent)2 Location (android.location.Location)2 View (android.view.View)2 RouteHelper (cl.smartcities.isci.transportinspector.database.RouteHelper)2 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)2