Search in sources :

Example 6 with BusStopMarker

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

the class BusStopPlugin method onResponse.

private void onResponse(ArrayList<ServerSentBus> buses, ArrayList<ServerSentEvent> events, final BusStopLoadingLayerTask loaderTask, final Thread thread) {
    buses = filterBuses(buses);
    updateBusSource(buses);
    for (ServerSentEvent event : events) {
        event.finishInitialization();
    }
    ((BusStopMarker) selectedBusStop).setEvents(events);
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
    buildingList.add(new MapBusIconsBuilder(FeatureCollection.fromFeatures(busesFeatures.getFeatures())).toBuilder());
    GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (selectedBusStop == null) {
                return;
            }
            Log.d(BusStopPlugin.class.getSimpleName(), "onImageGenResult");
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            } else {
                return;
            }
            selectedBusStop.addBooleanProperty(BusStopMarker.PROPERTY_LOADING, false);
            if (loaderTask != null && thread != null) {
                loaderTask.stop();
                thread.interrupt();
            }
            refreshBusStopSource();
            refreshBusSource();
            if (!busesFeatures.getFeatures().isEmpty()) {
                Collections.sort(busesFeatures.getFeatures(), new Comparator<Feature>() {

                    @Override
                    public int compare(Feature bus1, Feature bus2) {
                        BusMarker m1 = (BusMarker) bus1;
                        BusMarker m2 = (BusMarker) bus2;
                        return m1.getBus().getDistanceToBusStop() < m2.getBus().getDistanceToBusStop() ? -1 : (m1.getBus().getDistanceToBusStop() == m2.getBus().getDistanceToBusStop() ? 0 : 1);
                    }
                });
                Feature busFeature = busesFeatures.getFeatures().get(0);
                LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
                latLngBoundsBuilder.include(MapboxUtil.convertToLatLng(busFeature));
                latLngBoundsBuilder.include(MapboxUtil.getRotatePoint(busFeature, selectedBusStop, busFeature.getNumberProperty(BusMarker.PROPERTY_BEARING).doubleValue()));
                CameraUpdate update = CameraUpdateFactory.newLatLngBounds(latLngBoundsBuilder.build(), 100, 100, 100, 100);
                if (loaderTask != null && thread != null) {
                    MapboxUtil.animateCameraToNewCameraPosition(update.getCameraPosition(mapboxMap), mapboxMap);
                    // mapboxMap.animateCamera(update, 1000);
                    periodicRequestHandler.startPeriodicRequest();
                    final BusStop busStop = ((BusStopMarker) selectedBusStop).getBusStop();
                    listener.onBusStopSelected(busStop);
                }
            }
        }
    }, viewMap, buildingList);
    ((BusStopMarker) selectedBusStop).getBusStop().setIncomingBuses(buses);
    task.execute();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder) MapBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) Comparator(java.util.Comparator) Bitmap(android.graphics.Bitmap) MapBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder) BusMarker(cl.smartcities.isci.transportinspector.map.model.bus.BusMarker) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder) CameraUpdate(com.mapbox.mapboxsdk.camera.CameraUpdate) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 7 with BusStopMarker

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

the class BusStopPlugin method updateBusStopSource.

private void updateBusStopSource(List<BusStop> busStops) {
    List<Feature> markerCoordinates = new ArrayList<>();
    boolean added = false;
    for (BusStop busStop : busStops) {
        if (selectedBusStop != null && selectedBusStop.getStringProperty(BusStopMarker.PROPERTY_ID).equals(busStop.getId())) {
            markerCoordinates.add(selectedBusStop);
            added = true;
        } else {
            markerCoordinates.add(new BusStopMarker(busStop));
        }
    }
    if (selectedBusStop != null && !added)
        markerCoordinates.add(selectedBusStop);
    busStopFeatures = FeatureCollection.fromFeatures(markerCoordinates);
    refreshBusStopSource();
}
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 8 with BusStopMarker

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

the class SearchBusStopEngine method updateBusStopSource.

public void updateBusStopSource(List<BusStop> busStops) {
    List<Feature> markerCoordinates = new ArrayList<>();
    for (BusStop busStop : busStops) {
        markerCoordinates.add(new BusStopMarker(busStop));
    }
    busStopFeatures = FeatureCollection.fromFeatures(markerCoordinates);
    refreshSourceWithFeatures(busStopSource, busStopFeatures);
}
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)

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