Skip to content

Commit 6ac9946

Browse files
authored
feat/more marker props
## Pull request ### Before submitting - [x] This PR targets the `dev` branch (not `main`) - [x] Commit messages follow the semantic-release format - [x] No debug logs or sensitive data included ### Summary Add more map marker features ### Type of change - [x] Feature - [ ] Fix - [ ] Refactor - [ ] Internal / CI - [ ] Documentation --- ### Scope - [x] Android - [x] iOS - [ ] Core - [x] Example App - [ ] Docs ---
2 parents 0320a78 + 6b177a4 commit 6ac9946

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ class GoogleMapsViewImpl(
954954
}
955955

956956
override fun onMarkerClick(marker: Marker): Boolean {
957+
marker.showInfoWindow()
957958
onMarkerPress?.invoke(marker.tag?.toString() ?: "unknown")
958959
return true
959960
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ class MapMarkerBuilder(
4141
): MarkerOptions =
4242
MarkerOptions().apply {
4343
position(LatLng(m.coordinate.latitude, m.coordinate.longitude))
44-
anchor((m.anchor?.x ?: 0.5).toFloat(), (m.anchor?.y ?: 0.5).toFloat())
4544
icon(icon)
45+
m.title?.let { title(it) }
46+
m.snippet?.let { snippet(it) }
47+
m.opacity?.let { alpha(it.toFloat()) }
48+
m.flat?.let { flat(it) }
49+
m.draggable?.let { draggable(it) }
50+
anchor((m.anchor?.x ?: 0.5).toFloat(), (m.anchor?.y ?: 0.5).toFloat())
4651
m.zIndex?.let { zIndex(it.toFloat()) }
4752
}
4853

@@ -56,17 +61,22 @@ class MapMarkerBuilder(
5661
next.coordinate.latitude,
5762
next.coordinate.longitude,
5863
)
59-
marker.zIndex = next.zIndex?.toFloat() ?: 0f
6064

6165
if (!prev.markerStyleEquals(next)) {
6266
buildIconAsync(marker.id, next) { icon ->
6367
marker.setIcon(icon)
6468
}
6569
}
70+
marker.title = next.title
71+
marker.snippet = next.snippet
72+
marker.alpha = next.opacity?.toFloat() ?: 0f
73+
marker.isFlat = next.flat ?: false
74+
marker.isDraggable = next.draggable ?: false
6675
marker.setAnchor(
6776
(next.anchor?.x ?: 0.5).toFloat(),
6877
(next.anchor?.y ?: 0.5).toFloat(),
6978
)
79+
marker.zIndex = next.zIndex?.toFloat() ?: 0f
7080
}
7181

7282
fun buildIconAsync(

example/src/utils/mapGenerators.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,22 @@ export const makeHeatmap = (id: number): RNHeatmap => ({
106106
opacity: 1,
107107
});
108108

109-
export const makeMarker = (id: number): RNMarker => ({
110-
id: id.toString(),
111-
zIndex: id,
112-
coordinate: randomCoordinates(37.7749, -122.4194, 0.2),
113-
anchor: { x: 0.5, y: 1.0 },
114-
iconSvg:
115-
id % 2 === 0
109+
export function makeMarker(id: number): RNMarker {
110+
const customIcon = id % 2 === 0;
111+
return {
112+
id: id.toString(),
113+
zIndex: id,
114+
coordinate: randomCoordinates(37.7749, -122.4194, 0.2),
115+
anchor: customIcon ? { x: 0.5, y: 1.0 } : undefined,
116+
title: `Marker title ${id}`,
117+
snippet: `Marker snippet ${id}`,
118+
draggable: customIcon,
119+
iconSvg: customIcon
116120
? {
117121
width: (64 / 100) * 50,
118122
height: (88 / 100) * 50,
119123
svgString: makeSvgIcon(64, 88),
120124
}
121125
: undefined,
122-
});
126+
};
127+
}

ios/GoogleMapViewImpl.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
722722
}
723723

724724
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
725+
mapView.selectedMarker = marker
725726
let id = (marker.userData as? String) ?? "unknown"
726727
onMarkerPress?(id)
727728
return true

ios/MapMarkerBuilder.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ final class MapMarkerBuilder {
2121
marker.userData = m.id
2222
marker.tracksViewChanges = true
2323
marker.icon = icon
24+
m.title.map { marker.title = $0 }
25+
m.snippet.map { marker.snippet = $0 }
26+
m.opacity.map { marker.iconView?.alpha = CGFloat($0) }
27+
m.flat.map { marker.isFlat = $0 }
28+
m.draggable.map { marker.isDraggable = $0 }
2429
marker.groundAnchor = CGPoint(
2530
x: m.anchor?.x ?? 0.5,
2631
y: m.anchor?.y ?? 0.5
@@ -42,13 +47,16 @@ final class MapMarkerBuilder {
4247
longitude: next.coordinate.longitude
4348
)
4449

50+
m.title = next.title
51+
m.snippet = next.snippet
52+
m.iconView?.alpha = CGFloat(next.opacity ?? 0)
53+
m.isFlat = next.flat ?? false
54+
m.isDraggable = next.draggable ?? false
4555
m.zIndex = Int32(next.zIndex ?? 0)
46-
4756
m.groundAnchor = CGPoint(
4857
x: next.anchor?.x ?? 0.5,
4958
y: next.anchor?.y ?? 0.5
5059
)
51-
5260
if !prev.markerStyleEquals(next) {
5361
buildIconAsync(next.id, next) { img in
5462
m.tracksViewChanges = true

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ export type RNMarker = {
136136
zIndex?: number;
137137
coordinate: RNLatLng;
138138
anchor?: RNPosition;
139+
showInfoWindow?: boolean;
140+
title?: string;
141+
snippet?: string;
142+
opacity?: number;
143+
flat?: boolean;
144+
draggable?: boolean;
139145
iconSvg?: RNMarkerSvg;
140146
};
141147

0 commit comments

Comments
 (0)