mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-31 04:51:15 +00:00
Added method for getting current bounds
Using recommended apporach until more native call is available.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user