Search in sources :

Example 1 with Feature

use of com.mapbox.services.commons.geojson.Feature in project androidApp by InspectorIncognito.

the class OnBusEngine method setBusStops.

public void setBusStops(List<BusStop> busStops) {
    if (bus == null) {
        this.busStops = busStops;
        return;
    }
    List<Feature> features = new ArrayList<>();
    for (BusStop busStop : busStops) {
        if (contains(serviceBusStops, busStop.getId())) {
            features.add(new BusStopMarker(busStop));
        }
    }
    busStopSource.setGeoJson(FeatureCollection.fromFeatures(features));
}
Also used : ArrayList(java.util.ArrayList) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 2 with Feature

use of com.mapbox.services.commons.geojson.Feature in project androidApp by InspectorIncognito.

the class PolylineEngine method addBusRoutePolyline.

@NonNull
public Polyline addBusRoutePolyline(MapboxMap mapboxMap, ArrayList<LatLng> points, int colorId) {
    if (busRouteEndFeature == null) {
        setupPolylineVars(mapboxMap);
    }
    Feature startPoint = Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(points.get(0).getLongitude(), points.get(0).getLatitude())));
    Feature endPoint = Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(points.get(points.size() - 1).getLongitude(), points.get(points.size() - 1).getLatitude())));
    busRouteStartFeature = FeatureCollection.fromFeatures(new Feature[] { startPoint });
    busRouteEndFeature = FeatureCollection.fromFeatures(new Feature[] { endPoint });
    refreshSourceWithFeatures(busRouteStartSource, busRouteStartFeature);
    refreshSourceWithFeatures(busRouteEndSource, busRouteEndFeature);
    return mapboxMap.addPolyline(new PolylineOptions().addAll(points).color(ContextCompat.getColor(TranSappApplication.getAppContext(), colorId)).width(4));
}
Also used : Feature(com.mapbox.services.commons.geojson.Feature) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions) NonNull(android.support.annotation.NonNull)

Example 3 with Feature

use of com.mapbox.services.commons.geojson.Feature in project androidApp by InspectorIncognito.

the class BusStopPlugin method setupData.

private void setupData() {
    if (mapboxMap == null) {
        return;
    }
    GridHelper helper = new GridHelper(getContext());
    List<BusStop> busStops = helper.getNearBusStops(mapboxMap.getCameraPosition().target.getLatitude(), mapboxMap.getCameraPosition().target.getLongitude());
    helper.close();
    onBusEngine.setBusStops(busStops);
    List<Feature> markerCoordinates = new ArrayList<>();
    for (BusStop busStop : busStops) {
        markerCoordinates.add(new BusStopMarker(busStop));
    }
    busStopFeatures = FeatureCollection.fromFeatures(markerCoordinates);
    busesFeatures = FeatureCollection.fromFeatures(new Feature[] {});
    busRouteStartFeature = FeatureCollection.fromFeatures(new Feature[] {});
    busRouteEndFeature = FeatureCollection.fromFeatures(new Feature[] {});
    setupBusRouteSource();
    setupBusRouteLayer();
    setupBusStopSource();
    setupBusStopLayer();
    setupBusSource();
    setupBusLayer();
}
Also used : GridHelper(cl.smartcities.isci.transportinspector.database.GridHelper) ArrayList(java.util.ArrayList) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 4 with Feature

use of com.mapbox.services.commons.geojson.Feature in project androidApp by InspectorIncognito.

the class BusStopPlugin method busStopFeatureClick.

private void busStopFeatureClick(Feature busStopFeature, BusStopClickHandler handler) {
    if (selectedBus != null) {
        Log.d(BusStopPlugin.class.getSimpleName(), "selectedBus != null");
        deselectSelectedBusFeature();
    }
    final Feature newSelectedFeature = handler.handleMarkerClick(busStopFeature, busStopFeatures);
    if (newSelectedFeature != null) {
        Log.d(BusStopPlugin.class.getSimpleName(), "newSelectedFeature != null");
        if (busStopServiceCall != null && !busStopServiceCall.isCanceled()) {
            busStopServiceCall.cancel();
        }
        busesFeatures = FeatureCollection.fromFeatures(new Feature[] {});
        if (periodicRequestHandler != null) {
            periodicRequestHandler.stopPeriodicRequest();
            periodicRequestHandler = null;
        }
        refreshBusSource();
        Log.d(BusStopPlugin.class.getSimpleName(), "selectedBusStop assign");
        if (selectedBusStop != null) {
            deselectSelectedBusStop();
        }
        selectedBusStop = newSelectedFeature;
        final BusStop busStop = ((BusStopMarker) newSelectedFeature).getBusStop();
        final BusStopLoadingLayerTask loaderTask = new BusStopLoadingLayerTask(newSelectedFeature, new BusStopLoadingLayerTask.LoadingListener() {

            @Override
            public void refresh() {
                refreshBusStopSource();
            }
        });
        final Thread thread = new Thread(loaderTask);
        thread.start();
        busStopServiceCall = busStopInfoService.getBusStopData(Installation.getPhoneId(), newSelectedFeature.getStringProperty(BusStopMarker.PROPERTY_ID));
        /*Log the URL called*/
        Log.d(BusStopPlugin.class.getSimpleName(), busStopServiceCall.request().url().toString());
        busStopServiceCall.enqueue(new Callback<ServerSentBusStopInfo>() {

            @Override
            public void onResponse(Call<ServerSentBusStopInfo> call, Response<ServerSentBusStopInfo> response) {
                Log.d(BusStopPlugin.class.getSimpleName(), "onResponse");
                if (response == null || response.body() == null) {
                    if (response != null)
                        Log.e("BusStopPlugin", response.toString());
                    return;
                }
                periodicRequestHandler = new PeriodicRequestHandler(getContext(), BusStopPlugin.this, busStop, response.body().getEventsList());
                BusStopPlugin.this.onResponse(response.body().getBusList(), response.body().getEventsList(), loaderTask, thread);
            }

            @Override
            public void onFailure(Call<ServerSentBusStopInfo> call, Throwable t) {
                Log.d(BusStopPlugin.class.getSimpleName(), "onFailure");
                if (!call.isCanceled()) {
                    Toast.makeText(getContext(), "Error de conexión", Toast.LENGTH_SHORT).show();
                }
                loaderTask.stop();
                thread.interrupt();
                deselectSelectedBusStop(newSelectedFeature);
            }
        });
        listener.onBusStopFocusGained();
        animateCameraToSelection(newSelectedFeature);
    } else {
        refreshBusSource();
        centerCameraInSelection(busStopFeature);
    }
    refreshBusStopSource();
}
Also used : PeriodicRequestHandler(cl.smartcities.isci.transportinspector.periodicRequest.PeriodicRequestHandler) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) BusStopLoadingLayerTask(cl.smartcities.isci.transportinspector.map.tasks.BusStopLoadingLayerTask) Feature(com.mapbox.services.commons.geojson.Feature) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) ServerSentBusStopInfo(cl.smartcities.isci.transportinspector.model.gson.ServerSentBusStopInfo)

Example 5 with Feature

use of com.mapbox.services.commons.geojson.Feature 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

Feature (com.mapbox.services.commons.geojson.Feature)26 ArrayList (java.util.ArrayList)13 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)8 BusStopMarker (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker)7 Bitmap (android.graphics.Bitmap)4 NonNull (android.support.annotation.NonNull)4 View (android.view.View)4 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)4 ServerSentBus (cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)4 BusStopIconsBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)3 IconBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder)3 GenerateViewIconTask (cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask)3 PolylineOptions (com.mapbox.mapboxsdk.annotations.PolylineOptions)3 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 PointF (android.graphics.PointF)2 FavoriteHelper (cl.smartcities.isci.transportinspector.database.FavoriteHelper)2 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)2 BusStopClickHandler (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler)2 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)2 PeriodicRequestHandler (cl.smartcities.isci.transportinspector.periodicRequest.PeriodicRequestHandler)2