Search in sources :

Example 11 with Feature

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

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

the class BusStopPlugin method onFavIconClick.

@Override
public void onFavIconClick(final String busStopId) {
    final FavoriteHelper helper = new FavoriteHelper(getContext());
    final boolean isFavorite = helper.isFavorite(busStopId);
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
    final GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            }
            refreshBusStopSource();
        }
    }, viewMap, buildingList);
    new Thread(new Runnable() {

        @Override
        public void run() {
            if (isFavorite) {
                helper.removeFavoriteBusStop(busStopId);
            } else {
                helper.addFavoriteBusStop(busStopId);
            }
            task.execute();
        }
    }).start();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) Bitmap(android.graphics.Bitmap) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)

Example 13 with Feature

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

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

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

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