Skip to content

Commit

Permalink
feat: support map view without navigation (#259)
Browse files Browse the repository at this point in the history
Co-authored-by: Joonas Kerttula <[email protected]>
  • Loading branch information
illuminati1911 and jokerttu authored Sep 13, 2024
1 parent b182d14 commit 15fd94b
Show file tree
Hide file tree
Showing 21 changed files with 1,179 additions and 72 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ To set up, specify your API key in the application delegate `ios/Runner/AppDeleg
## Usage
### Add a navigation view
You can now add a `NavigationView` component to your application..
The view can be controlled with the `ViewController` (Navigation and MapView) that are retrieved from the `onMapViewControllerCreated` and `onNavigationViewControllerCreated` (respectively).
The `NavigationView` compoonent should be used within a View with a bounded size. Using it
in an unbounded widget will cause the application to behave unexpectedly.
### Add a navigation view
```tsx
// Permissions must have been granted by this point.
Expand All @@ -105,6 +105,17 @@ in an unbounded widget will cause the application to behave unexpectedly.
/>
```

### Add a map view

You can also add a bare `MapView` that works as a normal map view without navigation functionality. `MapView` only need a `MapViewController` to be controlled.

```tsx
<MapView
mapViewCallbacks={mapViewCallbacks}
onMapViewControllerCreated={setMapViewController}
/>
```

See the [example](./example) directory for a complete navigation sample app.

### Requesting and handling permissions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright 2023 Google LLC
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.react.navsdk;

public class CustomTypes {
public enum FragmentType {
MAP,
NAVIGATION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ public static int getMapTypeFromJsValue(int jsValue) {
return CameraPerspective.TILTED;
}
}

public static CustomTypes.FragmentType getFragmentTypeFromJsValue(int jsValue) {
switch (jsValue) {
case 0:
default:
return CustomTypes.FragmentType.MAP;
case 1:
return CustomTypes.FragmentType.NAVIGATION;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Copyright 2023 Google LLC
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.react.navsdk;

import android.view.View;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.Polyline;
import java.io.IOException;
import java.util.Map;

public interface IMapViewFragment {
void setStylingOptions(Map stylingOptions);

void applyStylingOptions();

void setFollowingPerspective(int jsValue);

void setNightModeOption(int jsValue);

void setMapType(int jsValue);

void clearMapView();

void resetMinMaxZoomLevel();

void animateCamera(Map map);

Circle addCircle(Map optionsMap);

Marker addMarker(Map optionsMap);

Polyline addPolyline(Map optionsMap);

Polygon addPolygon(Map optionsMap);

void removeMarker(String id);

void removePolyline(String id);

void removePolygon(String id);

void removeCircle(String id);

void removeGroundOverlay(String id);

GroundOverlay addGroundOverlay(Map map);

void setMapStyle(String url);

String fetchJsonFromUrl(String urlString) throws IOException;

void moveCamera(Map map);

void setZoomLevel(int level);

void setIndoorEnabled(boolean isOn);

void setTrafficEnabled(boolean isOn);

void setCompassEnabled(boolean isOn);

void setRotateGesturesEnabled(boolean isOn);

void setScrollGesturesEnabled(boolean isOn);

void setScrollGesturesEnabledDuringRotateOrZoom(boolean isOn);

void setTiltGesturesEnabled(boolean isOn);

void setZoomControlsEnabled(boolean isOn);

void setZoomGesturesEnabled(boolean isOn);

void setBuildingsEnabled(boolean isOn);

void setMyLocationEnabled(boolean isOn);

void setMapToolbarEnabled(boolean isOn);

void setMyLocationButtonEnabled(boolean isOn);

GoogleMap getGoogleMap();

// Fragment
boolean isAdded();

View getView();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2023 Google LLC
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.react.navsdk;

public interface INavViewFragment extends IMapViewFragment {
void setNavigationUiEnabled(boolean enableNavigationUi);

void setTripProgressBarEnabled(boolean enabled);

void setSpeedometerEnabled(boolean enabled);

void setSpeedLimitIconEnabled(boolean enabled);

void setTrafficIncidentCardsEnabled(boolean enabled);

void setEtaCardEnabled(boolean enabled);

void setHeaderEnabled(boolean enabled);

void setRecenterButtonEnabled(boolean enabled);

void showRouteOverview();
}
Loading

0 comments on commit 15fd94b

Please sign in to comment.