Skip to content

Commit e32a3f5

Browse files
committed
feat: add mapType
1 parent 9faa702 commit e32a3f5

7 files changed

Lines changed: 120 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: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -173,97 +173,97 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
173173

174174
@MainActor
175175
var buildingEnabled: Bool? {
176-
get { mapView.isBuildingsEnabled }
177-
set {
178-
pendingBuildingEnabled = newValue
179-
if let value = newValue {
180-
mapView.isBuildingsEnabled = value
181-
}
176+
get { mapView.isBuildingsEnabled }
177+
set {
178+
pendingBuildingEnabled = newValue
179+
if let value = newValue {
180+
mapView.isBuildingsEnabled = value
182181
}
182+
}
183183
}
184184

185185
@MainActor
186186
var trafficEnabled: Bool? {
187-
get { mapView.isTrafficEnabled }
188-
set {
189-
pendingTrafficEnabled = newValue
190-
if let value = newValue {
191-
mapView.isTrafficEnabled = value
192-
}
187+
get { mapView.isTrafficEnabled }
188+
set {
189+
pendingTrafficEnabled = newValue
190+
if let value = newValue {
191+
mapView.isTrafficEnabled = value
193192
}
193+
}
194194
}
195195

196196
@MainActor
197197
var customMapStyle: GMSMapStyle? {
198-
get { pendingCustomMapStyle }
199-
set {
200-
pendingCustomMapStyle = newValue
201-
if let style = newValue {
202-
mapView.mapStyle = style
203-
}
198+
get { pendingCustomMapStyle }
199+
set {
200+
pendingCustomMapStyle = newValue
201+
if let style = newValue {
202+
mapView.mapStyle = style
204203
}
204+
}
205205
}
206206

207207
@MainActor
208208
var initialCamera: GMSCameraPosition? {
209-
get { pendingInitialCamera }
210-
set {
211-
pendingInitialCamera = newValue
212-
if let camera = newValue, !mapReady {
213-
mapView.camera = camera
214-
}
209+
get { pendingInitialCamera }
210+
set {
211+
pendingInitialCamera = newValue
212+
if let camera = newValue, !mapReady {
213+
mapView.camera = camera
215214
}
215+
}
216216
}
217217

218218
@MainActor
219219
var userInterfaceStyle: UIUserInterfaceStyle? {
220-
get { pendingUserInterfaceStyle }
221-
set {
222-
pendingUserInterfaceStyle = newValue
223-
if let style = newValue {
224-
mapView.overrideUserInterfaceStyle = style
225-
}
220+
get { pendingUserInterfaceStyle }
221+
set {
222+
pendingUserInterfaceStyle = newValue
223+
if let style = newValue {
224+
mapView.overrideUserInterfaceStyle = style
226225
}
226+
}
227227
}
228228

229229
@MainActor
230230
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-
}
231+
get { pendingMinZoomLevel }
232+
set {
233+
pendingMinZoomLevel = newValue
234+
if let min = newValue, let max = pendingMaxZoomLevel {
235+
mapView.setMinZoom(Float(min), maxZoom: Float(max))
237236
}
237+
}
238238
}
239239

240240
@MainActor
241241
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-
}
242+
get { pendingMaxZoomLevel }
243+
set {
244+
pendingMaxZoomLevel = newValue
245+
if let max = newValue, let min = pendingMinZoomLevel {
246+
mapView.setMinZoom(Float(min), maxZoom: Float(max))
248247
}
248+
}
249249
}
250250

251251
@MainActor
252252
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-
}
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
266265
}
266+
}
267267
}
268268

269269
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)