Search in sources :

Example 1 with BusStopMarker

use of cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker 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 BusStopMarker

use of cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker 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 3 with BusStopMarker

use of cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker 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 4 with BusStopMarker

use of cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker in project androidApp by InspectorIncognito.

the class BusStopPlugin method updateBusSource.

private void updateBusSource(List<ServerSentBus> buses) {
    List<Feature> markerCoordinates = new ArrayList<>();
    for (ServerSentBus bus : buses) {
        markerCoordinates.add(new BusMarker(bus, (BusStopMarker) selectedBusStop));
    }
    busesFeatures = FeatureCollection.fromFeatures(markerCoordinates);
    // the camera bearing
    for (Feature busFeature : busesFeatures.getFeatures()) {
        Number bearing = busFeature.getNumberProperty(BusMarker.PROPERTY_BEARING);
        double newBearing = (bearing.doubleValue() + mapboxMap.getCameraPosition().bearing) % 360;
        busFeature.addBooleanProperty(BusMarker.PROPERTY_LOOKING_LEFT, newBearing < 180);
        if (selectedBus != null && selectedBus.getId().equals(busFeature.getId())) {
            busFeature.addBooleanProperty(BusMarker.PROPERTY_MAXIMIZED, true);
            selectedBus = busFeature;
        }
    }
}
Also used : BusMarker(cl.smartcities.isci.transportinspector.map.model.bus.BusMarker) ArrayList(java.util.ArrayList) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) Feature(com.mapbox.services.commons.geojson.Feature) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

Example 5 with BusStopMarker

use of cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker in project androidApp by InspectorIncognito.

the class BusStopPlugin method updateBusStopEvents.

public void updateBusStopEvents(ArrayList<ServerSentEvent> newEvents, String reporterId) {
    if (selectedBusStop != null && reporterId.equals(selectedBusStop.getId())) {
        periodicRequestHandler.updateEvents(newEvents);
        BusStopMarker busStopMarker = (BusStopMarker) selectedBusStop;
        busStopMarker.setEvents(newEvents);
        refreshBusStopSource();
        updateSelectedBusStopIcons();
    }
}
Also used : BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker)

Aggregations

BusStopMarker (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker)8 Feature (com.mapbox.services.commons.geojson.Feature)7 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)6 ArrayList (java.util.ArrayList)6 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)2 Bitmap (android.graphics.Bitmap)1 View (android.view.View)1 GridHelper (cl.smartcities.isci.transportinspector.database.GridHelper)1 MapBusIconsBuilder (cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder)1 BusStopIconsBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)1 IconBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder)1 BusStopLoadingLayerTask (cl.smartcities.isci.transportinspector.map.tasks.BusStopLoadingLayerTask)1 GenerateViewIconTask (cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask)1 ServerSentBus (cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)1 ServerSentBusStopInfo (cl.smartcities.isci.transportinspector.model.gson.ServerSentBusStopInfo)1 ServerSentEvent (cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent)1 PeriodicRequestHandler (cl.smartcities.isci.transportinspector.periodicRequest.PeriodicRequestHandler)1 CameraUpdate (com.mapbox.mapboxsdk.camera.CameraUpdate)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 Comparator (java.util.Comparator)1