Added method for getting current bounds

Using recommended apporach until more native call is available.
This commit is contained in:
Max Schedin
2016-03-07 12:14:16 +01:00
parent 6e84c9e987
commit fd06c0b4ac
4 changed files with 26 additions and 0 deletions
@@ -36,6 +36,7 @@ import java.net.URL;
import java.net.HttpURLConnection;
import android.graphics.drawable.BitmapDrawable;
import javax.annotation.Nullable;
import android.graphics.PointF;
public class ReactNativeMapboxGLManager extends SimpleViewManager<MapView> {
@@ -397,6 +398,21 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager<MapView> {
return callbackDict;
}
public WritableMap getBounds(MapView view) {
WritableMap callbackDict = Arguments.createMap();
int viewportWidth = view.getWidth();
int viewportHeight = view.getHeight();
if (viewportWidth > 0 && viewportHeight > 0) {
LatLng ne = view.fromScreenLocation(new PointF(viewportWidth, 0));
LatLng sw = view.fromScreenLocation(new PointF(0, viewportHeight));
callbackDict.putDouble("latNE", ne.getLatitude());
callbackDict.putDouble("lngNE", ne.getLongitude());
callbackDict.putDouble("latSW", sw.getLatitude());
callbackDict.putDouble("lngSW", sw.getLongitude());
}
return callbackDict;
}
public MapView getMapView() {
return mapView;
}