Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ This project follows
follow [GitHub's directions](https://help.github.com/articles/generating-ssh-keys/)
to generate an SSH key.
- `git clone git@github.com:<your_name_here>/googlemaps/react-native-navigation-sdk.git`
- `git remote add upstream git@github.com:googlemaps/react-native-sdk.git` (So that you
- `git remote add upstream git@github.com:googlemaps/react-native-navigation-sdk.git` (So that you
fetch from the master repository, not your clone, when running `git fetch`
et al.)

#### Create branch

1. `git fetch upstream`
2. `git checkout upstream/master -b <name_of_your_branch>`
2. `git checkout upstream/main -b <name_of_your_branch>`
3. Start coding!

#### Commit changes
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ Both `NavigationView` and `MapView` support the following props. Props marked wi
| ----------------------------------- | ------------------------------------------------ | :---: | ------------------------------------------------ |
| `onMapReady` | `() => void` | | Called when the map is ready to use |
| `onMapClick` | `(latLng: LatLng) => void` | | Called when the map is clicked |
| `onMapDrag` | `(result: DragResult) => void` | | Called when the map is dragged |
| `onMapDragEnd` | `(result: DragResult) => void` | | Called when the map dragging stops |
| `onMarkerClick` | `(marker: Marker) => void` | | Called when a marker is clicked |
| `onPolylineClick` | `(polyline: Polyline) => void` | | Called when a polyline is clicked |
| `onPolygonClick` | `(polygon: Polygon) => void` | | Called when a polygon is clicked |
Expand All @@ -564,6 +566,10 @@ The `MapViewController` is provided via the `onMapViewControllerCreated` callbac
| `addPolyline(options: PolylineOptions)` | `Promise<Polyline>` | Add or update a polyline. If `options.id` matches an existing polyline, it is updated |
| `addPolygon(options: PolygonOptions)` | `Promise<Polygon>` | Add or update a polygon. If `options.id` matches an existing polygon, it is updated |
| `addCircle(options: CircleOptions)` | `Promise<Circle>` | Add or update a circle. If `options.id` matches an existing circle, it is updated |
| `coordinateForPoint(point: Point)` | `Promise<LatLng>` | Maps a point coordinate in the map’s view to an Earth coordinate |
| `pointForCoordinate(coordinate: LatLng)` | `Promise<Point>` | Maps an Earth coordinate to a point coordinate in the map’s view |
| `fitBounds(boundsOptions: BoundsOptions)` | `Promise<void>` | Transforms the camera such that the specified bounds are centered on screen |
| `getBounds()` | `Promise<Bounds>` | Retrieves the rectangular bounds of the map view |
| `addGroundOverlay(options: GroundOverlayOptions)` | `Promise<GroundOverlay>` | Add or update a ground overlay. If `options.id` matches an existing overlay, it is updated |
| `removeMarker(id: string)` | `void` | Remove a marker by its ID |
| `removePolyline(id: string)` | `void` | Remove a polyline by its ID |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@
public class Constants {
public static final String LAT_FIELD_KEY = "lat";
public static final String LNG_FIELD_KEY = "lng";

public static final String URI_KEY = "uri";

public static final String X_KEY = "x";
public static final String Y_KEY = "y";

public static final String CAMERA_POSITION_KEY = "cameraPosition";
public static final String TARGET_KEY = "target";
public static final String BEARING_KEY = "bearing";
public static final String TILT_KEY = "tilt";
public static final String ZOOM_KEY = "zoom";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package com.google.android.react.navsdk;

import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.LatLng;
Expand All @@ -36,4 +37,8 @@ public interface INavigationViewCallback {
void onMarkerInfoWindowTapped(Marker marker);

void onMapClick(LatLng latLng);

void onMapDrag(CameraPosition cameraPosition);

void onMapDragEnd(CameraPosition cameraPosition);
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void setupMapListeners(INavigationViewCallback navigationViewCallback) {
mGoogleMap.setOnInfoWindowClickListener(
marker -> mNavigationViewCallback.onMarkerInfoWindowTapped(marker));
mGoogleMap.setOnMapClickListener(latLng -> mNavigationViewCallback.onMapClick(latLng));
mGoogleMap.setOnCameraMoveListener(
() -> mNavigationViewCallback.onMapDrag(mGoogleMap.getCameraPosition()));
mGoogleMap.setOnCameraIdleListener(
() -> mNavigationViewCallback.onMapDragEnd(mGoogleMap.getCameraPosition()));
}

public GoogleMap getGoogleMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.LatLng;
Expand Down Expand Up @@ -137,6 +138,24 @@ public void onMapClick(LatLng latLng) {
emitEvent("onMapClick", ObjectTranslationUtil.getMapFromLatLng(latLng));
}

@Override
public void onMapDrag(CameraPosition cameraPosition) {
WritableMap map = Arguments.createMap();
map.putMap(
Constants.CAMERA_POSITION_KEY,
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
emitEvent("onMapDrag", map);
}

@Override
public void onMapDragEnd(CameraPosition cameraPosition) {
WritableMap map = Arguments.createMap();
map.putMap(
Constants.CAMERA_POSITION_KEY,
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
emitEvent("onMapDragEnd", map);
}

public MapViewController getMapController() {
return mMapViewController;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,52 @@ public void addCircle(ReadableMap options, final Promise promise) {
});
}

@Override
public void coordinateForPoint(String nativeID, ReadableMap point, Promise promise) {
UiThreadUtil.runOnUiThread(
() -> {
if (mMapViewController == null) {
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
return;
}

NavViewModule.resolveCoordinateForPoint(
getReactApplicationContext(), mMapViewController.getGoogleMap(), point, promise);
});
}

@Override
public void pointForCoordinate(String nativeID, ReadableMap coordinate, Promise promise) {
if (mMapViewController == null) {
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
return;
}

NavViewModule.resolvePointForCoordinate(
getReactApplicationContext(), mMapViewController.getGoogleMap(), coordinate, promise);
}

@Override
public void fitBounds(String nativeID, ReadableMap boundsOptions, Promise promise) {
if (mMapViewController == null) {
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
return;
}

NavViewModule.resolveFitBounds(
getReactApplicationContext(), mMapViewController.getGoogleMap(), boundsOptions, promise);
}

@Override
public void getBounds(String nativeID, Promise promise) {
if (mMapViewController == null) {
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
return;
}

NavViewModule.resolveGetBounds(mMapViewController.getGoogleMap(), promise);
}

@Override
public void addMarker(ReadableMap options, final Promise promise) {
ReadableMap markerOptionsMap = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.facebook.react.uimanager.events.EventDispatcher;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.LatLng;
Expand Down Expand Up @@ -242,6 +243,24 @@ public void onMapClick(LatLng latLng) {
emitEvent("onMapClick", ObjectTranslationUtil.getMapFromLatLng(latLng));
}

@Override
public void onMapDrag(CameraPosition cameraPosition) {
WritableMap map = Arguments.createMap();
map.putMap(
Constants.CAMERA_POSITION_KEY,
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
emitEvent("onMapDrag", map);
}

@Override
public void onMapDragEnd(CameraPosition cameraPosition) {
WritableMap map = Arguments.createMap();
map.putMap(
Constants.CAMERA_POSITION_KEY,
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
emitEvent("onMapDragEnd", map);
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
MapBuilder.of("registrationName", "onPromptVisibilityChanged"))
.put("onMapReady", MapBuilder.of("registrationName", "onMapReady"))
.put("onMapClick", MapBuilder.of("registrationName", "onMapClick"))
.put("onMapDrag", MapBuilder.of("registrationName", "onMapDrag"))
.put("onMapDragEnd", MapBuilder.of("registrationName", "onMapDragEnd"))
.put("onMarkerClick", MapBuilder.of("registrationName", "onMarkerClick"))
.put("onPolylineClick", MapBuilder.of("registrationName", "onPolylineClick"))
.put("onPolygonClick", MapBuilder.of("registrationName", "onPolygonClick"))
Expand Down
Loading