<lambda>null1 package expo.modules.maps
2 
3 import com.facebook.react.bridge.ReactApplicationContext
4 import com.facebook.react.uimanager.UIManagerModule
5 import expo.modules.kotlin.Promise
6 import expo.modules.kotlin.modules.Module
7 import expo.modules.kotlin.modules.ModuleDefinition
8 import expo.modules.maps.googleMaps.GoogleMapsView
9 import expo.modules.maps.records.CameraMoveRecord
10 
11 class ExpoGoogleMapsModule : Module() {
12 
13   override fun definition() = ModuleDefinition {
14     Name("ExpoGoogleMaps")
15 
16     AsyncFunction("getSearchCompletions") { viewHandle: Int, searchQueryFragment: String, promise: Promise ->
17       val rnContext = appContext.reactContext as? ReactApplicationContext ?: return@AsyncFunction
18       val uiManager = rnContext.getNativeModule(UIManagerModule::class.java) ?: return@AsyncFunction
19       appContext.activityProvider?.currentActivity?.runOnUiThread {
20         val view = uiManager.resolveView(viewHandle) as GoogleMapsView
21         view.fetchPlacesSearchCompletions(searchQueryFragment, promise)
22       }
23     }
24     AsyncFunction("moveCamera") { viewHandle: Int, cameraPosition: CameraMoveRecord, promise: Promise ->
25       val rnContext = appContext.reactContext as? ReactApplicationContext ?: return@AsyncFunction
26       val uiManager = rnContext.getNativeModule(UIManagerModule::class.java) ?: return@AsyncFunction
27       appContext.activityProvider?.currentActivity?.runOnUiThread {
28         val view = uiManager.resolveView(viewHandle) as GoogleMapsView
29         view.moveCamera(cameraPosition, promise)
30       }
31     }
32 
33     View(GoogleMapsView::class) {
34       Events(
35         "onMapPress",
36         "onLongPress",
37         "onMapLoaded",
38         "onRegionChange",
39         "onRegionChangeComplete",
40         "onRegionChangeStarted",
41         "onPoiClick",
42         "onMarkerPress",
43         "onMarkerDrag",
44         "onMarkerDragStarted",
45         "onMarkerDragComplete",
46         "onClusterPress",
47         "onLocationButtonPress",
48         "onLocationDotPress",
49         "onLocationChange"
50       )
51 
52       OnViewDestroys<GoogleMapsView> {
53         it.onViewDestroyed()
54       }
55 
56       Prop("enableRotateGestures") { view: GoogleMapsView, enable: Boolean ->
57         view.setEnabledRotateGestures(enable)
58       }
59 
60       Prop("enableScrollGestures") { view: GoogleMapsView, enable: Boolean ->
61         view.setEnabledScrollGestures(enable)
62       }
63 
64       Prop("enableTiltRotateGestures") { view: GoogleMapsView, enable: Boolean ->
65         view.setEnabledTiltGestures(enable)
66       }
67 
68       Prop("enableZoomGestures") { view: GoogleMapsView, enable: Boolean ->
69         view.setEnabledZoomGestures(enable)
70       }
71 
72       Prop("mapType") { view: GoogleMapsView, mapType: MapType ->
73         view.setMapType(mapType)
74       }
75 
76       Prop("showZoomControls") { view: GoogleMapsView, enable: Boolean ->
77         view.setShowZoomControl(enable)
78       }
79 
80       Prop("showCompass") { view: GoogleMapsView, enable: Boolean ->
81         view.setShowCompass(enable)
82       }
83 
84       Prop("showMapToolbar") { view: GoogleMapsView, enable: Boolean ->
85         view.setShowMapToolbar(enable)
86       }
87 
88       Prop("showMyLocationButton") { view: GoogleMapsView, enable: Boolean ->
89         view.setShowMyLocationButton(enable)
90       }
91 
92       Prop("showLevelPicker") { view: GoogleMapsView, enable: Boolean ->
93         view.setShowLevelPicker(enable)
94       }
95 
96       Prop("googleMapsJsonStyleString") { view: GoogleMapsView, jsonStyleString: String ->
97         view.setMapStyle(jsonStyleString)
98       }
99 
100       Prop("markers") { view: GoogleMapsView, markerObjects: Array<MarkerObject> ->
101         view.setMarkers(markerObjects)
102       }
103 
104       Prop("polygons") { view: GoogleMapsView, polygonObjects: Array<PolygonObject> ->
105         view.setPolygons(polygonObjects)
106       }
107 
108       Prop("polylines") { view: GoogleMapsView, polylineObjects: Array<PolylineObject> ->
109         view.setPolylines(polylineObjects)
110       }
111 
112       Prop("initialCameraPosition") { view: GoogleMapsView, initialCameraPosition: CameraMoveRecord ->
113         view.setInitialCameraPosition(initialCameraPosition)
114       }
115 
116       Prop("circles") { view: GoogleMapsView, circleObjects: Array<CircleObject> ->
117         view.setCircles(circleObjects)
118       }
119 
120       Prop("clusters") { view: GoogleMapsView, clusterObjects: Array<ClusterObject> ->
121         view.setClusters(clusterObjects)
122       }
123 
124       Prop("enableTraffic") { view: GoogleMapsView, enable: Boolean ->
125         view.setEnabledTraffic(enable)
126       }
127 
128       Prop("kmls") { view: GoogleMapsView, kmlObjects: Array<KMLObject> ->
129         view.setKMLs(kmlObjects)
130       }
131 
132       Prop("geojsons") { view: GoogleMapsView, geoJsonObjects: Array<GeoJsonObject> ->
133         view.setGeoJsons(geoJsonObjects)
134       }
135 
136       Prop("overlays") { view: GoogleMapsView, overlayObjects: Array<OverlayObject> ->
137         view.setOverlays(overlayObjects)
138       }
139 
140       Prop("heatmaps") { view: GoogleMapsView, heatmapObjects: Array<HeatmapObject> ->
141         view.setHeatmaps(heatmapObjects)
142       }
143 
144       Prop("createPOISearchRequest") { view: GoogleMapsView, place: String ->
145         view.createPlaceSearchRequest(place)
146       }
147 
148       Prop("clickablePOIs") { view: GoogleMapsView, arePOIClickable: Boolean ->
149         view.setClickablePOIs(arePOIClickable)
150       }
151 
152       Prop("onLocationChangeEventPriority") { view: GoogleMapsView, priority: Int ->
153         view.setLocationCallbackPriority(priority)
154       }
155 
156       Prop("onLocationChangeEventInterval") { view: GoogleMapsView, interval: Double ->
157         view.setLocationCallbackInterval(interval.toLong())
158       }
159     }
160   }
161 }
162