mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-31 13:01:15 +00:00
Merge pull request #300 from maqen/master
Added method for getting current bounds [android]
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;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,12 @@ public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
||||
successCallback.invoke(location);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getBounds(int mapRef, Callback successCallback) {
|
||||
WritableMap bounds = aPackage.getManager().getBounds(aPackage.getManager().getMapView());
|
||||
successCallback.invoke(bounds);
|
||||
}
|
||||
|
||||
public void setPackage(ReactNativeMapboxGLPackage aPackage) {
|
||||
this.aPackage = aPackage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user