Skip to content
Merged
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
39 changes: 31 additions & 8 deletions android/src/main/java/com/rngooglemapsplus/MapCircleBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,38 @@ class MapCircleBuilder {
}

fun update(
circle: Circle,
prev: RNCircle,
next: RNCircle,
circle: Circle,
) {
circle.center = next.center.toLatLng()
circle.radius = next.radius
circle.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
circle.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
circle.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
circle.isClickable = next.pressable ?: false
circle.zIndex = next.zIndex?.toFloat() ?: 0f
if (prev.center.latitude != next.center.latitude ||
prev.center.longitude != next.center.longitude
) {
circle.center = next.center.toLatLng()
}

if (prev.radius != next.radius) {
circle.radius = next.radius
}

if (prev.strokeWidth != next.strokeWidth) {
circle.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
}

if (prev.strokeColor != next.strokeColor) {
circle.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
}

if (prev.fillColor != next.fillColor) {
circle.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
}

if (prev.pressable != next.pressable) {
circle.isClickable = next.pressable ?: false
}

if (prev.zIndex != next.zIndex) {
circle.zIndex = next.zIndex?.toFloat() ?: 0f
}
}
}
87 changes: 69 additions & 18 deletions android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,84 @@ class MapMarkerBuilder(
}

fun update(
marker: Marker,
prev: RNMarker,
next: RNMarker,
marker: Marker,
) {
marker.position =
next.coordinate.toLatLng()
if (prev.coordinate.latitude != next.coordinate.latitude ||
prev.coordinate.longitude != next.coordinate.longitude
) {
marker.position = next.coordinate.toLatLng()
}

if (!prev.markerStyleEquals(next)) {
buildIconAsync(marker.id, next) { icon ->
marker.setIcon(icon)
if (prev.infoWindowAnchor?.x != next.infoWindowAnchor?.x ||
prev.infoWindowAnchor?.y != next.infoWindowAnchor?.y
) {
marker.setInfoWindowAnchor(
(next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
(next.infoWindowAnchor?.y ?: 0f).toFloat(),
)
}

if (prev.anchor?.x != next.anchor?.x ||
prev.anchor?.y != next.anchor?.y
) {
marker.setAnchor(
(next.anchor?.x ?: 0.5f).toFloat(),
(next.anchor?.y ?: 1.0f).toFloat(),
)
}
}
} else {
if (prev.infoWindowAnchor?.x != next.infoWindowAnchor?.x ||
prev.infoWindowAnchor?.y != next.infoWindowAnchor?.y
) {
marker.setInfoWindowAnchor(
(next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
(next.infoWindowAnchor?.y ?: 0f).toFloat(),
)
}

if (prev.anchor?.x != next.anchor?.x ||
prev.anchor?.y != next.anchor?.y
) {
marker.setAnchor(
(next.anchor?.x ?: 0.5f).toFloat(),
(next.anchor?.y ?: 1.0f).toFloat(),
)
}
}

if (prev.title != next.title) {
marker.title = next.title
}

if (prev.snippet != next.snippet) {
marker.snippet = next.snippet
}

if (prev.opacity != next.opacity) {
marker.alpha = next.opacity?.toFloat() ?: 1f
}

if (prev.flat != next.flat) {
marker.isFlat = next.flat ?: false
}

if (prev.draggable != next.draggable) {
marker.isDraggable = next.draggable ?: false
}

if (prev.rotation != next.rotation) {
marker.rotation = next.rotation?.toFloat() ?: 0f
}

if (prev.zIndex != next.zIndex) {
marker.zIndex = next.zIndex?.toFloat() ?: 0f
}
marker.title = next.title
marker.snippet = next.snippet
marker.alpha = next.opacity?.toFloat() ?: 1f
marker.isFlat = next.flat ?: false
marker.isDraggable = next.draggable ?: false
marker.rotation = next.rotation?.toFloat() ?: 0f
marker.setInfoWindowAnchor(
(next.infoWindowAnchor?.x ?: 0.5).toFloat(),
(next.infoWindowAnchor?.y ?: 0).toFloat(),
)
marker.setAnchor(
(next.anchor?.x ?: 0.5).toFloat(),
(next.anchor?.y ?: 1.0).toFloat(),
)
marker.zIndex = next.zIndex?.toFloat() ?: 0f
}

fun buildIconAsync(
Expand Down
67 changes: 53 additions & 14 deletions android/src/main/java/com/rngooglemapsplus/MapPolygonBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,60 @@ class MapPolygonBuilder {
}

fun update(
poly: Polygon,
prev: RNPolygon,
next: RNPolygon,
poly: Polygon,
) {
poly.points =
next.coordinates.map {
it.toLatLng()
}
poly.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
poly.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
poly.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
poly.isClickable = next.pressable ?: false
poly.isGeodesic = next.geodesic ?: false
poly.holes = next.holes?.map { hole ->
hole.coordinates.map { it.toLatLng() }
} ?: emptyList()
poly.zIndex = next.zIndex?.toFloat() ?: 0f
val coordsChanged =
prev.coordinates.size != next.coordinates.size ||
!prev.coordinates.zip(next.coordinates).all { (a, b) ->
a.latitude == b.latitude && a.longitude == b.longitude
}

if (coordsChanged) {
poly.points = next.coordinates.map { it.toLatLng() }
}

val prevHoles = prev.holes?.toList() ?: emptyList()
val nextHoles = next.holes?.toList() ?: emptyList()
val holesChanged =
prevHoles.size != nextHoles.size ||
!prevHoles.zip(nextHoles).all { (ha, hb) ->
ha.coordinates.size == hb.coordinates.size &&
ha.coordinates.zip(hb.coordinates).all { (a, b) ->
a.latitude == b.latitude && a.longitude == b.longitude
}
}

if (holesChanged) {
poly.holes =
nextHoles.map { hole ->
hole.coordinates.map { it.toLatLng() }
}
}

if (prev.fillColor != next.fillColor) {
poly.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
}

if (prev.strokeColor != next.strokeColor) {
poly.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
}

if (prev.strokeWidth != next.strokeWidth) {
poly.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
}

if (prev.pressable != next.pressable) {
poly.isClickable = next.pressable ?: false
}

if (prev.geodesic != next.geodesic) {
poly.isGeodesic = next.geodesic ?: false
}

if (prev.zIndex != next.zIndex) {
poly.zIndex = next.zIndex?.toFloat() ?: 0f
}
}
}
55 changes: 44 additions & 11 deletions android/src/main/java/com/rngooglemapsplus/MapPolylineBuilder.kt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,52 @@ class MapPolylineBuilder {
}

fun update(
polyline: Polyline,
prev: RNPolyline,
next: RNPolyline,
polyline: Polyline,
) {
polyline.points = next.coordinates.map { it.toLatLng() }
polyline.width = next.width?.dpToPx() ?: 1f
val cap = mapLineCap(next.lineCap ?: RNLineCapType.BUTT)
polyline.startCap = cap
polyline.endCap = cap
polyline.jointType = mapLineJoin(next.lineJoin ?: RNLineJoinType.MITER)
polyline.color = next.color?.toColor() ?: Color.BLACK
polyline.isClickable = next.pressable ?: false
polyline.isGeodesic = next.geodesic ?: false
polyline.zIndex = next.zIndex?.toFloat() ?: 0f
val coordsChanged =
prev.coordinates.size != next.coordinates.size ||
!prev.coordinates.zip(next.coordinates).all { (a, b) ->
a.latitude == b.latitude && a.longitude == b.longitude
}

if (coordsChanged) {
polyline.points = next.coordinates.map { it.toLatLng() }
}

if (prev.width != next.width) {
polyline.width = next.width?.dpToPx() ?: 1f
}

val newCap = mapLineCap(next.lineCap ?: RNLineCapType.BUTT)
val prevCap = mapLineCap(prev.lineCap ?: RNLineCapType.BUTT)
if (newCap != prevCap) {
polyline.startCap = newCap
polyline.endCap = newCap
}

val newJoin = mapLineJoin(next.lineJoin ?: RNLineJoinType.MITER)
val prevJoin = mapLineJoin(prev.lineJoin ?: RNLineJoinType.MITER)
if (newJoin != prevJoin) {
polyline.jointType = newJoin
}

if (prev.color != next.color) {
polyline.color = next.color?.toColor() ?: Color.BLACK
}

if (prev.pressable != next.pressable) {
polyline.isClickable = next.pressable ?: false
}

if (prev.geodesic != next.geodesic) {
polyline.isGeodesic = next.geodesic ?: false
}

if (prev.zIndex != next.zIndex) {
polyline.zIndex = next.zIndex?.toFloat() ?: 0f
}
}

private fun mapLineCap(type: RNLineCapType?): Cap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class RNGoogleMapsPlusView(
} else if (!prev.markerEquals(next)) {
view.updateMarker(id) { marker ->
onUi {
markerBuilder.update(marker, next, prev)
markerBuilder.update(prev, next, marker)
}
}
}
Expand All @@ -181,7 +181,7 @@ class RNGoogleMapsPlusView(
} else if (!prev.polylineEquals(next)) {
view.updatePolyline(id) { polyline ->
onUi {
polylineBuilder.update(polyline, next)
polylineBuilder.update(prev, next, polyline)
}
}
}
Expand All @@ -205,7 +205,7 @@ class RNGoogleMapsPlusView(
view.addPolygon(id, polygonBuilder.build(next))
} else if (!prev.polygonEquals(next)) {
view.updatePolygon(id) { polygon ->
onUi { polygonBuilder.update(polygon, next) }
onUi { polygonBuilder.update(prev, next, polygon) }
}
}
}
Expand All @@ -229,7 +229,7 @@ class RNGoogleMapsPlusView(
} else if (!prev.circleEquals(next)) {
view.updateCircle(id) { circle ->
onUi {
circleBuilder.update(circle, next)
circleBuilder.update(prev, next, circle)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,8 @@ PODS:
- React-RCTFBReactNativeSpec
- ReactCommon/turbomodule/core
- SocketRocket
- react-native-clusterer (4.0.0):
- React-Core
- react-native-safe-area-context (5.6.1):
- boost
- DoubleConversion
Expand Down Expand Up @@ -2795,6 +2797,7 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
- react-native-clusterer (from `../node_modules/react-native-clusterer`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-oscompat (from `../node_modules/react-native/ReactCommon/oscompat`)
Expand Down Expand Up @@ -2928,6 +2931,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
React-microtasksnativemodule:
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
react-native-clusterer:
:path: "../node_modules/react-native-clusterer"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-NativeModulesApple:
Expand Down Expand Up @@ -3052,6 +3057,7 @@ SPEC CHECKSUMS:
React-logger: 30adf849117e87cf86e88dca1824bb0f18f87e10
React-Mapbuffer: 2a5edca6905cb1b3a40fb7ed3f4496df4f1bc60e
React-microtasksnativemodule: 6d775fdf71445f58dbedbd66ed9cb08b48ae2797
react-native-clusterer: a9526b8fb1d6be10cd9a6d05d7d8b982da7c6abc
react-native-safe-area-context: ee1e8e2a7abf737a8d4d9d1a5686a7f2e7466236
React-NativeModulesApple: b2ee5b48020439fd81d1fd9cba40ebf0c3af5636
React-oscompat: 80ca388c4831481cd03a6b45ecfc82739ca9a95e
Expand Down
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@react-navigation/stack": "7.4.9",
"react": "19.1.1",
"react-native": "0.82.0",
"react-native-clusterer": "4.0.0",
"react-native-gesture-handler": "2.28.0",
"react-native-google-maps-plus": "workspace:*",
"react-native-nitro-modules": "0.30.0",
Expand Down
6 changes: 6 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import IndoorLevelMapScreen from './screens/IndoorLevelMapScreen';
import CameraTestScreen from './screens/CameraTestScreen';
import type { RootStackParamList } from './types/navigation';
import SnapshotTestScreen from './screens/SnaptshotTestScreen';
import ClusteringScreen from './screens/ClsuteringScreen';

const Stack = createStackNavigator<RootStackParamList>();

Expand Down Expand Up @@ -112,6 +113,11 @@ export default function App() {
component={SnapshotTestScreen}
options={{ title: 'Snapshot test' }}
/>
<Stack.Screen
name="Clustering"
component={ClusteringScreen}
options={{ title: 'Clustering test' }}
/>
<Stack.Screen
name="Stress"
component={StressTestScreen}
Expand Down
Loading
Loading