Search in sources :

Example 1 with BusStopClickHandler

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

the class BusStopPlugin method moveCenterInAndOpen.

public void moveCenterInAndOpen(String id) {
    if (selectedBusStop != null) {
        if (selectedBusStop.getStringProperty(Marker.PROPERTY_ID).equals(id)) {
            MapboxUtil.animateCameraToSelection(selectedBusStop, animatorSet, mapboxMap);
            return;
        } else {
            deselectSelectedBusStop();
        }
    }
    Feature busStopFeature = getFeature(id, busStopFeatures, BusStopMarker.PROPERTY_ID);
    BusStopClickHandler handler = new BusStopClickHandler(getContext().getResources(), periodicRequestHandler, BusStopPlugin.this);
    if (busStopFeature == null) {
        BusStopHelper helper = new BusStopHelper(getContext());
        ArrayList<BusStop> busStops = new ArrayList<>();
        busStops.add(helper.getBusStopById(id));
        updateBusStopSource(busStops);
        busStopFeature = busStopFeatures.getFeatures().get(0);
    }
    busStopFeatureClick(busStopFeature, handler);
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) ArrayList(java.util.ArrayList) BusStopClickHandler(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 2 with BusStopClickHandler

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

Aggregations

BusStopClickHandler (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler)2 Feature (com.mapbox.services.commons.geojson.Feature)2 ArrayList (java.util.ArrayList)2 PointF (android.graphics.PointF)1 NonNull (android.support.annotation.NonNull)1 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)1 BusStopHelper (cl.smartcities.isci.transportinspector.database.BusStopHelper)1 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)1 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)1 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 List (java.util.List)1