Search in sources :

Example 1 with VisibleRegion

use of com.mapbox.mapboxsdk.geometry.VisibleRegion in project maps by rnmapbox.

the class GeoViewport method getRegion.

public static VisibleRegion getRegion(LatLng centerCoord, int zoomLevel, int viewportWidth, int viewportHeight) {
    PointF px = sphericalMercator.getPX(centerCoord, zoomLevel);
    LatLng tl = sphericalMercator.getLatLng(new PointF(px.x - (viewportWidth / 2), px.y - (viewportHeight / 2)), zoomLevel);
    LatLng br = sphericalMercator.getLatLng(new PointF(px.x + (viewportWidth / 2), px.y + (viewportHeight / 2)), zoomLevel);
    LatLng farLeft = tl;
    LatLng farRight = new LatLng(tl.getLatitude(), br.getLongitude());
    LatLng nearLeft = new LatLng(br.getLatitude(), tl.getLongitude());
    LatLng nearRight = br;
    return new VisibleRegion(farLeft, farRight, nearLeft, nearRight, null);
}
Also used : VisibleRegion(com.mapbox.mapboxsdk.geometry.VisibleRegion) PointF(android.graphics.PointF) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 2 with VisibleRegion

use of com.mapbox.mapboxsdk.geometry.VisibleRegion in project maps by rnmapbox.

the class RCTMGLMapView method makeRegionPayload.

private WritableMap makeRegionPayload(Boolean isAnimated) {
    CameraPosition position = mMap.getCameraPosition();
    if (position == null || position.target == null) {
        return new WritableNativeMap();
    }
    LatLng latLng = new LatLng(position.target.getLatitude(), position.target.getLongitude());
    WritableMap properties = new WritableNativeMap();
    properties.putDouble("zoomLevel", position.zoom);
    properties.putDouble("heading", position.bearing);
    properties.putDouble("pitch", position.tilt);
    properties.putBoolean("animated", (null == isAnimated) ? mCameraChangeTracker.isAnimated() : isAnimated.booleanValue());
    properties.putBoolean("isUserInteraction", mCameraChangeTracker.isUserInteraction());
    try {
        VisibleRegion visibleRegion = mMap.getProjection().getVisibleRegion();
        properties.putArray("visibleBounds", GeoJSONUtils.fromLatLngBounds(visibleRegion.latLngBounds));
    } catch (Exception ex) {
        Logger.e(LOG_TAG, String.format("An error occurred while attempting to make the region: %s", ex.getMessage()));
    }
    return GeoJSONUtils.toPointFeature(latLng, properties);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) WritableMap(com.facebook.react.bridge.WritableMap) VisibleRegion(com.mapbox.mapboxsdk.geometry.VisibleRegion) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 3 with VisibleRegion

use of com.mapbox.mapboxsdk.geometry.VisibleRegion in project maps by rnmapbox.

the class RCTMGLMapView method getVisibleRegion.

public VisibleRegion getVisibleRegion(LatLng center, double zoomLevel) {
    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    int[] contentPadding = mMap.getPadding();
    int mapWidth = (int) ((mMap.getWidth() * 0.75 - (contentPadding[0] + contentPadding[2])) / metrics.scaledDensity);
    int mapHeight = (int) ((mMap.getHeight() * 0.75 - (contentPadding[1] + contentPadding[3])) / metrics.scaledDensity);
    VisibleRegion region = GeoViewport.getRegion(center, (int) zoomLevel, mapWidth, mapHeight);
    return region;
}
Also used : VisibleRegion(com.mapbox.mapboxsdk.geometry.VisibleRegion) DisplayMetrics(android.util.DisplayMetrics)

Example 4 with VisibleRegion

use of com.mapbox.mapboxsdk.geometry.VisibleRegion in project maps by rnmapbox.

the class RCTMGLMapView method getVisibleBounds.

public void getVisibleBounds(String callbackID) {
    VisibleRegion region = mMap.getProjection().getVisibleRegion();
    WritableMap payload = new WritableNativeMap();
    payload.putArray("visibleBounds", GeoJSONUtils.fromLatLngBounds(region.latLngBounds));
    AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
    mManager.handleEvent(event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) VisibleRegion(com.mapbox.mapboxsdk.geometry.VisibleRegion) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) AndroidCallbackEvent(com.mapbox.rctmgl.events.AndroidCallbackEvent)

Aggregations

VisibleRegion (com.mapbox.mapboxsdk.geometry.VisibleRegion)4 WritableMap (com.facebook.react.bridge.WritableMap)2 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)2 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 PointF (android.graphics.PointF)1 DisplayMetrics (android.util.DisplayMetrics)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 AndroidCallbackEvent (com.mapbox.rctmgl.events.AndroidCallbackEvent)1