Search in sources :

Example 1 with MultiLayerOnMapClickListener

use of cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener 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)

Example 2 with MultiLayerOnMapClickListener

use of cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener 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 3 with MultiLayerOnMapClickListener

use of cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener in project androidApp by InspectorIncognito.

the class VectorMapFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    Log.d("VectorMapFragment", "onViewCreated");
    super.onViewCreated(view, savedInstanceState);
    getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap resMapboxMap) {
            mapboxMap = resMapboxMap;
            clickListeners = new ArrayList<>();
            // mapboxMap.getUiSettings().setCompassImage(ContextCompat.getDrawable(getContext(), R.drawable.direction_arrow));
            mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {

                @Override
                public void onMapClick(@NonNull LatLng point) {
                    for (MultiLayerOnMapClickListener listener : clickListeners) {
                        if (listener.onMapClick(point)) {
                            return;
                        }
                    }
                }
            });
            locationEngine = new MultiLocationEngine();
            mapboxMap.getUiSettings().setCompassMargins(0, 27 * getResources().getDisplayMetrics().heightPixels / 100, 4 * getResources().getDisplayMetrics().widthPixels / 100, 0);
            onBusEngine = new OnBusEngine(mapboxMap);
            busStopPlugin = new BusStopPlugin(mapboxMap, getContext(), VectorMapFragment.this, onBusEngine);
            busUserPlugin = new BusUserPlugin(mapView, mapboxMap, locationEngine, VectorMapFragment.this, onBusEngine);
            clickListeners.add(busUserPlugin.getOnMapClickListener());
            clickListeners.add(busStopPlugin.getOnMapClickListener());
            outOfBusStopStackFrame = new MainActivity.OnBackButtonStack() {

                @Override
                public void onPressBackButton() {
                    busStopPlugin.clearSelectedFeature();
                }
            };
            mapboxMap.addOnScrollListener(new MapboxMap.OnScrollListener() {

                @Override
                public void onScroll() {
                    centerButton.deselectButton();
                    busUserPlugin.setTrackingEnabled(false);
                }
            });
            centerButton = new LocationToggleButton((ImageButton) getActivity().findViewById(R.id.floating_button_center), new LocationToggleButton.OnToggleButtonCheck() {

                @Override
                public void onButtonSelected() {
                    Log.d("VectorMapFragment", "onButtonSelected");
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        return;
                    }
                    mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationEngine.getLastLocation().getLatitude(), locationEngine.getLastLocation().getLongitude()), 16));
                    busUserPlugin.setTrackingEnabled(true);
                }

                @Override
                public void onButtonUnselected() {
                    busUserPlugin.setTrackingEnabled(false);
                }
            }, true);
            enableLocationPlugin();
            if (savedBus != null) {
                changeToOnBus(savedBus);
                savedBus = null;
            }
        }
    });
}
Also used : BusUserPlugin(cl.smartcities.isci.transportinspector.map.plugin.userPlugin.BusUserPlugin) MultiLocationEngine(cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine) ArrayList(java.util.ArrayList) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) MultiLayerOnMapClickListener(cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener) MultiLayerOnMapClickListener(cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener) NonNull(android.support.annotation.NonNull) OnBusEngine(cl.smartcities.isci.transportinspector.map.engine.OnBusEngine) BusStopPlugin(cl.smartcities.isci.transportinspector.map.plugin.busStopPlugin.BusStopPlugin) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Aggregations

NonNull (android.support.annotation.NonNull)3 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)3 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 PointF (android.graphics.PointF)2 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)2 Feature (com.mapbox.services.commons.geojson.Feature)2 ArrayList (java.util.ArrayList)2 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)1 OnBusEngine (cl.smartcities.isci.transportinspector.map.engine.OnBusEngine)1 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)1 BusStopClickHandler (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler)1 BusStopPlugin (cl.smartcities.isci.transportinspector.map.plugin.busStopPlugin.BusStopPlugin)1 BusUserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.BusUserPlugin)1 PeriodicRequestHandler (cl.smartcities.isci.transportinspector.periodicRequest.PeriodicRequestHandler)1 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)1 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)1 GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)1 List (java.util.List)1