Search in sources :

Example 41 with LatLng

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

the class MapFragment method confirmPosition.

private void confirmPosition() {
    LatLng newPoiPosition;
    LatLng pos;
    switch(mapMode) {
        case POI_CREATION:
            if (getZoomLevel() < zoomVectorial) {
                changeMapZoomSmooth(15d);
            }
            createPoi();
            break;
        case NOTE_CREATION:
            pos = mapboxMap.getCameraPosition().target;
            NoteCommentDialogFragment dialog = NoteCommentDialogFragment.newInstance(pos.getLatitude(), pos.getLongitude());
            dialog.show(getActivity().getFragmentManager(), "dialog");
            break;
        case POI_POSITION_EDITION:
            Poi poi = (Poi) markerSelected.getRelatedObject();
            newPoiPosition = mapboxMap.getCameraPosition().target;
            eventBus.post(new PleaseApplyPoiPositionChange(newPoiPosition, poi.getId()));
            markerSelected.setPosition(newPoiPosition);
            markerSelected.setIcon(IconFactory.getInstance(getActivity()).fromBitmap(bitmapHandler.getMarkerBitmap(poi.getType(), Poi.computeState(false, false, true))));
            poi.setUpdated(true);
            mapboxMap.updateMarker(markerSelected);
            switchMode(MapMode.DETAIL_POI);
            break;
        case NODE_REF_POSITION_EDITION:
            PoiNodeRef poiNodeRef = wayMarkerSelected.getPoiNodeRef();
            newPoiPosition = mapboxMap.getCameraPosition().target;
            eventBus.post(new PleaseApplyNodeRefPositionChange(newPoiPosition, poiNodeRef.getId()));
            wayMarkerSelected.setPosition(newPoiPosition);
            wayMarkerSelected.setIcon(IconFactory.getInstance(getActivity()).fromBitmap(bitmapHandler.getNodeRefBitmap(PoiNodeRef.State.SELECTED)));
            removePolyline(editionPolyline);
            switchMode(MapMode.WAY_EDITION);
            break;
        case DETAIL_POI:
            getActivity().finish();
            break;
        default:
            break;
    }
}
Also used : PleaseApplyNodeRefPositionChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyNodeRefPositionChange) PleaseApplyPoiPositionChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiPositionChange) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) NoteCommentDialogFragment(io.jawg.osmcontributor.ui.dialogs.NoteCommentDialogFragment)

Example 42 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class BusStopPlugin method getOnMapClickListener.

public MultiLayerOnMapClickListener getOnMapClickListener() {
    return new MultiLayerOnMapClickListener() {

        @Override
        public boolean onMapClick(@NonNull LatLng point) {
            PointF screenPoint = mapboxMap.getProjection().toScreenLocation(point);
            final List<Feature> allFeatures = mapboxMap.queryRenderedFeatures(screenPoint);
            Collections.reverse(allFeatures);
            for (Feature feature : allFeatures) {
                if (feature.hasProperty(BusStopMarker.PROPERTY_TYPE) && feature.getStringProperty(BusStopMarker.PROPERTY_TYPE).equals(BusStopMarker.PROPERTY_TYPE_BUS_STOP)) {
                    BusStopClickHandler handler = new BusStopClickHandler(getContext().getResources(), periodicRequestHandler, BusStopPlugin.this);
                    // BUS STOP FEATURE CLICK
                    final List<Feature> busStopsInfoWindows = mapboxMap.queryRenderedFeatures(screenPoint, BUS_STOP_INFO_WINDOW_LAYER_ID_MAX, BUS_STOP_INFO_WINDOW_LAYER_ID_MIN);
                    if (!busStopsInfoWindows.isEmpty()) {
                        // INFO WINDOW CLICK
                        Feature busStopInfoWindowFeature = getFeatureByStringProperty(busStopsInfoWindows.get(0), busStopFeatures, BusStopMarker.PROPERTY_ID);
                        PointF symbolScreenPoint = mapboxMap.getProjection().toScreenLocation(MapboxUtil.convertToLatLng(busStopInfoWindowFeature));
                        if (handler.handleInfoWindowClick(busStopInfoWindowFeature, screenPoint, symbolScreenPoint, viewMap)) {
                            if (selectedBus != null) {
                                deselectSelectedBusFeature();
                                centerCameraInSelection(busStopInfoWindowFeature);
                            }
                            refreshBusStopSource();
                        }
                        return true;
                    } else {
                        // MARKER CLICK
                        Log.d(BusStopPlugin.class.getSimpleName(), "MARKER CLICK");
                        busStopFeatureClick(feature, handler);
                        return true;
                    }
                } else if (feature.hasProperty(BusMarker.PROPERTY_TYPE) && feature.getStringProperty(BusMarker.PROPERTY_TYPE).equals(BusMarker.PROPERTY_TYPE_BUS)) {
                    // BUS FEATURE CLICK
                    final List<Feature> infoWindowFeature = mapboxMap.queryRenderedFeatures(screenPoint, BUS_INFO_WINDOW_LAYER_ID_MAX);
                    if (!infoWindowFeature.isEmpty()) {
                        BusClickHandler handler = new BusClickHandler(getContext().getResources(), periodicRequestHandler, listener);
                        Feature selectedFeature = getFeatureByStringProperty(infoWindowFeature.get(0), busesFeatures, Marker.PROPERTY_ID);
                        PointF symbolScreenPoint = mapboxMap.getProjection().toScreenLocation(MapboxUtil.convertToLatLng(feature));
                        assert (selectedFeature) != null;
                        if (handler.handleInfoWindowClick(((BusMarker) selectedFeature).getBus(), screenPoint, symbolScreenPoint, viewMap, false)) {
                            return true;
                        }
                    }
                    busFeatureClick(feature);
                    return true;
                }
            }
            // we didn't find a click event on any layer
            if (busStopServiceCall != null && !busStopServiceCall.isCanceled()) {
                Log.d(BusStopPlugin.class.getSimpleName(), "busStopServiceCall.cancel()");
                busStopServiceCall.cancel();
            } else if (selectedBusStop != null) {
                deselectSelectedBusStop();
            }
            return false;
        }
    };
}
Also used : BusMarker(cl.smartcities.isci.transportinspector.map.model.bus.BusMarker) NonNull(android.support.annotation.NonNull) PointF(android.graphics.PointF) BusStopClickHandler(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler) List(java.util.List) ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MultiLayerOnMapClickListener(cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener) Feature(com.mapbox.services.commons.geojson.Feature) BusClickHandler(cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)

Example 43 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class BusStopPlugin method busFeatureClick.

private void busFeatureClick(Feature selectedBusFeature) {
    Log.d("BusStopPlugin", "busFeatureClick");
    Feature busFeature = getFeatureByStringProperty(selectedBusFeature, busesFeatures, BusMarker.PROPERTY_ID);
    if (busFeature == null) {
        return;
    }
    if (selectedBus != null) {
        if (busFeature.getId().equals(selectedBus.getId())) {
            boolean maximized = selectedBus.getBooleanProperty(BusMarker.PROPERTY_MAXIMIZED);
            selectedBus.addBooleanProperty(BusMarker.PROPERTY_MAXIMIZED, !maximized);
            refreshBusSource();
            return;
        } else {
            deselectSelectedBusFeature();
        }
    }
    busFeature.addBooleanProperty(BusMarker.PROPERTY_MAXIMIZED, true);
    selectedBus = busFeature;
    selectedBusStop.addBooleanProperty(BusStopMarker.PROPERTY_MAXIMIZED, false);
    refreshBusSource();
    refreshBusStopSource();
    RouteHelper helper = new RouteHelper(getContext());
    ServerSentBus bus = ((BusMarker) busFeature).getBus();
    ArrayList<LatLng> points = helper.getRoute(bus.getService(), bus.getDirection());
    busPolyline = addBusRoutePolyline(points, Constants.BUS_COLOR.get(bus.getColorArrayIndex()));
    animateCameraToSelection(busFeature);
}
Also used : BusMarker(cl.smartcities.isci.transportinspector.map.model.bus.BusMarker) RouteHelper(cl.smartcities.isci.transportinspector.database.RouteHelper) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Feature(com.mapbox.services.commons.geojson.Feature) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

Example 44 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class UserPlugin method locationChangeAnimate.

/*
   * Animators
   */
/**
 * Handles the animation from currentSourcePoint to the new user location point.
 */
private void locationChangeAnimate(@NonNull final GeoJsonSource locationGeoJsonSource, @NonNull Point currentSourcePoint, @NonNull Point newPoint) {
    if (locationChangeAnimator != null) {
        locationChangeAnimator.end();
    }
    locationChangeAnimator = ValueAnimator.ofObject(new PointEvaluator(), currentSourcePoint, newPoint);
    locationChangeAnimator.setDuration(linearAnimation ? getLocationUpdateDuration() : LocationLayerConstants.LOCATION_UPDATE_DELAY_MS);
    if (linearAnimation) {
        locationChangeAnimator.setInterpolator(new LinearInterpolator());
    } else {
        locationChangeAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    }
    locationChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            previousPoint = (Point) animation.getAnimatedValue();
            userLocationFeature.setGeometry(previousPoint);
            locationGeoJsonSource.setGeoJson(userLocationFeature);
            if (tracking) {
                mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(previousPoint.getCoordinates().getLatitude(), previousPoint.getCoordinates().getLongitude())));
            }
        }
    });
    locationChangeAnimator.start();
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Point(com.mapbox.services.commons.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ValueAnimator(android.animation.ValueAnimator)

Example 45 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class MapboxUtil method convertToLatLng.

public static LatLng convertToLatLng(Feature feature) {
    Point symbolPoint = (Point) feature.getGeometry();
    Position position = symbolPoint.getCoordinates();
    return new LatLng(position.getLatitude(), position.getLongitude());
}
Also used : Position(com.mapbox.services.commons.models.Position) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Point(com.mapbox.services.commons.geojson.Point) ILatLng(com.mapbox.mapboxsdk.geometry.ILatLng) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

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