Search in sources :

Example 1 with MapClickEvent

use of com.mapbox.rctmgl.events.MapClickEvent in project maps by rnmapbox.

the class RCTMGLMapView method onMapClick.

@Override
public boolean onMapClick(@NonNull LatLng point) {
    if (mAnnotationClicked) {
        mAnnotationClicked = false;
        return true;
    }
    PointF screenPoint = mMap.getProjection().toScreenLocation(point);
    List<RCTSource> touchableSources = getAllTouchableSources();
    Map<String, List<Feature>> hits = new HashMap<>();
    List<RCTSource> hitTouchableSources = new ArrayList<>();
    for (RCTSource touchableSource : touchableSources) {
        Map<String, Double> hitbox = touchableSource.getTouchHitbox();
        if (hitbox == null) {
            continue;
        }
        float halfWidth = hitbox.get("width").floatValue() / 2.0f;
        float halfHeight = hitbox.get("height").floatValue() / 2.0f;
        RectF hitboxF = new RectF();
        hitboxF.set(screenPoint.x - halfWidth, screenPoint.y - halfHeight, screenPoint.x + halfWidth, screenPoint.y + halfHeight);
        List<Feature> features = mMap.queryRenderedFeatures(hitboxF, touchableSource.getLayerIDs());
        if (features.size() > 0) {
            hits.put(touchableSource.getID(), features);
            hitTouchableSources.add(touchableSource);
        }
    }
    if (hits.size() > 0) {
        RCTSource source = getTouchableSourceWithHighestZIndex(hitTouchableSources);
        if (source != null && source.hasPressListener()) {
            source.onPress(new RCTSource.OnPressEvent(hits.get(source.getID()), point, screenPoint));
            return true;
        }
    }
    MapClickEvent event = new MapClickEvent(this, point, screenPoint);
    mManager.handleEvent(event);
    return false;
}
Also used : RCTSource(com.mapbox.rctmgl.components.styles.sources.RCTSource) HashMap(java.util.HashMap) PointF(android.graphics.PointF) ArrayList(java.util.ArrayList) Feature(com.mapbox.geojson.Feature) AbstractMapFeature(com.mapbox.rctmgl.components.AbstractMapFeature) RectF(android.graphics.RectF) MapClickEvent(com.mapbox.rctmgl.events.MapClickEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with MapClickEvent

use of com.mapbox.rctmgl.events.MapClickEvent in project maps by rnmapbox.

the class RCTMGLMapView method onMapClick.

@Override
public boolean onMapClick(@NonNull Point point) {
    RCTMGLMapView _this = this;
    /*if (mPointAnnotationManager != nil) {
            getAnnotations()
        }*/
    if (mAnnotationClicked) {
        mAnnotationClicked = false;
        return true;
    }
    ScreenCoordinate screenPoint = mMap.pixelForCoordinate(point);
    List<RCTSource> touchableSources = getAllTouchableSources();
    HashMap<String, List<Feature>> hits = new HashMap<>();
    handleTapInSources(new LinkedList<>(touchableSources), screenPoint, hits, new ArrayList<>(), new HandleTap() {

        @Override
        public void run(List<RCTSource> hitTouchableSources, Map<String, List<Feature>> hits) {
            if (hits.size() > 0) {
                RCTSource source = getTouchableSourceWithHighestZIndex(hitTouchableSources);
                if (source != null && source.hasPressListener()) {
                    source.onPress(new RCTSource.OnPressEvent(hits.get(source.getID()), GeoJSONUtils.toLatLng(point), new PointF((float) screenPoint.getX(), (float) screenPoint.getY())));
                    return;
                }
            }
            MapClickEvent event = new MapClickEvent(_this, new LatLng(point), screenPoint);
            mManager.handleEvent(event);
        }
    });
    return false;
}
Also used : RCTSource(com.mapbox.rctmgl.components.styles.sources.RCTSource) HashMap(java.util.HashMap) ScreenCoordinate(com.mapbox.maps.ScreenCoordinate) PointF(android.graphics.PointF) MapClickEvent(com.mapbox.rctmgl.events.MapClickEvent) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LatLng(com.mapbox.rctmgl.utils.LatLng)

Example 3 with MapClickEvent

use of com.mapbox.rctmgl.events.MapClickEvent in project maps by rnmapbox.

the class RCTMGLMapView method onMapLongClick.

@Override
public boolean onMapLongClick(@NonNull LatLng point) {
    if (mAnnotationClicked) {
        mAnnotationClicked = false;
        return true;
    }
    PointF screenPoint = mMap.getProjection().toScreenLocation(point);
    MapClickEvent event = new MapClickEvent(this, point, screenPoint, EventTypes.MAP_LONG_CLICK);
    mManager.handleEvent(event);
    return false;
}
Also used : MapClickEvent(com.mapbox.rctmgl.events.MapClickEvent) PointF(android.graphics.PointF)

Aggregations

PointF (android.graphics.PointF)3 MapClickEvent (com.mapbox.rctmgl.events.MapClickEvent)3 RCTSource (com.mapbox.rctmgl.components.styles.sources.RCTSource)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 RectF (android.graphics.RectF)1 Feature (com.mapbox.geojson.Feature)1 ScreenCoordinate (com.mapbox.maps.ScreenCoordinate)1 AbstractMapFeature (com.mapbox.rctmgl.components.AbstractMapFeature)1 LatLng (com.mapbox.rctmgl.utils.LatLng)1 LinkedList (java.util.LinkedList)1