Search in sources :

Example 21 with LatLng

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

the class MapboxUtil method getRotatePoint.

public static LatLng getRotatePoint(Feature pointToRotate, Feature pivotPoint, double bearing) {
    LatLng p1 = convertToLatLng(pointToRotate);
    LatLng p2 = convertToLatLng(pivotPoint);
    int distance = distanceTo(p1, p2);
    return destinationPoint(p2, distance, (float) bearing);
}
Also used : ILatLng(com.mapbox.mapboxsdk.geometry.ILatLng) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Point(com.mapbox.services.commons.geojson.Point)

Example 22 with LatLng

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

the class RouteHelper method cursorToRouteList.

/**
 * Creates a List<Pair> based on the Cursor information
 *
 * @param cursor
 * @return List of RoutePoint
 */
private ArrayList<LatLng> cursorToRouteList(Cursor cursor) {
    ArrayList<LatLng> route = new ArrayList<>();
    while (cursor.moveToNext()) {
        double lat = cursor.getDouble(2);
        double lon = cursor.getDouble(3);
        route.add(new LatLng(lat, lon));
    }
    return route;
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 23 with LatLng

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

the class RouteHelper method getRoute.

/**
 * Return a list of pair<latitude, longitude> that describe the route of a service
 * with a direction defined.
 *
 * @param serviceName Name of bus service, ex: 506, 506e, D03, D03N
 * @param direction the route direction used by service
 * @return List of pair<latitude,longitude>
 */
public ArrayList<LatLng> getRoute(String serviceName, String direction) {
    String query = "SELECT * FROM " + DataBaseContract.Route.TABLE_NAME + " WHERE " + DataBaseContract.Route.SERVICE + " = ?" + " ORDER BY " + DataBaseContract.Route.SEQUENCE + " ASC";
    String[] params = new String[] { serviceName + direction };
    Cursor cursor = this.getReadableDatabase().rawQuery(query, params);
    ArrayList<LatLng> route = this.cursorToRouteList(cursor);
    cursor.close();
    this.close();
    return route;
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Cursor(android.database.Cursor)

Example 24 with LatLng

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");
    busButton = new BusToggleButton((ImageView) findViewById(R.id.floating_button_bus), null, false);
    userMapLevel = findViewById(R.id.user_map_level);
    userMapLevel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openActivity(AccountActivity.class);
        }
    });
    findViewById(R.id.floating_button_bus).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            busButtonClick();
        }
    });
    // Sliding Panel Initialization
    initializeSlidingPanel();
    tittleView = getLayoutInflater().inflate(R.layout.activity_main_title_bar, null);
    tittleText = tittleView.findViewById(R.id.activity_main_title_text);
    tittleImage = tittleView.findViewById(R.id.activity_main_title_image);
    // Connection Message
    MessageLayout = findViewById(R.id.textOfflineBar);
    ConnectionChange = ConnectionChangeReceiver.getBroadcastReceiverInstance();
    // Create supportMapFragment
    if (savedInstanceState == null) {
        // Create fragment
        final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        Location location = PositionProvider.getInstance().getLastKnownLocation();
        // Build mapboxMap
        MapboxMapOptions options = new MapboxMapOptions();
        options.styleUrl(Style.MAPBOX_STREETS);
        options.camera(new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude())).zoom(16).build());
        // Create map fragment
        mapFragment = VectorMapFragment.newInstance(options);
        // Add map fragment to parent container
        transaction.add(R.id.container, mapFragment, "com.mapbox.map");
        transaction.commit();
    } else {
        mapFragment = (VectorMapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
    }
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey(BUS_SERVICE_KEY) && extras.containsKey(BUS_TOKEN_KEY)) {
            showEvaluationDialog(extras.getString(BUS_SERVICE_KEY), extras.getString(BUS_TOKEN_KEY));
        }
    }
    onFoot();
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) AccountActivity(cl.smartcities.isci.transportinspector.gamification.ui.AccountActivity) Bundle(android.os.Bundle) MapboxMapOptions(com.mapbox.mapboxsdk.maps.MapboxMapOptions) BusToggleButton(cl.smartcities.isci.transportinspector.map.buttons.BusToggleButton) ImageView(android.widget.ImageView) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Location(android.location.Location)

Example 25 with LatLng

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

the class BusUserPlugin 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(LocationLayerConstants.PROPERTY_ON_BUS) && feature.getBooleanProperty(LocationLayerConstants.PROPERTY_ON_BUS).equals(true)) {
                    // BUS FEATURE CLICK
                    final List<Feature> infoWindowFeature = mapboxMap.queryRenderedFeatures(screenPoint, LocationLayerConstants.LOCATION_LAYER_INFO_WINDOW);
                    if (!infoWindowFeature.isEmpty()) {
                        PeriodicRequestHandler periodicRequestHandler = new PeriodicRequestHandler(TranSappApplication.getAppContext(), null, null);
                        BusClickHandler handler = new BusClickHandler(TranSappApplication.getAppContext().getResources(), periodicRequestHandler, listener);
                        PointF symbolScreenPoint = mapboxMap.getProjection().toScreenLocation(MapboxUtil.convertToLatLng(feature));
                        if (handler.handleInfoWindowClick(currentUserBus, screenPoint, symbolScreenPoint, viewMap, true)) {
                            return true;
                        }
                        minimizeFeature();
                        return true;
                    }
                    userLocationFeature.addBooleanProperty(LocationLayerConstants.PROPERTY_MAXIMIZED, true);
                    GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
                    if (locationGeoJsonSource == null) {
                        return true;
                    }
                    locationGeoJsonSource.setGeoJson(userLocationFeature);
                    return true;
                }
            }
            // we didn't find a click event on any layer
            minimizeFeature();
            return false;
        }
    };
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) PeriodicRequestHandler(cl.smartcities.isci.transportinspector.periodicRequest.PeriodicRequestHandler) NonNull(android.support.annotation.NonNull) PointF(android.graphics.PointF) 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)

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