Skip to content

Commit 754df51

Browse files
authored
feat: add mapType
2 parents 9faa702 + 300614f commit 754df51

7 files changed

Lines changed: 133 additions & 66 deletions

File tree

android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.google.android.gms.maps.OnMapReadyCallback
1414
import com.google.android.gms.maps.model.CameraPosition
1515
import com.google.android.gms.maps.model.LatLng
1616
import com.google.android.gms.maps.model.LatLngBounds
17+
import com.google.android.gms.maps.model.MapColorScheme
1718
import com.google.android.gms.maps.model.MapStyleOptions
1819
import com.google.android.gms.maps.model.Marker
1920
import com.google.android.gms.maps.model.MarkerOptions
@@ -45,6 +46,7 @@ class GoogleMapsViewImpl(
4546
private var pendingMinZoomLevel: Double? = null
4647
private var pendingMaxZoomLevel: Double? = null
4748
private var pendingMapPadding: RNMapPadding? = null
49+
private var pendingMapType: Int? = null
4850
private val pendingPolygons = mutableListOf<Pair<String, PolygonOptions>>()
4951
private val pendingPolylines = mutableListOf<Pair<String, PolylineOptions>>()
5052
private val pendingMarkers = mutableListOf<Pair<String, MarkerOptions>>()
@@ -245,6 +247,9 @@ class GoogleMapsViewImpl(
245247
googleMap?.isTrafficEnabled = it
246248
}
247249
googleMap?.setMapStyle(pendingCustomMapStyle)
250+
pendingMapType?.let {
251+
googleMap?.mapType = it
252+
}
248253
pendingUserInterfaceStyle?.let {
249254
googleMap?.mapColorScheme = it
250255
}
@@ -282,20 +287,25 @@ class GoogleMapsViewImpl(
282287
get() = googleMap?.isBuildingsEnabled ?: pendingBuildingEnabled
283288
set(value) {
284289
pendingBuildingEnabled = value
285-
value?.let {
286-
onUi {
290+
onUi {
291+
value?.let {
287292
googleMap?.isBuildingsEnabled = it
288293
}
294+
?: run {
295+
googleMap?.isBuildingsEnabled = false
296+
}
289297
}
290298
}
291299

292300
var trafficEnabled: Boolean?
293301
get() = googleMap?.isTrafficEnabled ?: pendingTrafficEnabled
294302
set(value) {
295303
pendingTrafficEnabled = value
296-
value?.let {
297-
onUi {
304+
onUi {
305+
value?.let {
298306
googleMap?.isTrafficEnabled = it
307+
} ?: run {
308+
googleMap?.isTrafficEnabled = false
299309
}
300310
}
301311
}
@@ -319,10 +329,11 @@ class GoogleMapsViewImpl(
319329
get() = pendingUserInterfaceStyle
320330
set(value) {
321331
pendingUserInterfaceStyle = value
322-
323-
value?.let {
324-
onUi {
332+
onUi {
333+
value?.let {
325334
googleMap?.mapColorScheme = it
335+
} ?: run {
336+
googleMap?.mapColorScheme = MapColorScheme.FOLLOW_SYSTEM
326337
}
327338
}
328339
}
@@ -331,9 +342,11 @@ class GoogleMapsViewImpl(
331342
get() = pendingMinZoomLevel
332343
set(value) {
333344
pendingMinZoomLevel = value
334-
value?.let {
335-
onUi {
345+
onUi {
346+
value?.let {
336347
googleMap?.setMinZoomPreference(it.toFloat())
348+
} ?: run {
349+
googleMap?.setMinZoomPreference(2.0f)
337350
}
338351
}
339352
}
@@ -342,9 +355,11 @@ class GoogleMapsViewImpl(
342355
get() = pendingMaxZoomLevel
343356
set(value) {
344357
pendingMaxZoomLevel = value
345-
value?.let {
346-
onUi {
358+
onUi {
359+
value?.let {
347360
googleMap?.setMaxZoomPreference(it.toFloat())
361+
} ?: run {
362+
googleMap?.setMaxZoomPreference(21.0f)
348363
}
349364
}
350365
}
@@ -362,6 +377,21 @@ class GoogleMapsViewImpl(
362377
it.bottom.dpToPx().toInt(),
363378
)
364379
}
380+
} ?: run {
381+
googleMap?.setPadding(0, 0, 0, 0)
382+
}
383+
}
384+
385+
var mapType: Int?
386+
get() = pendingMapType
387+
set(value) {
388+
pendingMapType = value
389+
onUi {
390+
value?.let {
391+
googleMap?.mapType = it
392+
} ?: run {
393+
googleMap?.mapType = 1
394+
}
365395
}
366396
}
367397

android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ class RNGoogleMapsPlusView(
7676
view.mapPadding = value
7777
}
7878

79+
override var mapType: RNMapType?
80+
get() = RNMapType.entries.firstOrNull { it.value == view.mapType }
81+
set(value) {
82+
value?.let {
83+
view.mapType = it.value
84+
}
85+
}
86+
7987
override var markers: Array<RNMarker>? = emptyArray()
8088
set(value) {
8189
val prevById = field?.associateBy { it.id } ?: emptyMap()

example/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ export default function App() {
368368
zoom: 15,
369369
}}
370370
userInterfaceStyle={'light'}
371+
mapType={'normal'}
371372
maxZoomLevel={20}
372373
minZoomLevel={0}
373374
mapPadding={{

ios/GoogleMapViewImpl.swift

Lines changed: 68 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
1717
private var pendingMinZoomLevel: Double?
1818
private var pendingMaxZoomLevel: Double?
1919
private var pendingMapPadding: RNMapPadding?
20+
private var pendingMapType: GMSMapViewType?
2021

2122
private var pendingPolygons: [(id: String, polygon: GMSPolygon)] = []
2223
private var pendingPolylines: [(id: String, polyline: GMSPolyline)] = []
@@ -131,6 +132,10 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
131132
mapView.mapStyle = style
132133
}
133134

135+
if let mapType = pendingMapType {
136+
mapView.mapType = mapType
137+
}
138+
134139
if let buildings = pendingBuildingEnabled {
135140
mapView.isBuildingsEnabled = buildings
136141
}
@@ -173,97 +178,105 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
173178

174179
@MainActor
175180
var buildingEnabled: Bool? {
176-
get { mapView.isBuildingsEnabled }
177-
set {
178-
pendingBuildingEnabled = newValue
179-
if let value = newValue {
180-
mapView.isBuildingsEnabled = value
181-
}
181+
get { mapView.isBuildingsEnabled }
182+
set {
183+
pendingBuildingEnabled = newValue
184+
if let value = newValue {
185+
mapView.isBuildingsEnabled = value
182186
}
187+
}
183188
}
184189

185190
@MainActor
186191
var trafficEnabled: Bool? {
187-
get { mapView.isTrafficEnabled }
188-
set {
189-
pendingTrafficEnabled = newValue
190-
if let value = newValue {
191-
mapView.isTrafficEnabled = value
192-
}
192+
get { mapView.isTrafficEnabled }
193+
set {
194+
pendingTrafficEnabled = newValue
195+
if let value = newValue {
196+
mapView.isTrafficEnabled = value
193197
}
198+
}
194199
}
195200

196201
@MainActor
197202
var customMapStyle: GMSMapStyle? {
198-
get { pendingCustomMapStyle }
199-
set {
200-
pendingCustomMapStyle = newValue
201-
if let style = newValue {
202-
mapView.mapStyle = style
203-
}
203+
get { pendingCustomMapStyle }
204+
set {
205+
pendingCustomMapStyle = newValue
206+
if let style = newValue {
207+
mapView.mapStyle = style
204208
}
209+
}
205210
}
206211

207212
@MainActor
208213
var initialCamera: GMSCameraPosition? {
209-
get { pendingInitialCamera }
210-
set {
211-
pendingInitialCamera = newValue
212-
if let camera = newValue, !mapReady {
213-
mapView.camera = camera
214-
}
214+
get { pendingInitialCamera }
215+
set {
216+
pendingInitialCamera = newValue
217+
if let camera = newValue, !mapReady {
218+
mapView.camera = camera
215219
}
220+
}
216221
}
217222

218223
@MainActor
219224
var userInterfaceStyle: UIUserInterfaceStyle? {
220-
get { pendingUserInterfaceStyle }
221-
set {
222-
pendingUserInterfaceStyle = newValue
223-
if let style = newValue {
224-
mapView.overrideUserInterfaceStyle = style
225-
}
225+
get { pendingUserInterfaceStyle }
226+
set {
227+
pendingUserInterfaceStyle = newValue
228+
if let style = newValue {
229+
mapView.overrideUserInterfaceStyle = style
226230
}
231+
}
227232
}
228233

229234
@MainActor
230235
var minZoomLevel: Double? {
231-
get { pendingMinZoomLevel }
232-
set {
233-
pendingMinZoomLevel = newValue
234-
if let min = newValue, let max = pendingMaxZoomLevel {
235-
mapView.setMinZoom(Float(min), maxZoom: Float(max))
236-
}
236+
get { pendingMinZoomLevel }
237+
set {
238+
pendingMinZoomLevel = newValue
239+
if let min = newValue, let max = pendingMaxZoomLevel {
240+
mapView.setMinZoom(Float(min), maxZoom: Float(max))
237241
}
242+
}
238243
}
239244

240245
@MainActor
241246
var maxZoomLevel: Double? {
242-
get { pendingMaxZoomLevel }
243-
set {
244-
pendingMaxZoomLevel = newValue
245-
if let max = newValue, let min = pendingMinZoomLevel {
246-
mapView.setMinZoom(Float(min), maxZoom: Float(max))
247-
}
247+
get { pendingMaxZoomLevel }
248+
set {
249+
pendingMaxZoomLevel = newValue
250+
if let max = newValue, let min = pendingMinZoomLevel {
251+
mapView.setMinZoom(Float(min), maxZoom: Float(max))
248252
}
253+
}
249254
}
250255

251256
@MainActor
252257
var mapPadding: RNMapPadding? {
253-
get { pendingMapPadding }
254-
set {
255-
pendingMapPadding = newValue
256-
if let padding = newValue {
257-
mapView.padding = UIEdgeInsets(
258-
top: padding.top,
259-
left: padding.left,
260-
bottom: padding.bottom,
261-
right: padding.right
262-
)
263-
} else {
264-
mapView.padding = .zero
265-
}
258+
get { pendingMapPadding }
259+
set {
260+
pendingMapPadding = newValue
261+
if let padding = newValue {
262+
mapView.padding = UIEdgeInsets(
263+
top: padding.top,
264+
left: padding.left,
265+
bottom: padding.bottom,
266+
right: padding.right
267+
)
268+
} else {
269+
mapView.padding = .zero
266270
}
271+
}
272+
}
273+
274+
@MainActor var mapType: Int32? {
275+
get { pendingMapType.map { Int32($0.rawValue) } }
276+
set {
277+
pendingMapType = GMSMapViewType(rawValue: UInt(newValue ?? 1))
278+
mapView.mapType = pendingMapType ?? .normal
279+
}
267280
}
268281

269282
func setCamera(camera: RNCamera, animated: Bool, durationMS: Double) {

ios/RNGoogleMapsPlusView.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
8585
set { impl.mapPadding = newValue }
8686
}
8787

88+
@MainActor
89+
var mapType: RNMapType? {
90+
get {
91+
guard let value = impl.mapType else { return nil }
92+
return RNMapType(rawValue: value)
93+
}
94+
set {
95+
impl.mapType = newValue.map { Int32($0.rawValue) }
96+
}
97+
}
98+
8899
@MainActor
89100
var markers: [RNMarker]? {
90101
didSet {

src/RNGoogleMapsPlusView.nitro.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
RNRegion,
1717
RNLocation,
1818
RNMapErrorCode,
19+
RNMapType,
1920
} from './types';
2021

2122
export interface RNGoogleMapsPlusViewProps extends HybridViewProps {
@@ -27,6 +28,7 @@ export interface RNGoogleMapsPlusViewProps extends HybridViewProps {
2728
minZoomLevel?: number;
2829
maxZoomLevel?: number;
2930
mapPadding?: RNMapPadding;
31+
mapType?: RNMapType;
3032
markers?: RNMarker[];
3133
polygons?: RNPolygon[];
3234
polylines?: RNPolyline[];

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export type RNMapPadding = {
1414
right: number;
1515
};
1616

17+
export type RNMapType = 'none' | 'normal' | 'hybrid' | 'satellite' | 'terrain';
18+
1719
export type RNUserInterfaceStyle = 'light' | 'dark' | 'default';
1820

1921
export type RNFeatureType = string;

0 commit comments

Comments
 (0)