mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-31 04:51:15 +00:00
User location event
This commit is contained in:
+22
-9
@@ -3,6 +3,8 @@ package com.mapbox.reactnativemapboxgl;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.location.Location;
|
||||
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
@@ -177,15 +179,26 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager<MapView> {
|
||||
});
|
||||
}
|
||||
|
||||
// @ReactProp(name = PROP_ONUSER_LOCATION_CHANGE, defaultBoolean = true)
|
||||
// public void onUserLocationChange(final MapView view, Boolean value) {
|
||||
// view.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
|
||||
// @Override
|
||||
// public void onUserLocationChange(int location) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@ReactProp(name = PROP_ONUSER_LOCATION_CHANGE, defaultBoolean = true)
|
||||
public void onMyLocationChange(final MapView view, Boolean value) {
|
||||
view.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
|
||||
@Override
|
||||
public void onMyLocationChange(@Nullable Location location) {
|
||||
WritableMap event = Arguments.createMap();
|
||||
WritableMap locationMap = Arguments.createMap();
|
||||
locationMap.putDouble("latitude", location.getLatitude());
|
||||
locationMap.putDouble("longitude", location.getLongitude());
|
||||
locationMap.putDouble("accuracy", location.getAccuracy());
|
||||
locationMap.putDouble("altitude", location.getAltitude());
|
||||
locationMap.putDouble("bearing", location.getBearing());
|
||||
locationMap.putDouble("speed", location.getSpeed());
|
||||
locationMap.putString("provider", location.getProvider());
|
||||
event.putMap("src", locationMap);
|
||||
ReactContext reactContext = (ReactContext) view.getContext();
|
||||
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(view.getId(), "topSelect", event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_CENTER_COORDINATE)
|
||||
public void setCenterCoordinate(MapView view, @Nullable ReadableMap center) {
|
||||
|
||||
+6
-1
@@ -32,6 +32,7 @@ var ReactMapView = requireNativeComponent('RCTMapbox', {
|
||||
zoomLevel: React.PropTypes.number,
|
||||
tilt: React.PropTypes.number,
|
||||
onRegionChange: React.PropTypes.func,
|
||||
onUserLocationChange: React.PropTypes.func,
|
||||
removeAllAnnotations: React.PropTypes.bool,
|
||||
// Fix for https://github.com/mapbox/react-native-mapbox-gl/issues/118
|
||||
scaleY: React.PropTypes.number,
|
||||
@@ -75,10 +76,14 @@ var ReactMapViewWrapper = React.createClass({
|
||||
handleOnChange(event) {
|
||||
if (this.props.onRegionChange) this.props.onRegionChange(event.nativeEvent.src);
|
||||
},
|
||||
handleUserLocation(event) {
|
||||
if (this.props.onUserLocationChange) this.props.onUserLocationChange(event.nativeEvent.src);
|
||||
},
|
||||
render() {
|
||||
return <ReactMapView
|
||||
{...this.props}
|
||||
onChange={this.handleOnChange} />
|
||||
onChange={this.handleOnChange}
|
||||
onSelect={this.handleUserLocation} />
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user