Mapbox-gl-native: Get bounding box on Android

Created on 27 Jan 2016  路  8Comments  路  Source: mapbox/mapbox-gl-native

Is there no way to get the current bounding box on Android? On iOS it seems to be a bounds variable that I can use, but I cannot find anything similar on Android.

Android

Most helpful comment

@sddamico, since 4.0.0 we changed the naming of CoordinateBounds to LatLngBounds. If you are interested in getting the bounds of current viewport. Take a look at Mapbox.getProjection(). Reach out if you have any other questions!

All 8 comments

Until they add it, I guess you could try this:

//create bounds
LatLng southWest = mapView.fromScreenLocation(new PointF(0f, mapView.getHeight()));
LatLng northEast = mapView.fromScreenLocation(new PointF(mapView.getWidth(), 0f));
CoordinateBounds bounds = new CoordinateBounds(southWest, northEast);

//set the bounds
mapView.setVisibleCoordinateBounds(bounds, true);

@esisa
Thank you for reaching out, sadly we don't expose this as an API just yet.
I will definitely takes this in mind when landing #3145 and #3602.
The suggestion of @alphez is currently the correct way of calculating the bounds for now.
Will close this down in favour of the feature request in above issues.

Thanks @alphez

@tobrun did this work around get lost in 4.0?

@sddamico, since 4.0.0 we changed the naming of CoordinateBounds to LatLngBounds. If you are interested in getting the bounds of current viewport. Take a look at Mapbox.getProjection(). Reach out if you have any other questions!

@tobrun yeah, I was specifically referring to setVisibleCoordinateBounds which still seems like there's a jni method but no corresponding java one...

I'm attempting to accomplish something similar to the effect of the api's that might be offered in #3602. The web engineer I am working with was able to achieve the effect of bounding the map by using the options.maxBounds in js.

@sddamico
We expose the following camera update method:

    /**
     * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
     * bounds are centered on screen at the greatest possible zoom level.
     * You can specify padding, in order to inset the bounding box from the map view's edges.
     * The returned CameraUpdate has a bearing of 0 and a tilt of 0.
     *
     * @param bounds  Bounds to match Camera position with
     * @param padding Padding added to the bounds
     * @return CameraUpdate Final Camera Position
     */
    public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int padding) {
        return newLatLngBounds(bounds, padding, padding, padding, padding);
    }

    /**

Note that we don't restrict the user from navigating outside of the set bounds.
This feature is being tracked in #3602.

@tobrun yeah, I definitely need to limit the user from navigating outside the bounds. I'll start investigating some other workarounds.

Was this page helpful?
0 / 5 - 0 ratings