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);
}
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);
}
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;
}
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);
}
Aggregations