mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-30 20:41:08 +00:00
Merge pull request #300 from maqen/master
Added method for getting current bounds [android]
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
| `getDirection` | `mapViewRef`, `callback` | Gets the current direction. Returns a single callback object. |
|
||||
| `onOpenAnnotation` | `{title: null, subtitle: null, latitude: 0, longitude: 0}` | Fired when focusing a an annotation. If the annotation is opened already, the event will not fire.
|
||||
| `onLongPress` | `{latitude: 0, longitude: 0}` | Fired when the user taps and holds the map.
|
||||
| `getBounds` | `mapViewRef`, `callback` | Returns current bounds for view (NE & SW).
|
||||
|
||||
## Methods for Modifying the Map State
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ var MapMixins = {
|
||||
getDirection(mapRef, callback) {;
|
||||
NativeModules.MapboxGLManager.getDirection(React.findNodeHandle(this.refs[mapRef]), callback);
|
||||
},
|
||||
getBounds(mapRef, callback) {
|
||||
NativeModules.MapboxGLManager.getBounds(React.findNodeHandle(this.refs[mapRef]), callback);
|
||||
},
|
||||
mapStyles: NativeModules.MapboxGLManager.mapStyles,
|
||||
userTrackingMode: NativeModules.MapboxGLManager.userTrackingMode
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user