Search in sources :

Example 1 with ScreenCoordinate

use of com.mapbox.maps.ScreenCoordinate in project maps by rnmapbox.

the class RCTMGLCamera method getUserLocationUpdateCameraOptions.

private CameraOptions getUserLocationUpdateCameraOptions(double zoomLevel) {
    LatLng center = mUserLocation.getCoordinate();
    ScreenCoordinate anchor = CameraAnimationsUtils.getCamera(mMapView).getAnchor();
    CameraState actState = mMapView.getMapboxMap().getCameraState();
    if (mUserLocationVerticalAlignment != UserLocationVerticalAlignment.CENTER) {
        CameraOptions options = ExtensionUtils.toCameraOptions(actState, anchor);
        CoordinateBounds bounds = mMapView.getMapboxMap().coordinateBoundsForCamera(options);
        switch(mUserLocationVerticalAlignment) {
            case UserLocationVerticalAlignment.TOP:
                center = new LatLng(bounds.getNortheast().latitude(), center.getLongitude());
                break;
            case UserLocationVerticalAlignment.BOTTOM:
                center = new LatLng(bounds.getSouthwest().latitude(), center.getLongitude());
                break;
        }
    }
    return new CameraOptions.Builder().center(center.getPoint()).bearing(getDirectionForUserLocationUpdate()).pitch(mPitch).anchor(anchor).padding(actState.getPadding()).zoom(zoomLevel).build();
}
Also used : CameraState(com.mapbox.maps.CameraState) ScreenCoordinate(com.mapbox.maps.ScreenCoordinate) CameraOptions(com.mapbox.maps.CameraOptions) LatLng(com.mapbox.rctmgl.utils.LatLng) CoordinateBounds(com.mapbox.maps.CoordinateBounds)

Example 2 with ScreenCoordinate

use of com.mapbox.maps.ScreenCoordinate 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 ScreenCoordinate

use of com.mapbox.maps.ScreenCoordinate in project maps by rnmapbox.

the class RCTMGLMapView method handleTapInSources.

void handleTapInSources(LinkedList<RCTSource> sources, ScreenCoordinate screenPoint, HashMap<String, List<Feature>> hits, ArrayList<RCTSource> hitTouchableSources, HandleTap handleTap) {
    if (sources.isEmpty()) {
        handleTap.run(hitTouchableSources, hits);
        return;
    }
    RCTSource source = sources.removeFirst();
    Map<String, Double> hitbox = source.getTouchHitbox();
    if (hitbox != null) {
        double halfWidth = hitbox.get("width").floatValue() / 2.0f;
        double halfHeight = hitbox.get("height").floatValue() / 2.0f;
        ScreenBox screenBox = new ScreenBox(new ScreenCoordinate(screenPoint.getX() - halfWidth, screenPoint.getY() - halfHeight), new ScreenCoordinate(screenPoint.getX() + halfWidth, screenPoint.getY() + halfHeight));
        getMapboxMap().queryRenderedFeatures(screenBox, new RenderedQueryOptions(source.getLayerIDs(), null), new QueryFeaturesCallback() {

            @Override
            public void run(@NonNull Expected<String, List<QueriedFeature>> features) {
                HashMap<String, List<Feature>> newHits = hits;
                if (features.isValue()) {
                    if (features.getValue().size() > 0) {
                        ArrayList<Feature> featuresList = new ArrayList<>();
                        for (QueriedFeature i : features.getValue()) {
                            featuresList.add(i.getFeature());
                        }
                        newHits.put(source.getID(), featuresList);
                        hitTouchableSources.add(source);
                    }
                } else {
                    Logger.e("handleTapInSources", features.getError());
                }
                handleTapInSources(sources, screenPoint, newHits, hitTouchableSources, handleTap);
            }
        });
    }
}
Also used : RCTSource(com.mapbox.rctmgl.components.styles.sources.RCTSource) HashMap(java.util.HashMap) ScreenCoordinate(com.mapbox.maps.ScreenCoordinate) ArrayList(java.util.ArrayList) QueryFeaturesCallback(com.mapbox.maps.QueryFeaturesCallback) Feature(com.mapbox.geojson.Feature) QueriedFeature(com.mapbox.maps.QueriedFeature) AbstractMapFeature(com.mapbox.rctmgl.components.AbstractMapFeature) RenderedQueryOptions(com.mapbox.maps.RenderedQueryOptions) QueriedFeature(com.mapbox.maps.QueriedFeature) ScreenBox(com.mapbox.maps.ScreenBox) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

ScreenCoordinate (com.mapbox.maps.ScreenCoordinate)3 RCTSource (com.mapbox.rctmgl.components.styles.sources.RCTSource)2 LatLng (com.mapbox.rctmgl.utils.LatLng)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 PointF (android.graphics.PointF)1 Feature (com.mapbox.geojson.Feature)1 CameraOptions (com.mapbox.maps.CameraOptions)1 CameraState (com.mapbox.maps.CameraState)1 CoordinateBounds (com.mapbox.maps.CoordinateBounds)1 QueriedFeature (com.mapbox.maps.QueriedFeature)1 QueryFeaturesCallback (com.mapbox.maps.QueryFeaturesCallback)1 RenderedQueryOptions (com.mapbox.maps.RenderedQueryOptions)1 ScreenBox (com.mapbox.maps.ScreenBox)1 AbstractMapFeature (com.mapbox.rctmgl.components.AbstractMapFeature)1 MapClickEvent (com.mapbox.rctmgl.events.MapClickEvent)1