react-native-maps 1.21.0-alpha.13 → 1.21.0-alpha.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/android/build.gradle +73 -53
  2. package/android/gradlew +1 -2
  3. package/android/src/main/RCTAppDependencyProvider.h +25 -0
  4. package/android/src/main/RCTAppDependencyProvider.mm +55 -0
  5. package/android/src/main/RCTModulesConformingToProtocolsProvider.h +18 -0
  6. package/android/src/main/RCTModulesConformingToProtocolsProvider.mm +33 -0
  7. package/android/src/main/RCTThirdPartyComponentsProvider.h +16 -0
  8. package/android/src/main/RCTThirdPartyComponentsProvider.mm +28 -0
  9. package/android/src/main/ReactAppDependencyProvider.podspec +34 -0
  10. package/android/src/main/java/com/facebook/fbreact/specs/NativeAirMapsModuleSpec.java +63 -0
  11. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerDelegate.java +35 -0
  12. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerInterface.java +17 -0
  13. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCircleManagerDelegate.java +49 -0
  14. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCircleManagerInterface.java +23 -0
  15. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerDelegate.java +49 -0
  16. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerInterface.java +23 -0
  17. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerDelegate.java +206 -0
  18. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerInterface.java +73 -0
  19. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerDelegate.java +104 -0
  20. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerInterface.java +39 -0
  21. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerDelegate.java +46 -0
  22. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerInterface.java +23 -0
  23. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerDelegate.java +58 -0
  24. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerInterface.java +26 -0
  25. package/android/src/main/java/com/rnmaps/fabric/CalloutManager.java +77 -0
  26. package/android/src/main/java/com/rnmaps/fabric/CircleManager.java +94 -0
  27. package/android/src/main/java/com/rnmaps/fabric/JSONUtil.java +86 -0
  28. package/android/src/main/java/com/rnmaps/fabric/MapViewManager.java +619 -0
  29. package/android/src/main/java/com/rnmaps/fabric/MarkerManager.java +258 -0
  30. package/android/src/main/java/com/rnmaps/fabric/NativeAirMapsModule.java +235 -2
  31. package/android/src/main/java/com/rnmaps/fabric/OverlayManager.java +95 -0
  32. package/android/src/main/java/com/rnmaps/fabric/PolygonManager.java +89 -0
  33. package/android/src/main/java/com/rnmaps/fabric/PolylineManager.java +121 -0
  34. package/android/src/main/java/com/rnmaps/fabric/event/OnCalloutPressEvent.java +25 -0
  35. package/android/src/main/java/com/rnmaps/fabric/event/OnDeselectEvent.java +28 -0
  36. package/android/src/main/java/com/rnmaps/fabric/event/OnDoublePressEvent.java +27 -0
  37. package/android/src/main/java/com/rnmaps/fabric/event/OnDragEndEvent.java +28 -0
  38. package/android/src/main/java/com/rnmaps/fabric/event/OnDragEvent.java +28 -0
  39. package/android/src/main/java/com/rnmaps/fabric/event/OnDragStartEvent.java +28 -0
  40. package/android/src/main/java/com/rnmaps/fabric/event/OnIndoorBuildingFocusedEvent.java +28 -0
  41. package/android/src/main/java/com/rnmaps/fabric/event/OnIndoorLevelActivatedEvent.java +28 -0
  42. package/android/src/main/java/com/rnmaps/fabric/event/OnKmlReadyEvent.java +28 -0
  43. package/android/src/main/java/com/rnmaps/fabric/event/OnLongPressEvent.java +28 -0
  44. package/android/src/main/java/com/rnmaps/fabric/event/OnMapLoadedEvent.java +29 -0
  45. package/android/src/main/java/com/rnmaps/fabric/event/OnMapReadyEvent.java +29 -0
  46. package/android/src/main/java/com/rnmaps/fabric/event/OnMarkerDeselectEvent.java +28 -0
  47. package/android/src/main/java/com/rnmaps/fabric/event/OnMarkerDragEndEvent.java +28 -0
  48. package/android/src/main/java/com/rnmaps/fabric/event/OnMarkerDragEvent.java +28 -0
  49. package/android/src/main/java/com/rnmaps/fabric/event/OnMarkerDragStartEvent.java +28 -0
  50. package/android/src/main/java/com/rnmaps/fabric/event/OnMarkerPressEvent.java +28 -0
  51. package/android/src/main/java/com/rnmaps/fabric/event/OnMarkerSelectEvent.java +28 -0
  52. package/android/src/main/java/com/rnmaps/fabric/event/OnPanDragEvent.java +28 -0
  53. package/android/src/main/java/com/rnmaps/fabric/event/OnPoiClickEvent.java +27 -0
  54. package/android/src/main/java/com/rnmaps/fabric/event/OnPressEvent.java +27 -0
  55. package/android/src/main/java/com/rnmaps/fabric/event/OnRegionChangeCompleteEvent.java +30 -0
  56. package/android/src/main/java/com/rnmaps/fabric/event/OnRegionChangeEvent.java +48 -0
  57. package/android/src/main/java/com/rnmaps/fabric/event/OnRegionChangeStartEvent.java +33 -0
  58. package/android/src/main/java/com/rnmaps/fabric/event/OnSelectEvent.java +28 -0
  59. package/android/src/main/java/com/rnmaps/fabric/event/OnUserLocationChangeEvent.java +28 -0
  60. package/android/src/main/java/com/rnmaps/maps/MapAirModulePackage.java +40 -4
  61. package/android/src/main/java/com/rnmaps/maps/MapCallout.java +18 -0
  62. package/android/src/main/java/com/rnmaps/maps/MapCircle.java +24 -0
  63. package/android/src/main/java/com/rnmaps/maps/MapManager.java +14 -14
  64. package/android/src/main/java/com/rnmaps/maps/MapMarker.java +637 -556
  65. package/android/src/main/java/com/rnmaps/maps/MapMarkerManager.java +3 -3
  66. package/android/src/main/java/com/rnmaps/maps/MapModule.java +206 -206
  67. package/android/src/main/java/com/rnmaps/maps/MapOverlay.java +267 -151
  68. package/android/src/main/java/com/rnmaps/maps/MapPolygon.java +31 -1
  69. package/android/src/main/java/com/rnmaps/maps/MapPolyline.java +207 -141
  70. package/android/src/main/java/com/rnmaps/maps/MapPolylineManager.java +1 -16
  71. package/android/src/main/java/com/rnmaps/maps/MapView.java +1650 -1337
  72. package/android/src/main/jni/CMakeLists.txt +36 -0
  73. package/android/src/main/jni/RNMapsSpecs-generated.cpp +68 -0
  74. package/android/src/main/jni/RNMapsSpecs.h +31 -0
  75. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.cpp +29 -0
  76. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.h +31 -0
  77. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/EventEmitters.cpp +977 -0
  78. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/EventEmitters.h +846 -0
  79. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/Props.cpp +193 -0
  80. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/Props.h +1223 -0
  81. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI-generated.cpp +74 -0
  82. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI.h +268 -0
  83. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.cpp +24 -0
  84. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.h +109 -0
  85. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/States.cpp +16 -0
  86. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/States.h +113 -0
  87. package/ios/AirGoogleMaps/AIRGoogleMap.h +10 -11
  88. package/ios/AirGoogleMaps/AIRGoogleMap.m +103 -69
  89. package/ios/AirGoogleMaps/AIRGoogleMapCircle.m +23 -11
  90. package/ios/AirGoogleMaps/AIRGoogleMapManager.m +10 -9
  91. package/ios/AirGoogleMaps/AIRGoogleMapMarker.m +6 -3
  92. package/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m +1 -1
  93. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.m +3 -0
  94. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.h +0 -1
  95. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.m +0 -7
  96. package/ios/AirGoogleMaps/AIRGoogleMapUrlTile.m +2 -2
  97. package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.h +1 -1
  98. package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.m +4 -4
  99. package/ios/AirGoogleMaps/RNMapsGoogleMapView.h +1 -1
  100. package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +112 -43
  101. package/ios/AirGoogleMaps/RNMapsGoogleMapViewManager.mm +16 -1
  102. package/ios/AirGoogleMaps/RNMapsGooglePolygonView.h +26 -0
  103. package/ios/AirGoogleMaps/RNMapsGooglePolygonView.mm +217 -0
  104. package/ios/AirGoogleMaps/RNMapsGooglePolygonViewManager.mm +26 -0
  105. package/ios/AirMaps/AIRMap.h +8 -9
  106. package/ios/AirMaps/AIRMap.m +222 -239
  107. package/ios/AirMaps/AIRMapManager.m +10 -7
  108. package/ios/AirMaps/AIRMapMarker.h +1 -0
  109. package/ios/AirMaps/AIRMapMarker.m +165 -103
  110. package/ios/AirMaps/Callout/SMCalloutView.m +1 -1
  111. package/ios/AirMaps/FabricPlaceholders/PlaceHolderGoogleMapView.h +28 -0
  112. package/ios/AirMaps/FabricPlaceholders/PlaceHolderGoogleMapView.mm +68 -0
  113. package/ios/AirMaps/FabricPlaceholders/PlaceHolderPolygonView.h +25 -0
  114. package/ios/AirMaps/FabricPlaceholders/PlaceHolderPolygonView.mm +43 -0
  115. package/ios/AirMaps/RNMapsAirModule.h +1 -1
  116. package/ios/AirMaps/RNMapsAirModule.mm +4 -3
  117. package/ios/AirMaps/RNMapsDefines.h +0 -0
  118. package/ios/AirMaps/RNMapsMapView.h +1 -1
  119. package/ios/AirMaps/RNMapsMapView.mm +119 -95
  120. package/ios/AirMaps/RNMapsMapViewManager.mm +19 -1
  121. package/ios/AirMaps/RNMapsMarkerView.h +24 -0
  122. package/ios/AirMaps/RNMapsMarkerView.mm +430 -0
  123. package/ios/AirMaps/RNMapsMarkerViewManager.mm +28 -0
  124. package/ios/AirMaps.xcodeproj/project.pbxproj +20 -0
  125. package/ios/generated/RCTAppDependencyProvider.h +25 -0
  126. package/ios/generated/RCTAppDependencyProvider.mm +55 -0
  127. package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
  128. package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
  129. package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
  130. package/ios/generated/RCTThirdPartyComponentsProvider.mm +26 -0
  131. package/ios/{AirMaps → generated}/RNMapsAirModuleDelegate.h +2 -2
  132. package/ios/generated/RNMapsSpecs/ComponentDescriptors.cpp +29 -0
  133. package/ios/generated/RNMapsSpecs/ComponentDescriptors.h +31 -0
  134. package/ios/generated/RNMapsSpecs/EventEmitters.cpp +977 -0
  135. package/ios/generated/RNMapsSpecs/EventEmitters.h +846 -0
  136. package/ios/generated/RNMapsSpecs/Props.cpp +193 -0
  137. package/ios/generated/RNMapsSpecs/Props.h +1223 -0
  138. package/ios/generated/RNMapsSpecs/RCTComponentViewHelpers.h +591 -0
  139. package/ios/generated/RNMapsSpecs/RNMapsSpecs-generated.mm +92 -0
  140. package/ios/generated/RNMapsSpecs/RNMapsSpecs.h +137 -0
  141. package/ios/generated/RNMapsSpecs/ShadowNodes.cpp +24 -0
  142. package/ios/generated/RNMapsSpecs/ShadowNodes.h +109 -0
  143. package/ios/generated/RNMapsSpecs/States.cpp +16 -0
  144. package/ios/generated/RNMapsSpecs/States.h +113 -0
  145. package/ios/generated/RNMapsSpecsJSI-generated.cpp +74 -0
  146. package/ios/generated/RNMapsSpecsJSI.h +268 -0
  147. package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
  148. package/package.json +25 -18
  149. package/react-native-google-maps.podspec +26 -0
  150. package/react-native-maps-generated.podspec +31 -0
  151. package/react-native-maps.podspec +53 -15
  152. package/react-native.config.js +16 -0
  153. package/src/AnimatedRegion.ts +169 -0
  154. package/src/Geojson.tsx +541 -0
  155. package/src/MapCallout.tsx +77 -0
  156. package/src/MapCalloutSubview.tsx +64 -0
  157. package/src/MapCircle.tsx +162 -0
  158. package/src/MapHeatmap.tsx +125 -0
  159. package/src/MapLocalTile.tsx +60 -0
  160. package/src/MapMarker.tsx +531 -0
  161. package/src/MapMarkerNativeComponent.ts +51 -0
  162. package/src/MapOverlay.tsx +156 -0
  163. package/src/MapPolygon.tsx +188 -0
  164. package/src/MapPolygon.types.ts +25 -0
  165. package/src/MapPolyline.tsx +215 -0
  166. package/src/MapUrlTile.tsx +169 -0
  167. package/src/MapView.tsx +1223 -0
  168. package/src/MapView.types.ts +212 -0
  169. package/src/MapView.web.ts +2 -0
  170. package/src/MapViewNativeComponent.ts +86 -0
  171. package/src/MapWMSTile.tsx +148 -0
  172. package/src/ProviderConstants.ts +2 -0
  173. package/src/createFabricMap.tsx +253 -0
  174. package/src/decorateMapComponent.ts +219 -0
  175. package/src/fixImageProp.ts +17 -0
  176. package/src/index.ts +52 -0
  177. package/src/sharedTypes.ts +101 -0
  178. package/src/specs/NativeAirMapsModule.ts +36 -0
  179. package/src/specs/NativeComponentCallout.ts +63 -0
  180. package/src/specs/NativeComponentCircle.ts +93 -0
  181. package/src/specs/NativeComponentGoogleMapView.ts +913 -0
  182. package/src/specs/NativeComponentGooglePolygon.ts +94 -0
  183. package/src/specs/NativeComponentMapView.ts +1091 -0
  184. package/src/specs/NativeComponentMarker.ts +326 -0
  185. package/src/specs/NativeComponentOverlay.ts +89 -0
  186. package/src/specs/NativeComponentPolyline.ts +124 -0
  187. package/lib/AnimatedRegion.d.ts +0 -19
  188. package/lib/AnimatedRegion.js +0 -134
  189. package/lib/Geojson.d.ts +0 -204
  190. package/lib/Geojson.js +0 -166
  191. package/lib/MapCallout.d.ts +0 -40
  192. package/lib/MapCallout.js +0 -51
  193. package/lib/MapCalloutSubview.d.ts +0 -34
  194. package/lib/MapCalloutSubview.js +0 -48
  195. package/lib/MapCircle.d.ts +0 -117
  196. package/lib/MapCircle.js +0 -53
  197. package/lib/MapHeatmap.d.ts +0 -78
  198. package/lib/MapHeatmap.js +0 -59
  199. package/lib/MapLocalTile.d.ts +0 -35
  200. package/lib/MapLocalTile.js +0 -44
  201. package/lib/MapMarker.d.ts +0 -309
  202. package/lib/MapMarker.js +0 -116
  203. package/lib/MapMarkerNativeComponent.d.ts +0 -15
  204. package/lib/MapMarkerNativeComponent.js +0 -17
  205. package/lib/MapOverlay.d.ts +0 -87
  206. package/lib/MapOverlay.js +0 -63
  207. package/lib/MapPolygon.d.ts +0 -140
  208. package/lib/MapPolygon.js +0 -53
  209. package/lib/MapPolygon.types.d.ts +0 -18
  210. package/lib/MapPolygon.types.js +0 -2
  211. package/lib/MapPolyline.d.ts +0 -156
  212. package/lib/MapPolyline.js +0 -53
  213. package/lib/MapUrlTile.d.ts +0 -134
  214. package/lib/MapUrlTile.js +0 -44
  215. package/lib/MapView.d.ts +0 -715
  216. package/lib/MapView.js +0 -447
  217. package/lib/MapView.types.d.ts +0 -161
  218. package/lib/MapView.types.js +0 -2
  219. package/lib/MapView.web.d.ts +0 -1
  220. package/lib/MapView.web.js +0 -9
  221. package/lib/MapViewNativeComponent.d.ts +0 -18
  222. package/lib/MapViewNativeComponent.js +0 -19
  223. package/lib/MapWMSTile.d.ts +0 -116
  224. package/lib/MapWMSTile.js +0 -44
  225. package/lib/ProviderConstants.d.ts +0 -2
  226. package/lib/ProviderConstants.js +0 -5
  227. package/lib/createFabricMap.d.ts +0 -23
  228. package/lib/createFabricMap.js +0 -175
  229. package/lib/decorateMapComponent.d.ts +0 -36
  230. package/lib/decorateMapComponent.js +0 -80
  231. package/lib/index.d.ts +0 -38
  232. package/lib/index.js +0 -81
  233. package/lib/sharedTypes.d.ts +0 -81
  234. package/lib/sharedTypes.js +0 -2
  235. package/lib/sharedTypesInternal.js +0 -2
  236. package/lib/specs/NativeAirMapsModule.d.ts +0 -31
  237. package/lib/specs/NativeAirMapsModule.js +0 -4
  238. package/lib/specs/NativeComponentGoogleMapView.d.ts +0 -713
  239. package/lib/specs/NativeComponentGoogleMapView.js +0 -21
  240. package/lib/specs/NativeComponentMapView.d.ts +0 -855
  241. package/lib/specs/NativeComponentMapView.js +0 -21
  242. /package/ios/{AirMaps → generated}/RNMapsHostVewDelegate.h +0 -0
  243. /package/{lib/sharedTypesInternal.d.ts → src/sharedTypesInternal.ts} +0 -0
@@ -2,13 +2,16 @@ package com.rnmaps.maps;
2
2
 
3
3
  import static androidx.core.content.PermissionChecker.checkSelfPermission;
4
4
 
5
+ import android.app.Activity;
5
6
  import android.content.Context;
6
7
  import android.content.res.ColorStateList;
7
8
  import android.graphics.Bitmap;
8
9
  import android.graphics.Color;
9
10
  import android.graphics.Point;
10
11
  import android.location.Location;
11
- import android.util.Log;
12
+ import androidx.lifecycle.DefaultLifecycleObserver;
13
+ import androidx.lifecycle.LifecycleOwner;
14
+
12
15
  import android.view.GestureDetector;
13
16
  import android.view.MotionEvent;
14
17
  import android.view.View;
@@ -23,9 +26,11 @@ import androidx.core.content.PermissionChecker;
23
26
  import androidx.core.view.GestureDetectorCompat;
24
27
  import androidx.core.view.MotionEventCompat;
25
28
 
29
+ import com.facebook.react.common.MapBuilder;
30
+
26
31
  import com.facebook.react.bridge.Arguments;
27
- import com.facebook.react.bridge.LifecycleEventListener;
28
32
  import com.facebook.react.bridge.ReactApplicationContext;
33
+ import com.facebook.react.bridge.ReactContext;
29
34
  import com.facebook.react.bridge.ReadableArray;
30
35
  import com.facebook.react.bridge.ReadableMap;
31
36
  import com.facebook.react.bridge.WritableArray;
@@ -34,13 +39,12 @@ import com.facebook.react.bridge.WritableNativeArray;
34
39
  import com.facebook.react.bridge.WritableNativeMap;
35
40
  import com.facebook.react.uimanager.ThemedReactContext;
36
41
  import com.facebook.react.uimanager.UIManagerHelper;
37
- import com.facebook.react.uimanager.common.UIManagerType;
42
+ import com.facebook.react.uimanager.events.Event;
38
43
  import com.facebook.react.uimanager.events.EventDispatcher;
39
44
  import com.google.android.gms.maps.CameraUpdate;
40
45
  import com.google.android.gms.maps.CameraUpdateFactory;
41
46
  import com.google.android.gms.maps.GoogleMap;
42
47
  import com.google.android.gms.maps.GoogleMapOptions;
43
- import com.google.android.gms.maps.MapsInitializer;
44
48
  import com.google.android.gms.maps.OnMapReadyCallback;
45
49
  import com.google.android.gms.maps.Projection;
46
50
  import com.google.android.gms.maps.model.BitmapDescriptorFactory;
@@ -65,8 +69,9 @@ import com.google.maps.android.collections.PolylineManager;
65
69
  import com.google.maps.android.data.kml.KmlContainer;
66
70
  import com.google.maps.android.data.kml.KmlLayer;
67
71
  import com.google.maps.android.data.kml.KmlPlacemark;
68
- import com.google.maps.android.data.kml.KmlStyle;
69
72
 
73
+ import org.json.JSONException;
74
+ import org.json.JSONObject;
70
75
  import org.xmlpull.v1.XmlPullParserException;
71
76
 
72
77
  import java.io.IOException;
@@ -74,1309 +79,1621 @@ import java.io.InputStream;
74
79
  import java.util.ArrayList;
75
80
  import java.util.Arrays;
76
81
  import java.util.HashMap;
82
+ import java.util.Iterator;
77
83
  import java.util.List;
78
84
  import java.util.Map;
79
85
  import java.util.concurrent.ExecutionException;
80
86
 
87
+ import com.rnmaps.fabric.event.*;
88
+
81
89
  public class MapView extends com.google.android.gms.maps.MapView implements GoogleMap.InfoWindowAdapter,
82
- GoogleMap.OnMarkerDragListener, OnMapReadyCallback, GoogleMap.OnPoiClickListener, GoogleMap.OnIndoorStateChangeListener {
83
- public GoogleMap map;
84
- private MarkerManager markerManager;
85
- private MarkerManager.Collection markerCollection;
86
- private PolylineManager polylineManager;
87
- private PolylineManager.Collection polylineCollection;
88
- private PolygonManager polygonManager;
89
- private PolygonManager.Collection polygonCollection;
90
- private CircleManager.Collection circleCollection;
91
- private GroundOverlayManager groundOverlayManager;
92
- private GroundOverlayManager.Collection groundOverlayCollection;
93
- private ProgressBar mapLoadingProgressBar;
94
- private RelativeLayout mapLoadingLayout;
95
- private ImageView cacheImageView;
96
- private Boolean isMapLoaded = false;
97
- private Integer loadingBackgroundColor = null;
98
- private Integer loadingIndicatorColor = null;
99
-
100
- private LatLngBounds boundsToMove;
101
- private CameraUpdate cameraToSet;
102
- private boolean setPaddingDeferred = false;
103
- private boolean showUserLocation = false;
104
- private boolean handlePanDrag = false;
105
- private boolean moveOnMarkerPress = true;
106
- private boolean cacheEnabled = false;
107
- private boolean poiClickEnabled = true;
108
-
109
- private ReadableMap initialRegion;
110
- private ReadableMap region;
111
- private ReadableMap initialCamera;
112
- private ReadableMap camera;
113
- private String customMapStyleString;
114
- private boolean initialRegionSet = false;
115
- private boolean initialCameraSet = false;
116
- private LatLngBounds cameraLastIdleBounds;
117
- private int cameraMoveReason = 0;
118
- private MapMarker selectedMarker;
119
-
120
- private static final String[] PERMISSIONS = new String[]{
121
- "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"};
122
-
123
- private final List<MapFeature> features = new ArrayList<>();
124
- private final Map<Marker, MapMarker> markerMap = new HashMap<>();
125
- private final Map<Polyline, MapPolyline> polylineMap = new HashMap<>();
126
- private final Map<Polygon, MapPolygon> polygonMap = new HashMap<>();
127
- private final Map<GroundOverlay, MapOverlay> overlayMap = new HashMap<>();
128
- private final Map<TileOverlay, MapHeatmap> heatmapMap = new HashMap<>();
129
- private final Map<TileOverlay, MapGradientPolyline> gradientPolylineMap = new HashMap<>();
130
- private final GestureDetectorCompat gestureDetector;
131
- private final MapManager manager;
132
- private LifecycleEventListener lifecycleListener;
133
- private boolean paused = false;
134
- private boolean destroyed = false;
135
- private final ThemedReactContext context;
136
- private final EventDispatcher eventDispatcher;
137
- private final FusedLocationSource fusedLocationSource;
138
-
139
- private final ViewAttacherGroup attacherGroup;
140
- private LatLng tapLocation;
141
-
142
- private static boolean contextHasBug(Context context) {
143
- return context == null ||
144
- context.getResources() == null ||
145
- context.getResources().getConfiguration() == null;
146
- }
147
-
148
- // We do this to fix this bug:
149
- // https://github.com/react-native-maps/react-native-maps/issues/271
150
- //
151
- // which conflicts with another bug regarding the passed in context:
152
- // https://github.com/react-native-maps/react-native-maps/issues/1147
153
- //
154
- // Doing this allows us to avoid both bugs.
155
- private static Context getNonBuggyContext(ThemedReactContext reactContext,
156
- ReactApplicationContext appContext) {
157
- Context superContext = reactContext;
158
- if (!contextHasBug(appContext.getCurrentActivity())) {
159
- superContext = appContext.getCurrentActivity();
160
- } else if (contextHasBug(superContext)) {
161
- // we have the bug! let's try to find a better context to use
162
- if (!contextHasBug(reactContext.getCurrentActivity())) {
163
- superContext = reactContext.getCurrentActivity();
164
- } else if (!contextHasBug(reactContext.getApplicationContext())) {
165
- superContext = reactContext.getApplicationContext();
166
- }
167
-
168
- }
169
- return superContext;
170
- }
171
-
172
- public MapView(ThemedReactContext reactContext, ReactApplicationContext appContext,
173
- MapManager manager,
174
- GoogleMapOptions googleMapOptions) {
175
- super(getNonBuggyContext(reactContext, appContext), googleMapOptions);
176
-
177
- this.manager = manager;
178
- this.context = reactContext;
179
- MapsInitializer.initialize(context, this.manager.renderer, renderer -> Log.d("AirMapRenderer", renderer.toString()));
90
+ GoogleMap.OnMarkerDragListener, OnMapReadyCallback, GoogleMap.OnPoiClickListener, GoogleMap.OnIndoorStateChangeListener, DefaultLifecycleObserver {
91
+ public GoogleMap map;
92
+ private MarkerManager markerManager;
93
+ private MarkerManager.Collection markerCollection;
94
+ private PolylineManager polylineManager;
95
+ private PolylineManager.Collection polylineCollection;
96
+ private PolygonManager polygonManager;
97
+ private PolygonManager.Collection polygonCollection;
98
+ private CircleManager.Collection circleCollection;
99
+ private GroundOverlayManager groundOverlayManager;
100
+ private GroundOverlayManager.Collection groundOverlayCollection;
101
+ private ProgressBar mapLoadingProgressBar;
102
+ private RelativeLayout mapLoadingLayout;
103
+ private ImageView cacheImageView;
104
+ private Boolean isMapLoaded = false;
105
+
106
+ private Boolean isMapReady = false;
107
+
108
+ private Integer loadingBackgroundColor = null;
109
+ private Integer loadingIndicatorColor = null;
110
+
111
+ private LatLngBounds boundsToMove;
112
+ private CameraUpdate cameraToSet;
113
+ private boolean setPaddingDeferred = false;
114
+ private boolean showUserLocation = false;
115
+
116
+ private boolean showsTraffic = false;
117
+
118
+ private boolean handlePanDrag = false;
119
+ private boolean moveOnMarkerPress = true;
120
+ private boolean cacheEnabled = false;
121
+ private boolean poiClickEnabled = true;
122
+
123
+ private ReadableMap initialRegion;
124
+ private ReadableMap region;
125
+ private ReadableMap initialCamera;
126
+ private ReadableMap camera;
127
+ private String customMapStyleString;
128
+ private boolean initialRegionSet = false;
129
+ private boolean initialCameraSet = false;
130
+ private LatLngBounds cameraLastIdleBounds;
131
+ private int cameraMoveReason = 0;
132
+ private MapMarker selectedMarker;
133
+
134
+ private static final String[] PERMISSIONS = new String[]{
135
+ "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"};
136
+
137
+ private final List<MapFeature> features = new ArrayList<>();
138
+ private final Map<Marker, MapMarker> markerMap = new HashMap<>();
139
+ private final Map<Polyline, MapPolyline> polylineMap = new HashMap<>();
140
+ private final Map<Polygon, MapPolygon> polygonMap = new HashMap<>();
141
+ private final Map<GroundOverlay, MapOverlay> overlayMap = new HashMap<>();
142
+ private final Map<TileOverlay, MapHeatmap> heatmapMap = new HashMap<>();
143
+ private final Map<TileOverlay, MapGradientPolyline> gradientPolylineMap = new HashMap<>();
144
+ private final GestureDetectorCompat gestureDetector;
145
+ private boolean paused = false;
146
+ private boolean destroyed = false;
147
+ private final ThemedReactContext context;
148
+ private final FusedLocationSource fusedLocationSource;
149
+
150
+ private final ViewAttacherGroup attacherGroup;
151
+ private LatLng tapLocation;
152
+ private Float maxZoomLevel;
153
+ private Float minZoomLevel;
154
+ private Boolean pitchEnabled;
155
+ private Boolean showsCompass;
156
+ private Boolean rotateEnabled;
157
+ private Boolean zoomEnabled;
158
+ private Boolean zoomControlEnabled;
159
+ private Boolean setShowBuildings;
160
+ private Boolean showsIndoorLevelPicker;
161
+ private Boolean showIndoors;
162
+ private Boolean scrollEnabled;
163
+ private Boolean scrollDuringRotateOrZoomEnabled;
164
+ private String kmlSrc = null;
165
+
166
+ private static boolean contextHasBug(Context context) {
167
+ return context == null ||
168
+ context.getResources() == null ||
169
+ context.getResources().getConfiguration() == null;
170
+ }
171
+
172
+ // We do this to fix this bug:
173
+ // https://github.com/react-native-maps/react-native-maps/issues/271
174
+ //
175
+ // which conflicts with another bug regarding the passed in context:
176
+ // https://github.com/react-native-maps/react-native-maps/issues/1147
177
+ //
178
+ // Doing this allows us to avoid both bugs.
179
+ private static Context getNonBuggyContext(ThemedReactContext reactContext,
180
+ ReactApplicationContext appContext) {
181
+ Context superContext = reactContext;
182
+ if (!contextHasBug(appContext.getCurrentActivity())) {
183
+ superContext = appContext.getCurrentActivity();
184
+ } else if (contextHasBug(superContext)) {
185
+ // we have the bug! let's try to find a better context to use
186
+ if (!contextHasBug(reactContext.getCurrentActivity())) {
187
+ superContext = reactContext.getCurrentActivity();
188
+ } else if (!contextHasBug(reactContext.getApplicationContext())) {
189
+ superContext = reactContext.getApplicationContext();
190
+ }
191
+
192
+ }
193
+ return superContext;
194
+ }
195
+
196
+
197
+ @Override
198
+ public void onCreate(LifecycleOwner owner) {
180
199
  super.onCreate(null);
181
- super.onResume();
182
- super.getMapAsync(this);
200
+ }
201
+
202
+ @Override
203
+ public void onStart(LifecycleOwner owner) {
204
+ super.onStart();
205
+ }
206
+ @Override
207
+ public void onResume(LifecycleOwner owner) {
208
+ if (hasPermissions() && map != null) {
209
+ //noinspection MissingPermission
210
+ map.setMyLocationEnabled(showUserLocation);
211
+ map.setLocationSource(fusedLocationSource);
212
+ }
213
+ synchronized (MapView.this) {
214
+ if (!destroyed) {
215
+ MapView.this.onResume();
216
+ }
217
+ paused = false;
218
+ }
219
+ }
220
+
221
+
222
+ @Override
223
+ public void onPause(LifecycleOwner owner){
224
+ super.onPause();
225
+ if (hasPermissions() && map != null) {
226
+ //noinspection MissingPermission
227
+ map.setMyLocationEnabled(false);
228
+ }
229
+ synchronized (MapView.this) {
230
+ if (!destroyed) {
231
+ MapView.this.onPause();
232
+ }
233
+ paused = true;
234
+ }
235
+ }
236
+
237
+ @Override
238
+ public void onStop(LifecycleOwner owner) {
239
+ super.onStop();
240
+ }
241
+
242
+ @Override
243
+ public void onDestroy(LifecycleOwner owner){
244
+ MapView.this.doDestroy();
245
+ }
246
+
247
+ public MapView(ThemedReactContext context,
248
+ GoogleMapOptions googleMapOptions) {
249
+ super(context, googleMapOptions);
250
+ this.context = context;
251
+ Activity activity = context.getCurrentActivity();
252
+ if (activity instanceof LifecycleOwner) {
253
+ ((LifecycleOwner) activity).getLifecycle().addObserver(this);
254
+ }
255
+ super.getMapAsync(this);
256
+
257
+ final MapView view = this;
258
+
259
+ fusedLocationSource = new FusedLocationSource(context);
260
+
261
+ gestureDetector =
262
+ new GestureDetectorCompat(context, new GestureDetector.SimpleOnGestureListener() {
263
+
264
+ @Override
265
+ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
266
+ float distanceY) {
267
+ if (handlePanDrag) {
268
+ onPanDrag(e2);
269
+ }
270
+ return false;
271
+ }
272
+
273
+ @Override
274
+ public boolean onDoubleTap(MotionEvent ev) {
275
+ onDoublePress(ev);
276
+ return false;
277
+ }
278
+ });
279
+
280
+ this.addOnLayoutChangeListener(new OnLayoutChangeListener() {
281
+ @Override
282
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
283
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
284
+ if (!paused) {
285
+ MapView.this.cacheView();
286
+ }
287
+ }
288
+ });
289
+
290
+
291
+ // Set up a parent view for triggering visibility in subviews that depend on it.
292
+ // Mainly ReactImageView depends on Fresco which depends on onVisibilityChanged() event
293
+ attacherGroup = new ViewAttacherGroup(context);
294
+ LayoutParams attacherLayoutParams = new LayoutParams(0, 0);
295
+ attacherLayoutParams.width = 0;
296
+ attacherLayoutParams.height = 0;
297
+ attacherLayoutParams.leftMargin = 99999999;
298
+ attacherLayoutParams.topMargin = 99999999;
299
+ attacherGroup.setLayoutParams(attacherLayoutParams);
300
+ addView(attacherGroup);
301
+ }
302
+
303
+ public MapView(ThemedReactContext reactContext, ReactApplicationContext appContext,
304
+ MapManager manager,
305
+ GoogleMapOptions googleMapOptions) {
306
+ this(null, googleMapOptions);
307
+
308
+ }
309
+
310
+ public double[][] getMarkersFrames(boolean onlyVisible) {
311
+
312
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
313
+ boolean addedPosition = false;
314
+ LatLngBounds mapBounds = map.getProjection().getVisibleRegion().latLngBounds;
315
+ for (MapFeature feature : features) {
316
+ if (feature instanceof MapMarker) {
317
+ Marker marker = (Marker) feature.getFeature();
318
+ if (!onlyVisible ||
319
+ mapBounds.contains(marker.getPosition())) {
320
+ builder.include(marker.getPosition());
321
+ addedPosition = true;
322
+ }
323
+ }
324
+ }
325
+ if (addedPosition) {
326
+
327
+ LatLngBounds bounds = builder.build();
328
+ LatLng northEast = bounds.northeast;
329
+ LatLng southWest = bounds.southwest;
330
+
331
+ return new double[][]{
332
+ {northEast.longitude, northEast.latitude},
333
+ {southWest.longitude, southWest.latitude}
334
+ };
335
+ }
336
+ return null;
337
+ }
338
+
339
+ public void setShowsTraffic(boolean value) {
340
+ showsTraffic = value;
341
+ if (map != null){
342
+ map.setTrafficEnabled(value);
343
+ }
344
+ }
345
+
346
+
347
+ @FunctionalInterface
348
+ public interface EventCreator<T extends Event> {
349
+ T create(int surfaceId, int viewId, WritableMap payload);
350
+ }
351
+
352
+ private <T extends Event> void dispatchEvent(WritableMap payload, EventCreator<T> creator) {
353
+ dispatchEvent(payload, creator, getId(), context);
354
+ }
355
+
356
+ public static <T extends Event> void dispatchEvent(WritableMap payload, EventCreator<T> creator, int viewId, ReactContext context) {
357
+ // Cast context to ReactContext
358
+ ReactContext reactContext = context;
359
+
360
+ // Get the event dispatcher
361
+ EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, viewId);
362
+
363
+ // If there is a dispatcher, create and dispatch the event
364
+ if (eventDispatcher != null) {
365
+ int surfaceId = UIManagerHelper.getSurfaceId(reactContext);
366
+ T event = creator.create(surfaceId, viewId, payload);
367
+ eventDispatcher.dispatchEvent(event);
368
+ }
369
+ }
370
+
371
+ @Override
372
+ public void onMapReady(@NonNull final GoogleMap map) {
373
+ if (destroyed) {
374
+ return;
375
+ }
376
+ this.map = map;
377
+ if (maxZoomLevel != null) {
378
+ setMaxZoomLevel(maxZoomLevel);
379
+ }
380
+ if (minZoomLevel != null) {
381
+ setMinZoomLevel(minZoomLevel);
382
+ }
383
+ if (pitchEnabled != null) {
384
+ setPitchEnabled(pitchEnabled);
385
+ }
386
+ if (showsCompass != null) {
387
+ setShowsCompass(showsCompass);
388
+ }
389
+ if (rotateEnabled != null) {
390
+ setRotateEnabled(rotateEnabled);
391
+ }
392
+ if (zoomEnabled != null) {
393
+ setZoomEnabled(zoomEnabled);
394
+ }
395
+ if (zoomControlEnabled != null) {
396
+ setZoomControlEnabled(zoomControlEnabled);
397
+ }
398
+ if (setShowBuildings != null) {
399
+ setShowBuildings(setShowBuildings);
400
+ }
401
+ if (showsIndoorLevelPicker != null) {
402
+ setShowsIndoorLevelPicker(showsIndoorLevelPicker);
403
+ }
404
+ if (showIndoors != null) {
405
+ setShowIndoors(showIndoors);
406
+ }
407
+ if (scrollEnabled != null) {
408
+ setScrollEnabled(scrollEnabled);
409
+ }
410
+ if (scrollDuringRotateOrZoomEnabled != null) {
411
+ setScrollDuringRotateOrZoomEnabled(scrollDuringRotateOrZoomEnabled);
412
+ }
413
+
414
+ markerManager = new MarkerManager(map);
415
+ markerCollection = markerManager.newCollection();
416
+ polylineManager = new PolylineManager(map);
417
+ polylineCollection = polylineManager.newCollection();
418
+ polygonManager = new PolygonManager(map);
419
+ polygonCollection = polygonManager.newCollection();
420
+ CircleManager circleManager = new CircleManager(map);
421
+ circleCollection = circleManager.newCollection();
422
+ groundOverlayManager = new GroundOverlayManager(map);
423
+ groundOverlayCollection = groundOverlayManager.newCollection();
424
+
425
+ markerCollection.setInfoWindowAdapter(this);
426
+ markerCollection.setOnMarkerDragListener(this);
427
+ this.map.setOnIndoorStateChangeListener(this);
428
+
429
+ applyBridgedProps();
430
+ dispatchEvent(new WritableNativeMap(), OnMapReadyEvent::new);
431
+
432
+ final MapView view = this;
433
+
434
+ map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
435
+ @Override
436
+ public void onMyLocationChange(Location location) {
437
+ WritableMap event = new WritableNativeMap();
438
+
439
+ WritableMap coordinate = new WritableNativeMap();
440
+ coordinate.putDouble("latitude", location.getLatitude());
441
+ coordinate.putDouble("longitude", location.getLongitude());
442
+ coordinate.putDouble("altitude", location.getAltitude());
443
+ coordinate.putDouble("timestamp", location.getTime());
444
+ coordinate.putDouble("accuracy", location.getAccuracy());
445
+ coordinate.putDouble("speed", location.getSpeed());
446
+ coordinate.putDouble("heading", location.getBearing());
447
+ coordinate.putBoolean("isFromMockProvider", location.isFromMockProvider());
448
+
449
+ event.putMap("coordinate", coordinate);
450
+ dispatchEvent(event, OnUserLocationChangeEvent::new);
451
+ }
452
+ });
453
+
454
+ markerCollection.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
455
+ @Override
456
+ public boolean onMarkerClick(@NonNull Marker marker) {
457
+ MapMarker airMapMarker = getMarkerMap(marker);
458
+
459
+ WritableMap eventData = makeClickEventData(marker.getPosition());
460
+ eventData.putString("action", "press");
461
+ eventData.putString("id", airMapMarker.getIdentifier());
462
+ airMapMarker.dispatchEvent(eventData, OnPressEvent::new);
463
+
464
+ WritableMap mapEventData = makeClickEventData(marker.getPosition());
465
+ mapEventData.putString("action", "marker-press");
466
+ mapEventData.putString("id", airMapMarker.getIdentifier());
467
+
468
+ dispatchEvent(mapEventData, OnMarkerPressEvent::new);
469
+
470
+
471
+ handleMarkerSelection(airMapMarker);
472
+
473
+ // Return false to open the callout info window and center on the marker
474
+ // https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
475
+ // .OnMarkerClickListener
476
+ if (view.moveOnMarkerPress) {
477
+ return false;
478
+ } else {
479
+ marker.showInfoWindow();
480
+ return true;
481
+ }
482
+ }
483
+ });
484
+
485
+ polygonCollection.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
486
+ @Override
487
+ public void onPolygonClick(@NonNull Polygon polygon) {
488
+ WritableMap event = makeClickEventData(tapLocation);
489
+ event.putString("action", "polygon-press");
490
+ MapPolygon mapPolygon = polygonMap.get(polygon);
491
+ mapPolygon.dispatchEvent(event, OnPressEvent::new, context);
492
+ event = makeClickEventData(tapLocation);
493
+ event.putString("action", "polygon-press");
494
+ event.putString("id", String.valueOf(mapPolygon.getId()));
495
+ dispatchEvent(event, OnPressEvent::new);
496
+ }
497
+ });
498
+
499
+ polylineCollection.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
500
+ @Override
501
+ public void onPolylineClick(@NonNull Polyline polyline) {
502
+ WritableMap event = makeClickEventData(tapLocation);
503
+ event.putString("action", "polyline-press");
504
+ dispatchEvent(event, OnPressEvent::new);
505
+ event = makeClickEventData(tapLocation);
506
+ dispatchEvent(event, OnPressEvent::new, polylineMap.get(polyline).getId(), context);
507
+
508
+ }
509
+ });
510
+
511
+ markerCollection.setOnInfoWindowClickListener(marker -> {
512
+ WritableMap event = makeClickEventData(marker.getPosition());
513
+ event.putString("action", "callout-press");
514
+ dispatchEvent(event, OnCalloutPressEvent::new);
515
+
516
+
517
+ event = makeClickEventData(marker.getPosition());
518
+ event.putString("action", "callout-press");
519
+ MapMarker markerView = getMarkerMap(marker);
520
+ dispatchEvent(event, OnCalloutPressEvent::new, markerView.getId(), context);
521
+
522
+ MapCallout infoWindow = markerView.getCalloutView();
523
+ if (infoWindow != null) {
524
+ event = makeClickEventData(marker.getPosition());
525
+ event.putString("action", "callout-press");
526
+ dispatchEvent(event, OnPressEvent::new, infoWindow.getId(), context);
527
+ }
528
+ });
529
+
530
+ map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
531
+ @Override
532
+ public void onMapClick(@NonNull LatLng point) {
533
+ WritableMap event = makeClickEventData(point);
534
+ event.putString("action", "press");
535
+ dispatchEvent(event, OnPressEvent::new);
536
+
537
+ handleMarkerSelection(null);
538
+ }
539
+ });
540
+
541
+ map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
542
+ @Override
543
+ public void onMapLongClick(@NonNull LatLng point) {
544
+ WritableMap event = makeClickEventData(point);
545
+ event.putString("action", "long-press");
546
+ dispatchEvent(event, OnLongPressEvent::new);
547
+ }
548
+ });
549
+
550
+ groundOverlayCollection.setOnGroundOverlayClickListener(new GoogleMap.OnGroundOverlayClickListener() {
551
+ @Override
552
+ public void onGroundOverlayClick(@NonNull GroundOverlay groundOverlay) {
553
+ WritableMap event = makeClickEventData(groundOverlay.getPosition());
554
+ event.putString("action", "overlay-press");
555
+
556
+ dispatchEvent(event, OnPressEvent::new);
557
+ event = makeClickEventData(groundOverlay.getPosition());
558
+ dispatchEvent(event, OnPressEvent::new,overlayMap.get(groundOverlay).getId(), context);
559
+ }
560
+ });
183
561
 
184
- final MapView view = this;
562
+ map.setOnCameraMoveStartedListener(reason -> {
563
+ cameraMoveReason = reason;
564
+ boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason;
565
+ WritableMap event = new WritableNativeMap();
566
+ event.putBoolean("isGesture", isGesture);
567
+ dispatchEvent(event, OnRegionChangeStartEvent::new);
568
+ });
185
569
 
186
- fusedLocationSource = new FusedLocationSource(context);
570
+ map.setOnCameraMoveListener(() -> {
571
+ LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
572
+ cameraLastIdleBounds = null;
573
+ boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason;
574
+ WritableMap payload = OnRegionChangeEvent.payLoadFor(bounds, false, isGesture);
575
+ dispatchEvent(payload, OnRegionChangeStartEvent::new);
576
+ });
187
577
 
188
- gestureDetector =
189
- new GestureDetectorCompat(reactContext, new GestureDetector.SimpleOnGestureListener() {
578
+ map.setOnCameraIdleListener(() -> {
579
+ LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
580
+ if ((cameraMoveReason != 0) &&
581
+ ((cameraLastIdleBounds == null) ||
582
+ LatLngBoundsUtils.BoundsAreDifferent(bounds, cameraLastIdleBounds))) {
190
583
 
191
- @Override
192
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
193
- float distanceY) {
194
- if (handlePanDrag) {
195
- onPanDrag(e2);
584
+ cameraLastIdleBounds = bounds;
585
+ boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason;
586
+ WritableMap payload = OnRegionChangeEvent.payLoadFor(bounds, false, isGesture);
587
+ dispatchEvent(payload, OnRegionChangeCompleteEvent::new);
196
588
  }
197
- return false;
198
- }
199
-
200
- @Override
201
- public boolean onDoubleTap(MotionEvent ev) {
202
- onDoublePress(ev);
203
- return false;
204
- }
205
589
  });
206
590
 
207
- this.addOnLayoutChangeListener(new OnLayoutChangeListener() {
208
- @Override public void onLayoutChange(View v, int left, int top, int right, int bottom,
209
- int oldLeft, int oldTop, int oldRight, int oldBottom) {
591
+ map.setOnMapLoadedCallback(() -> {
592
+ isMapLoaded = true;
593
+ dispatchEvent(new WritableNativeMap(), OnMapLoadedEvent::new);
594
+ MapView.this.cacheView();
595
+ });
596
+
597
+
598
+ map.setTrafficEnabled(showsTraffic);
599
+
600
+
601
+ isMapReady = true;
602
+ if (kmlSrc != null){
603
+ setKmlSrc(kmlSrc);
604
+ kmlSrc = null;
605
+ }
606
+ }
607
+
608
+ private synchronized void handleMarkerSelection(MapMarker target) {
609
+ if (selectedMarker == target) {
610
+ return;
611
+ }
612
+
613
+ WritableMap event;
614
+
615
+ if (selectedMarker != null) {
616
+ event = makeClickEventData(selectedMarker.getPosition());
617
+ event.putString("action", "marker-deselect");
618
+ event.putString("id", selectedMarker.getIdentifier());
619
+ selectedMarker.dispatchEvent(event, OnDeselectEvent::new);
620
+
621
+ event = makeClickEventData(selectedMarker.getPosition());
622
+ event.putString("action", "marker-deselect");
623
+ event.putString("id", selectedMarker.getIdentifier());
624
+ dispatchEvent(event, OnMarkerDeselectEvent::new);
625
+ }
626
+
627
+ if (target != null) {
628
+ event = makeClickEventData(target.getPosition());
629
+ event.putString("action", "marker-select");
630
+ event.putString("id", target.getIdentifier());
631
+ target.dispatchEvent(event, OnSelectEvent::new);
632
+
633
+ event = makeClickEventData(target.getPosition());
634
+ event.putString("action", "marker-select");
635
+ event.putString("id", target.getIdentifier());
636
+ dispatchEvent(event, OnMarkerSelectEvent::new);
637
+ }
638
+
639
+ selectedMarker = target;
640
+ }
641
+
642
+ private boolean hasPermissions() {
643
+ return checkSelfPermission(getContext(), PERMISSIONS[0]) == PermissionChecker.PERMISSION_GRANTED ||
644
+ checkSelfPermission(getContext(), PERMISSIONS[1]) == PermissionChecker.PERMISSION_GRANTED;
645
+ }
646
+
647
+
648
+ public static Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
649
+ MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
650
+ builder.put(OnPressEvent.EVENT_NAME, MapBuilder.of("registrationName", OnPressEvent.EVENT_NAME));
651
+ builder.put(OnLongPressEvent.EVENT_NAME, MapBuilder.of("registrationName", OnLongPressEvent.EVENT_NAME));
652
+ return builder.build();
653
+ }
654
+ // , ,
655
+ public static Map<String, Object> getExportedCustomDirectEventTypeConstants() {
656
+ MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
657
+ builder.put(OnMarkerPressEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMarkerPressEvent.EVENT_NAME));
658
+ builder.put(OnCalloutPressEvent.EVENT_NAME, MapBuilder.of("registrationName", OnCalloutPressEvent.EVENT_NAME));
659
+ builder.put(OnMarkerDragEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMarkerDragEvent.EVENT_NAME));
660
+ builder.put(OnMarkerDragStartEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMarkerDragStartEvent.EVENT_NAME));
661
+ builder.put(OnMarkerDragEndEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMarkerDragEndEvent.EVENT_NAME));
662
+ builder.put(OnPoiClickEvent.EVENT_NAME, MapBuilder.of("registrationName", OnPoiClickEvent.EVENT_NAME));
663
+ builder.put(OnDoublePressEvent.EVENT_NAME, MapBuilder.of("registrationName", OnDoublePressEvent.EVENT_NAME));
664
+ builder.put(OnPanDragEvent.EVENT_NAME, MapBuilder.of("registrationName", OnPanDragEvent.EVENT_NAME));
665
+ builder.put(OnMarkerSelectEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMarkerSelectEvent.EVENT_NAME));
666
+ builder.put(OnMarkerDeselectEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMarkerDeselectEvent.EVENT_NAME));
667
+ builder.put(OnMapLoadedEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMapLoadedEvent.EVENT_NAME));
668
+ builder.put(OnMapReadyEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMapReadyEvent.EVENT_NAME));
669
+ builder.put(OnUserLocationChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", OnUserLocationChangeEvent.EVENT_NAME));
670
+ builder.put(OnRegionChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", OnRegionChangeEvent.EVENT_NAME));
671
+ builder.put(OnRegionChangeStartEvent.EVENT_NAME, MapBuilder.of("registrationName", OnRegionChangeStartEvent.EVENT_NAME));
672
+ builder.put(OnRegionChangeCompleteEvent.EVENT_NAME, MapBuilder.of("registrationName", OnRegionChangeCompleteEvent.EVENT_NAME));
673
+ builder.put(OnIndoorBuildingFocusedEvent.EVENT_NAME, MapBuilder.of("registrationName", OnIndoorBuildingFocusedEvent.EVENT_NAME));
674
+ builder.put(OnIndoorLevelActivatedEvent.EVENT_NAME, MapBuilder.of("registrationName", OnIndoorLevelActivatedEvent.EVENT_NAME));
675
+ builder.put(OnKmlReadyEvent.EVENT_NAME, MapBuilder.of("registrationName", OnKmlReadyEvent.EVENT_NAME));
676
+ return builder.build();
677
+ }
678
+
679
+
680
+ /*
681
+ onDestroy is final method so I can't override it.
682
+ */
683
+ public synchronized void doDestroy() {
684
+ if (destroyed) {
685
+ return;
686
+ }
687
+ destroyed = true;
688
+
689
+ Activity activity = context.getCurrentActivity();
690
+ if (activity instanceof LifecycleOwner) {
691
+ ((LifecycleOwner) activity).getLifecycle().removeObserver(this);
692
+ }
210
693
  if (!paused) {
211
- MapView.this.cacheView();
212
- }
213
- }
214
- });
215
-
216
- int uiManagerType = UIManagerType.DEFAULT;
217
- if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
218
- uiManagerType = UIManagerType.FABRIC;
219
- }
220
-
221
- eventDispatcher = UIManagerHelper
222
- .getUIManager(reactContext, uiManagerType)
223
- .getEventDispatcher();
224
-
225
- // Set up a parent view for triggering visibility in subviews that depend on it.
226
- // Mainly ReactImageView depends on Fresco which depends on onVisibilityChanged() event
227
- attacherGroup = new ViewAttacherGroup(context);
228
- LayoutParams attacherLayoutParams = new LayoutParams(0, 0);
229
- attacherLayoutParams.width = 0;
230
- attacherLayoutParams.height = 0;
231
- attacherLayoutParams.leftMargin = 99999999;
232
- attacherLayoutParams.topMargin = 99999999;
233
- attacherGroup.setLayoutParams(attacherLayoutParams);
234
- addView(attacherGroup);
235
- }
236
-
237
- @Override
238
- public void onMapReady(@NonNull final GoogleMap map) {
239
- if (destroyed) {
240
- return;
241
- }
242
- this.map = map;
243
-
244
- markerManager = new MarkerManager(map);
245
- markerCollection = markerManager.newCollection();
246
- polylineManager = new PolylineManager(map);
247
- polylineCollection = polylineManager.newCollection();
248
- polygonManager = new PolygonManager(map);
249
- polygonCollection = polygonManager.newCollection();
250
- CircleManager circleManager = new CircleManager(map);
251
- circleCollection = circleManager.newCollection();
252
- groundOverlayManager = new GroundOverlayManager(map);
253
- groundOverlayCollection = groundOverlayManager.newCollection();
254
-
255
- markerCollection.setInfoWindowAdapter(this);
256
- markerCollection.setOnMarkerDragListener(this);
257
- this.map.setOnIndoorStateChangeListener(this);
258
-
259
- applyBridgedProps();
260
-
261
- manager.pushEvent(context, this, "onMapReady", new WritableNativeMap());
262
-
263
- final MapView view = this;
264
-
265
- map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
266
- @Override
267
- public void onMyLocationChange(Location location){
268
- WritableMap event = new WritableNativeMap();
694
+ onPause();
695
+ paused = true;
696
+ }
697
+ onDestroy();
698
+ }
269
699
 
270
- WritableMap coordinate = new WritableNativeMap();
271
- coordinate.putDouble("latitude", location.getLatitude());
272
- coordinate.putDouble("longitude", location.getLongitude());
273
- coordinate.putDouble("altitude", location.getAltitude());
274
- coordinate.putDouble("timestamp", location.getTime());
275
- coordinate.putDouble("accuracy", location.getAccuracy());
276
- coordinate.putDouble("speed", location.getSpeed());
277
- coordinate.putDouble("heading", location.getBearing());
278
- coordinate.putBoolean("isFromMockProvider", location.isFromMockProvider());
700
+ public void setInitialCameraSet(boolean initialCameraSet) {
701
+ this.initialCameraSet = initialCameraSet;
702
+ }
279
703
 
280
- event.putMap("coordinate", coordinate);
704
+ public void setInitialRegion(ReadableMap initialRegion) {
705
+ this.initialRegion = initialRegion;
706
+ // Theoretically onMapReady might be called before setInitialRegion
707
+ // In that case, trigger moveToRegion manually
708
+ if (!initialRegionSet && map != null) {
709
+ moveToRegion(initialRegion);
710
+ initialRegionSet = true;
711
+ }
712
+ }
281
713
 
282
- manager.pushEvent(context, view, "onUserLocationChange", event);
283
- }
284
- });
714
+ public void setInitialCamera(ReadableMap initialCamera) {
715
+ this.initialCamera = initialCamera;
716
+ if (!initialCameraSet && map != null) {
717
+ moveToCamera(initialCamera);
718
+ initialCameraSet = true;
719
+ }
720
+ }
285
721
 
286
- markerCollection.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
287
- @Override
288
- public boolean onMarkerClick(@NonNull Marker marker) {
289
- MapMarker airMapMarker = getMarkerMap(marker);
722
+ private void applyBridgedProps() {
723
+ if (initialRegion != null) {
724
+ moveToRegion(initialRegion);
725
+ initialRegionSet = true;
726
+ } else if (region != null) {
727
+ moveToRegion(region);
728
+ } else if (initialCamera != null) {
729
+ moveToCamera(initialCamera);
730
+ initialCameraSet = true;
731
+ } else if (camera != null) {
732
+ moveToCamera(camera);
733
+ }
734
+ if (customMapStyleString != null) {
735
+ map.setMapStyle(new MapStyleOptions(customMapStyleString));
736
+ }
737
+ this.setPoiClickEnabled(poiClickEnabled);
738
+ }
290
739
 
291
- WritableMap event = makeClickEventData(marker.getPosition());
292
- event.putString("action", "marker-press");
293
- event.putString("id", airMapMarker.getIdentifier());
294
- manager.pushEvent(context, view, "onMarkerPress", event);
740
+ public static LatLngBounds latLngBoundsFromRegion(ReadableMap region) {
741
+ if (region == null) return null;
742
+
743
+ double lng = region.getDouble("longitude");
744
+ double lat = region.getDouble("latitude");
745
+ double lngDelta = region.getDouble("longitudeDelta");
746
+ double latDelta = region.getDouble("latitudeDelta");
747
+ return new LatLngBounds(
748
+ new LatLng(lat - latDelta / 2, lng - lngDelta / 2), // southwest
749
+ new LatLng(lat + latDelta / 2, lng + lngDelta / 2) // northeast
750
+ );
751
+ }
295
752
 
296
- event = makeClickEventData(marker.getPosition());
297
- event.putString("action", "marker-press");
298
- event.putString("id", airMapMarker.getIdentifier());
299
- manager.pushEvent(context, airMapMarker, "onPress", event);
753
+ private void moveToRegion(ReadableMap region) {
754
+ LatLngBounds bounds = latLngBoundsFromRegion(region);
755
+ if (bounds == null) return;
756
+ double lng = region.getDouble("longitude");
757
+ double lat = region.getDouble("latitude");
758
+ if (super.getHeight() <= 0 || super.getWidth() <= 0) {
759
+ // in this case, our map has not been laid out yet, so we save the bounds in a local
760
+ // variable, and make a guess of zoomLevel 10. Not to worry, though: as soon as layout
761
+ // occurs, we will move the camera to the saved bounds. Note that if we tried to move
762
+ // to the bounds now, it would trigger an exception.
763
+ map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 10));
764
+ boundsToMove = bounds;
765
+ } else {
766
+ map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
767
+ boundsToMove = null;
768
+ }
769
+ }
770
+
771
+ public void setRegion(ReadableMap region) {
772
+ this.region = region;
773
+ if (region != null && map != null) {
774
+ moveToRegion(region);
775
+ }
776
+ }
777
+
778
+ public void setCamera(ReadableMap camera) {
779
+ this.camera = camera;
780
+ if (camera != null && map != null) {
781
+ moveToCamera(camera);
782
+ }
783
+ }
784
+
785
+ public static CameraPosition cameraPositionFromMap(ReadableMap camera) {
786
+ if (camera == null) return null;
300
787
 
301
- handleMarkerSelection(airMapMarker);
788
+ CameraPosition.Builder builder = new CameraPosition.Builder();
302
789
 
303
- // Return false to open the callout info window and center on the marker
304
- // https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
305
- // .OnMarkerClickListener
306
- if (view.moveOnMarkerPress) {
307
- return false;
790
+ ReadableMap center = camera.getMap("center");
791
+ if (center != null) {
792
+ double lng = center.getDouble("longitude");
793
+ double lat = center.getDouble("latitude");
794
+ builder.target(new LatLng(lat, lng));
795
+ }
796
+
797
+ builder.tilt((float) camera.getDouble("pitch"));
798
+ builder.bearing((float) camera.getDouble("heading"));
799
+ builder.zoom((float) camera.getDouble("zoom"));
800
+
801
+ return builder.build();
802
+ }
803
+
804
+ public CameraPosition cameraPositionFromJSON(JSONObject camera) throws JSONException {
805
+ if (camera == null) return null;
806
+ if (map == null) return null;
807
+
808
+ CameraPosition.Builder builder = new CameraPosition.Builder();
809
+
810
+ if (camera.has("center")) {
811
+ JSONObject center = camera.getJSONObject("center");
812
+ if (center != null) {
813
+ double lng = center.getDouble("longitude");
814
+ double lat = center.getDouble("latitude");
815
+ builder.target(new LatLng(lat, lng));
816
+ }
308
817
  } else {
309
- marker.showInfoWindow();
310
- return true;
311
- }
312
- }
313
- });
314
-
315
- polygonCollection.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
316
- @Override
317
- public void onPolygonClick(@NonNull Polygon polygon) {
318
- WritableMap event = makeClickEventData(tapLocation);
319
- event.putString("action", "polygon-press");
320
- manager.pushEvent(context, polygonMap.get(polygon), "onPress", event);
321
- }
322
- });
323
-
324
- polylineCollection.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
325
- @Override
326
- public void onPolylineClick(@NonNull Polyline polyline) {
327
- WritableMap event = makeClickEventData(tapLocation);
328
- event.putString("action", "polyline-press");
329
- manager.pushEvent(context, polylineMap.get(polyline), "onPress", event);
330
- }
331
- });
332
-
333
- markerCollection.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
334
- @Override
335
- public void onInfoWindowClick(@NonNull Marker marker) {
336
- WritableMap event = makeClickEventData(marker.getPosition());
337
- event.putString("action", "callout-press");
338
- manager.pushEvent(context, view, "onCalloutPress", event);
818
+ builder.target(map.getCameraPosition().target);
819
+ }
339
820
 
340
- event = makeClickEventData(marker.getPosition());
341
- event.putString("action", "callout-press");
342
- MapMarker markerView = getMarkerMap(marker);
343
- manager.pushEvent(context, markerView, "onCalloutPress", event);
821
+ if (camera.has("pitch")) {
822
+ builder.tilt((float) camera.getDouble("pitch"));
823
+ } else {
824
+ builder.tilt(map.getCameraPosition().tilt);
825
+ }
826
+ if (camera.has("heading")) {
827
+ builder.bearing((float) camera.getDouble("heading"));
828
+ } else {
829
+ builder.bearing(map.getCameraPosition().bearing);
830
+ }
831
+ if (camera.has("zoom")) {
832
+ builder.zoom((float) camera.getDouble("zoom"));
833
+ } else {
834
+ builder.zoom(map.getCameraPosition().zoom);
835
+ }
344
836
 
345
- event = makeClickEventData(marker.getPosition());
346
- event.putString("action", "callout-press");
347
- MapCallout infoWindow = markerView.getCalloutView();
348
- if (infoWindow != null) manager.pushEvent(context, infoWindow, "onPress", event);
349
- }
350
- });
351
-
352
- map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
353
- @Override
354
- public void onMapClick(@NonNull LatLng point) {
355
- WritableMap event = makeClickEventData(point);
356
- event.putString("action", "press");
357
- manager.pushEvent(context, view, "onPress", event);
358
-
359
- handleMarkerSelection(null);
360
- }
361
- });
362
-
363
- map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
364
- @Override
365
- public void onMapLongClick(@NonNull LatLng point) {
366
- WritableMap event = makeClickEventData(point);
367
- event.putString("action", "long-press");
368
- manager.pushEvent(context, view, "onLongPress", makeClickEventData(point));
369
- }
370
- });
371
-
372
- groundOverlayCollection.setOnGroundOverlayClickListener(new GoogleMap.OnGroundOverlayClickListener() {
373
- @Override
374
- public void onGroundOverlayClick(@NonNull GroundOverlay groundOverlay) {
375
- WritableMap event = makeClickEventData(groundOverlay.getPosition());
376
- event.putString("action", "overlay-press");
377
- manager.pushEvent(context, overlayMap.get(groundOverlay), "onPress", event);
378
- }
379
- });
380
-
381
- map.setOnCameraMoveStartedListener(new GoogleMap.OnCameraMoveStartedListener() {
382
- @Override
383
- public void onCameraMoveStarted(int reason) {
384
- cameraMoveReason = reason;
385
- boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason;
386
- WritableMap event = new WritableNativeMap();
387
- event.putBoolean("isGesture", isGesture);
388
- manager.pushEvent(context, view, "onRegionChangeStart", event);
389
- }
390
- });
391
-
392
- map.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
393
- @Override
394
- public void onCameraMove() {
395
- LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
837
+ return builder.build();
838
+ }
396
839
 
397
- cameraLastIdleBounds = null;
398
- boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason;
840
+ public void moveToCamera(ReadableMap cameraMap) {
841
+ moveToCamera(cameraPositionFromMap(cameraMap));
842
+ }
399
843
 
400
- RegionChangeEvent event = new RegionChangeEvent(getId(), bounds, true, isGesture);
401
- eventDispatcher.dispatchEvent(event);
402
- }
403
- });
844
+ public void moveToCamera(CameraPosition camera) {
845
+ if (camera == null) return;
846
+ CameraUpdate update = CameraUpdateFactory.newCameraPosition(camera);
404
847
 
405
- map.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
406
- @Override
407
- public void onCameraIdle() {
408
- LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
409
- if ((cameraMoveReason != 0) &&
410
- ((cameraLastIdleBounds == null) ||
411
- LatLngBoundsUtils.BoundsAreDifferent(bounds, cameraLastIdleBounds))) {
412
-
413
- cameraLastIdleBounds = bounds;
414
- boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason;
415
-
416
- RegionChangeEvent event = new RegionChangeEvent(getId(), bounds, false, isGesture);
417
- eventDispatcher.dispatchEvent(event);
418
- }
419
- }
420
- });
421
-
422
- map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
423
- @Override public void onMapLoaded() {
424
- isMapLoaded = true;
425
- manager.pushEvent(context, view, "onMapLoaded", new WritableNativeMap());
426
- MapView.this.cacheView();
427
- }
428
- });
429
-
430
- // We need to be sure to disable location-tracking when app enters background, in-case some
431
- // other module
432
- // has acquired a wake-lock and is controlling location-updates, otherwise, location-manager
433
- // will be left
434
- // updating location constantly, killing the battery, even though some other location-mgmt
435
- // module may
436
- // desire to shut-down location-services.
437
- lifecycleListener = new LifecycleEventListener() {
438
- @Override
439
- public void onHostResume() {
440
- if (hasPermissions() && map != null) {
441
- //noinspection MissingPermission
442
- map.setMyLocationEnabled(showUserLocation);
443
- map.setLocationSource(fusedLocationSource);
848
+ if (super.getHeight() <= 0 || super.getWidth() <= 0) {
849
+ // in this case, our map has not been laid out yet, so we save the camera update in a
850
+ // local variable. As soon as layout occurs, we will move the camera to the saved update.
851
+ // Note that if we tried to move to the camera now, it would trigger an exception.
852
+ cameraToSet = update;
853
+ } else {
854
+ map.moveCamera(update);
855
+ cameraToSet = null;
444
856
  }
445
- synchronized (MapView.this) {
446
- if (!destroyed) {
447
- MapView.this.onResume();
448
- }
449
- paused = false;
857
+ }
858
+
859
+ public void setMapStyle(@Nullable String customMapStyleString) {
860
+ this.customMapStyleString = customMapStyleString;
861
+ if (map != null && customMapStyleString != null) {
862
+ map.setMapStyle(new MapStyleOptions(customMapStyleString));
450
863
  }
451
- }
864
+ }
452
865
 
453
- @Override
454
- public void onHostPause() {
455
- if (hasPermissions() && map != null) {
456
- //noinspection MissingPermission
457
- map.setMyLocationEnabled(false);
866
+ public void setShowsUserLocation(boolean showUserLocation) {
867
+ this.showUserLocation = showUserLocation; // hold onto this for lifecycle handling
868
+ if (hasPermissions()) {
869
+ map.setLocationSource(fusedLocationSource);
870
+ //noinspection MissingPermission
871
+ map.setMyLocationEnabled(showUserLocation);
458
872
  }
459
- synchronized (MapView.this) {
460
- if (!destroyed) {
461
- MapView.this.onPause();
462
- }
463
- paused = true;
873
+ }
874
+
875
+ public void setUserLocationPriority(int priority) {
876
+ fusedLocationSource.setPriority(priority);
877
+ }
878
+
879
+ public void setUserLocationUpdateInterval(int interval) {
880
+ fusedLocationSource.setInterval(interval);
881
+ }
882
+
883
+ public void setUserLocationFastestInterval(int interval) {
884
+ fusedLocationSource.setFastestInterval(interval);
885
+ }
886
+
887
+ public void setShowsMyLocationButton(boolean showMyLocationButton) {
888
+ if (map != null) {
889
+ if (hasPermissions() || !showMyLocationButton) {
890
+ map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
891
+ }
464
892
  }
465
- }
893
+ }
466
894
 
467
- @Override
468
- public void onHostDestroy() {
469
- MapView.this.doDestroy();
470
- }
471
- };
895
+ public void setToolbarEnabled(boolean toolbarEnabled) {
896
+ if (map != null) {
897
+ if (hasPermissions() || !toolbarEnabled) {
898
+ map.getUiSettings().setMapToolbarEnabled(toolbarEnabled);
899
+ }
900
+ }
901
+ }
472
902
 
473
- context.addLifecycleEventListener(lifecycleListener);
474
- }
903
+ public void setMapType(int mapType) {
904
+ if (map != null) {
905
+ map.setMapType(mapType);
906
+ }
907
+ }
475
908
 
476
- private synchronized void handleMarkerSelection(MapMarker target) {
477
- if (selectedMarker == target) {
478
- return;
479
- }
480
-
481
- WritableMap event;
482
-
483
- if (selectedMarker != null) {
484
- event = makeClickEventData(selectedMarker.getPosition());
485
- event.putString("action", "marker-deselect");
486
- event.putString("id", selectedMarker.getIdentifier());
487
- manager.pushEvent(context, selectedMarker, "onDeselect", event);
488
-
489
- event = makeClickEventData(selectedMarker.getPosition());
490
- event.putString("action", "marker-deselect");
491
- event.putString("id", selectedMarker.getIdentifier());
492
- manager.pushEvent(context, this, "onMarkerDeselect", event);
493
- }
494
-
495
- if (target != null) {
496
- event = makeClickEventData(target.getPosition());
497
- event.putString("action", "marker-select");
498
- event.putString("id", target.getIdentifier());
499
- manager.pushEvent(context, target, "onSelect", event);
500
-
501
- event = makeClickEventData(target.getPosition());
502
- event.putString("action", "marker-select");
503
- event.putString("id", target.getIdentifier());
504
- manager.pushEvent(context, this, "onMarkerSelect", event);
505
- }
506
-
507
- selectedMarker = target;
508
- }
509
-
510
- private boolean hasPermissions() {
511
- return checkSelfPermission(getContext(), PERMISSIONS[0]) == PermissionChecker.PERMISSION_GRANTED ||
512
- checkSelfPermission(getContext(), PERMISSIONS[1]) == PermissionChecker.PERMISSION_GRANTED;
513
- }
514
-
515
-
516
- /*
517
- onDestroy is final method so I can't override it.
518
- */
519
- public synchronized void doDestroy() {
520
- if (destroyed) {
521
- return;
522
- }
523
- destroyed = true;
524
-
525
- if (lifecycleListener != null && context != null) {
526
- context.removeLifecycleEventListener(lifecycleListener);
527
- lifecycleListener = null;
528
- }
529
- if (!paused) {
530
- onPause();
531
- paused = true;
532
- }
533
- onDestroy();
534
- }
535
-
536
- public void setInitialRegion(ReadableMap initialRegion) {
537
- this.initialRegion = initialRegion;
538
- // Theoretically onMapReady might be called before setInitialRegion
539
- // In that case, trigger moveToRegion manually
540
- if (!initialRegionSet && map != null) {
541
- moveToRegion(initialRegion);
542
- initialRegionSet = true;
543
- }
544
- }
545
-
546
- public void setInitialCamera(ReadableMap initialCamera) {
547
- this.initialCamera = initialCamera;
548
- if (!initialCameraSet && map != null) {
549
- moveToCamera(initialCamera);
550
- initialCameraSet = true;
551
- }
552
- }
553
-
554
- private void applyBridgedProps() {
555
- if(initialRegion != null) {
556
- moveToRegion(initialRegion);
557
- initialRegionSet = true;
558
- } else if(region != null) {
559
- moveToRegion(region);
560
- } else if (initialCamera != null) {
561
- moveToCamera(initialCamera);
562
- initialCameraSet = true;
563
- } else if (camera != null) {
564
- moveToCamera(camera);
565
- }
566
- if(customMapStyleString != null) {
567
- map.setMapStyle(new MapStyleOptions(customMapStyleString));
568
- }
569
- this.setPoiClickEnabled(poiClickEnabled);
570
- }
571
-
572
- private void moveToRegion(ReadableMap region) {
573
- if (region == null) return;
574
-
575
- double lng = region.getDouble("longitude");
576
- double lat = region.getDouble("latitude");
577
- double lngDelta = region.getDouble("longitudeDelta");
578
- double latDelta = region.getDouble("latitudeDelta");
579
- LatLngBounds bounds = new LatLngBounds(
580
- new LatLng(lat - latDelta / 2, lng - lngDelta / 2), // southwest
581
- new LatLng(lat + latDelta / 2, lng + lngDelta / 2) // northeast
582
- );
583
- if (super.getHeight() <= 0 || super.getWidth() <= 0) {
584
- // in this case, our map has not been laid out yet, so we save the bounds in a local
585
- // variable, and make a guess of zoomLevel 10. Not to worry, though: as soon as layout
586
- // occurs, we will move the camera to the saved bounds. Note that if we tried to move
587
- // to the bounds now, it would trigger an exception.
588
- map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 10));
589
- boundsToMove = bounds;
590
- } else {
591
- map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
592
- boundsToMove = null;
593
- }
594
- }
595
-
596
- public void setRegion(ReadableMap region) {
597
- this.region = region;
598
- if(region != null && map != null) {
599
- moveToRegion(region);
600
- }
601
- }
602
-
603
- public void setCamera(ReadableMap camera) {
604
- this.camera = camera;
605
- if(camera != null && map != null) {
606
- moveToCamera(camera);
607
- }
608
- }
609
- public static CameraPosition cameraPositionFromMap(ReadableMap camera){
610
- if (camera == null) return null;
611
-
612
- CameraPosition.Builder builder = new CameraPosition.Builder();
613
-
614
- ReadableMap center = camera.getMap("center");
615
- if (center != null) {
616
- double lng = center.getDouble("longitude");
617
- double lat = center.getDouble("latitude");
618
- builder.target(new LatLng(lat, lng));
619
- }
620
-
621
- builder.tilt((float)camera.getDouble("pitch"));
622
- builder.bearing((float)camera.getDouble("heading"));
623
- builder.zoom((float)camera.getDouble("zoom"));
624
-
625
- return builder.build();
626
- }
627
- public void moveToCamera(ReadableMap cameraMap) {
628
- CameraPosition camera = cameraPositionFromMap(cameraMap);
629
- if (camera == null) return;
630
- CameraUpdate update = CameraUpdateFactory.newCameraPosition(camera);
631
-
632
- if (super.getHeight() <= 0 || super.getWidth() <= 0) {
633
- // in this case, our map has not been laid out yet, so we save the camera update in a
634
- // local variable. As soon as layout occurs, we will move the camera to the saved update.
635
- // Note that if we tried to move to the camera now, it would trigger an exception.
636
- cameraToSet = update;
637
- } else {
638
- map.moveCamera(update);
639
- cameraToSet = null;
640
- }
641
- }
642
-
643
- public void setMapStyle(@Nullable String customMapStyleString) {
644
- this.customMapStyleString = customMapStyleString;
645
- if(map != null && customMapStyleString != null) {
646
- map.setMapStyle(new MapStyleOptions(customMapStyleString));
647
- }
648
- }
649
-
650
- public void setShowsUserLocation(boolean showUserLocation) {
651
- this.showUserLocation = showUserLocation; // hold onto this for lifecycle handling
652
- if (hasPermissions()) {
653
- map.setLocationSource(fusedLocationSource);
654
- //noinspection MissingPermission
655
- map.setMyLocationEnabled(showUserLocation);
656
- }
657
- }
658
-
659
- public void setUserLocationPriority(int priority){
660
- fusedLocationSource.setPriority(priority);
661
- }
662
-
663
- public void setUserLocationUpdateInterval(int interval){
664
- fusedLocationSource.setInterval(interval);
665
- }
666
-
667
- public void setUserLocationFastestInterval(int interval){
668
- fusedLocationSource.setFastestInterval(interval);
669
- }
670
-
671
- public void setShowsMyLocationButton(boolean showMyLocationButton) {
672
- if (hasPermissions() || !showMyLocationButton) {
673
- map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
674
- }
675
- }
676
-
677
- public void setToolbarEnabled(boolean toolbarEnabled) {
678
- if (hasPermissions() || !toolbarEnabled) {
679
- map.getUiSettings().setMapToolbarEnabled(toolbarEnabled);
680
- }
681
- }
682
-
683
- public void setCacheEnabled(boolean cacheEnabled) {
684
- this.cacheEnabled = cacheEnabled;
685
- this.cacheView();
686
- }
687
-
688
- public void setPoiClickEnabled(boolean poiClickEnabled) {
689
- this.poiClickEnabled = poiClickEnabled;
690
- map.setOnPoiClickListener(poiClickEnabled ? this : null);
691
- }
692
-
693
- public void enableMapLoading(boolean loadingEnabled) {
694
- if (loadingEnabled && !this.isMapLoaded) {
695
- this.getMapLoadingLayoutView().setVisibility(View.VISIBLE);
696
- }
697
- }
698
-
699
- public void setMoveOnMarkerPress(boolean moveOnPress) {
700
- this.moveOnMarkerPress = moveOnPress;
701
- }
702
-
703
- public void setLoadingBackgroundColor(Integer loadingBackgroundColor) {
704
- this.loadingBackgroundColor = loadingBackgroundColor;
705
-
706
- if (this.mapLoadingLayout != null) {
707
- if (loadingBackgroundColor == null) {
708
- this.mapLoadingLayout.setBackgroundColor(Color.WHITE);
709
- } else {
710
- this.mapLoadingLayout.setBackgroundColor(this.loadingBackgroundColor);
711
- }
712
- }
713
- }
714
-
715
- public void setLoadingIndicatorColor(Integer loadingIndicatorColor) {
716
- this.loadingIndicatorColor = loadingIndicatorColor;
717
- if (this.mapLoadingProgressBar != null) {
718
- Integer color = loadingIndicatorColor;
719
- if (color == null) {
720
- color = Color.parseColor("#606060");
721
- }
722
-
723
- ColorStateList progressTintList = ColorStateList.valueOf(loadingIndicatorColor);
724
- ColorStateList secondaryProgressTintList = ColorStateList.valueOf(loadingIndicatorColor);
725
- ColorStateList indeterminateTintList = ColorStateList.valueOf(loadingIndicatorColor);
726
-
727
- this.mapLoadingProgressBar.setProgressTintList(progressTintList);
728
- this.mapLoadingProgressBar.setSecondaryProgressTintList(secondaryProgressTintList);
729
- this.mapLoadingProgressBar.setIndeterminateTintList(indeterminateTintList);
730
- }
731
- }
732
-
733
- public void setHandlePanDrag(boolean handlePanDrag) {
734
- this.handlePanDrag = handlePanDrag;
735
- }
736
-
737
- public void addFeature(View child, int index) {
738
- // Our desired API is to pass up annotations/overlays as children to the mapview component.
739
- // This is where we intercept them and do the appropriate underlying mapview action.
740
- if (child instanceof MapMarker) {
741
- MapMarker annotation = (MapMarker) child;
742
- annotation.addToMap(markerCollection);
743
- features.add(index, annotation);
744
-
745
- // Allow visibility event to be triggered later
746
- int visibility = annotation.getVisibility();
747
- annotation.setVisibility(INVISIBLE);
748
-
749
- // Remove from a view group if already present, prevent "specified child
750
- // already had a parent" error.
751
- ViewGroup annotationParent = (ViewGroup)annotation.getParent();
752
- if (annotationParent != null) {
753
- annotationParent.removeView(annotation);
754
- }
755
-
756
- // Add to the parent group
757
- attacherGroup.addView(annotation);
758
-
759
- // Trigger visibility event if necessary.
760
- // With some testing, seems like it is not always
761
- // triggered just by being added to a parent view.
762
- annotation.setVisibility(visibility);
763
-
764
- Marker marker = (Marker) annotation.getFeature();
765
- markerMap.put(marker, annotation);
766
- } else if (child instanceof MapPolyline) {
767
- MapPolyline polylineView = (MapPolyline) child;
768
- polylineView.addToMap(polylineCollection);
769
- features.add(index, polylineView);
770
- Polyline polyline = (Polyline) polylineView.getFeature();
771
- polylineMap.put(polyline, polylineView);
772
- } else if (child instanceof MapGradientPolyline) {
773
- MapGradientPolyline polylineView = (MapGradientPolyline) child;
774
- polylineView.addToMap(map);
775
- features.add(index, polylineView);
776
- TileOverlay tileOverlay = (TileOverlay) polylineView.getFeature();
777
- gradientPolylineMap.put(tileOverlay, polylineView);
778
- } else if (child instanceof MapPolygon) {
779
- MapPolygon polygonView = (MapPolygon) child;
780
- polygonView.addToMap(polygonCollection);
781
- features.add(index, polygonView);
782
- Polygon polygon = (Polygon) polygonView.getFeature();
783
- polygonMap.put(polygon, polygonView);
784
- } else if (child instanceof MapCircle) {
785
- MapCircle circleView = (MapCircle) child;
786
- circleView.addToMap(circleCollection);
787
- features.add(index, circleView);
788
- } else if (child instanceof MapUrlTile) {
789
- MapUrlTile urlTileView = (MapUrlTile) child;
790
- urlTileView.addToMap(map);
791
- features.add(index, urlTileView);
792
- } else if (child instanceof MapWMSTile) {
793
- MapWMSTile urlTileView = (MapWMSTile) child;
794
- urlTileView.addToMap(map);
795
- features.add(index, urlTileView);
796
- } else if (child instanceof MapLocalTile) {
797
- MapLocalTile localTileView = (MapLocalTile) child;
798
- localTileView.addToMap(map);
799
- features.add(index, localTileView);
800
- } else if (child instanceof MapOverlay) {
801
- MapOverlay overlayView = (MapOverlay) child;
802
- overlayView.addToMap(groundOverlayCollection);
803
- features.add(index, overlayView);
804
- GroundOverlay overlay = (GroundOverlay) overlayView.getFeature();
805
- overlayMap.put(overlay, overlayView);
806
- } else if (child instanceof MapHeatmap) {
807
- MapHeatmap heatmapView = (MapHeatmap) child;
808
- heatmapView.addToMap(map);
809
- features.add(index, heatmapView);
810
- TileOverlay heatmap = (TileOverlay)heatmapView.getFeature();
811
- heatmapMap.put(heatmap, heatmapView);
812
- } else if (child instanceof ViewGroup) {
813
- ViewGroup children = (ViewGroup) child;
814
- for (int i = 0; i < children.getChildCount(); i++) {
815
- addFeature(children.getChildAt(i), index);
816
- }
817
- } else {
818
- addView(child, index);
819
- }
820
- }
821
-
822
- public int getFeatureCount() {
823
- return features.size();
824
- }
825
-
826
- public View getFeatureAt(int index) {
827
- return features.get(index);
828
- }
829
-
830
- public void removeFeatureAt(int index) {
831
- MapFeature feature = features.remove(index);
832
- if (feature instanceof MapMarker) {
833
- markerMap.remove(feature.getFeature());
834
- feature.removeFromMap(markerCollection);
835
- attacherGroup.removeView(feature);
836
- } else if (feature instanceof MapHeatmap) {
837
- heatmapMap.remove(feature.getFeature());
838
- feature.removeFromMap(map);
839
- } else if(feature instanceof MapCircle) {
840
- feature.removeFromMap(circleCollection);
841
- } else if(feature instanceof MapOverlay) {
842
- feature.removeFromMap(groundOverlayCollection);
843
- } else if(feature instanceof MapPolygon) {
844
- feature.removeFromMap(polygonCollection);
845
- } else if(feature instanceof MapPolyline) {
846
- feature.removeFromMap(polylineCollection);
847
- } else {
848
- feature.removeFromMap(map);
849
- }
850
- }
851
-
852
- public WritableMap makeClickEventData(LatLng point) {
853
- WritableMap event = new WritableNativeMap();
854
-
855
- WritableMap coordinate = new WritableNativeMap();
856
- coordinate.putDouble("latitude", point.latitude);
857
- coordinate.putDouble("longitude", point.longitude);
858
- event.putMap("coordinate", coordinate);
859
-
860
- Projection projection = map.getProjection();
861
- Point screenPoint = projection.toScreenLocation(point);
862
-
863
- WritableMap position = new WritableNativeMap();
864
- position.putDouble("x", screenPoint.x);
865
- position.putDouble("y", screenPoint.y);
866
- event.putMap("position", position);
867
-
868
- return event;
869
- }
870
-
871
- public void updateExtraData(Object extraData) {
872
- if (setPaddingDeferred && super.getHeight() > 0 && super.getWidth() > 0) {
873
- CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
874
-
875
- map.setPadding(edgeLeftPadding + baseLeftMapPadding,
876
- edgeTopPadding + baseTopMapPadding,
877
- edgeRightPadding + baseRightMapPadding,
878
- edgeBottomPadding + baseBottomMapPadding);
879
- map.moveCamera(cu);
880
-
881
- // Move the google logo to the default base padding value.
882
- map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
883
-
884
- setPaddingDeferred = false;
885
- }
886
-
887
- // if boundsToMove is not null, we now have the MapView's width/height, so we can apply
888
- // a proper camera move
889
- if (boundsToMove != null) {
890
- HashMap<String, Float> data = (HashMap<String, Float>) extraData;
891
- int width = data.get("width") == null ? 0 : data.get("width").intValue();
892
- int height = data.get("height") == null ? 0 : data.get("height").intValue();
893
-
894
- //fix for https://github.com/react-native-maps/react-native-maps/issues/245,
895
- //it's not guaranteed the passed-in height and width would be greater than 0.
896
- if (width <= 0 || height <= 0) {
897
- map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsToMove, 0));
898
- } else {
899
- map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsToMove, width, height, 0));
900
- }
901
-
902
- boundsToMove = null;
903
- cameraToSet = null;
904
- }
905
- else if (cameraToSet != null) {
906
- map.moveCamera(cameraToSet);
907
- cameraToSet = null;
908
- }
909
- }
910
-
911
- public void animateToCamera(ReadableMap camera, int duration) {
912
- if (map == null) return;
913
- CameraPosition.Builder builder = new CameraPosition.Builder(map.getCameraPosition());
914
- if (camera.hasKey("zoom")) {
915
- builder.zoom((float)camera.getDouble("zoom"));
916
- }
917
- if (camera.hasKey("heading")) {
918
- builder.bearing((float)camera.getDouble("heading"));
909
+ public void setCacheEnabled(boolean cacheEnabled) {
910
+ this.cacheEnabled = cacheEnabled;
911
+ this.cacheView();
912
+ }
913
+
914
+ public void setPoiClickEnabled(boolean poiClickEnabled) {
915
+ this.poiClickEnabled = poiClickEnabled;
916
+ if (map != null) {
917
+ map.setOnPoiClickListener(poiClickEnabled ? this : null);
918
+ }
919
+ }
920
+
921
+ public void setLoadingEnabled(boolean loadingEnabled) {
922
+ if (loadingEnabled && !this.isMapLoaded) {
923
+ this.getMapLoadingLayoutView().setVisibility(View.VISIBLE);
924
+ }
925
+ }
926
+
927
+ public void setMoveOnMarkerPress(boolean moveOnPress) {
928
+ this.moveOnMarkerPress = moveOnPress;
919
929
  }
920
- if (camera.hasKey("pitch")) {
921
- builder.tilt((float)camera.getDouble("pitch"));
922
- }
923
- if (camera.hasKey("center")) {
924
- ReadableMap center = camera.getMap("center");
925
- builder.target(new LatLng(center.getDouble("latitude"), center.getDouble("longitude")));
926
- }
927
-
928
- CameraUpdate update = CameraUpdateFactory.newCameraPosition(builder.build());
929
-
930
- if (duration <= 0) {
931
- map.moveCamera(update);
932
- }
933
- else {
934
- map.animateCamera(update, duration, null);
930
+
931
+ public void setMaxZoomLevel(float maxZoomLevel) {
932
+ this.maxZoomLevel = maxZoomLevel;
933
+ if (map != null) {
934
+ map.setMaxZoomPreference(maxZoomLevel);
935
+ }
935
936
  }
936
- }
937
937
 
938
- public void animateToRegion(LatLngBounds bounds, int duration) {
939
- if (map == null) return;
940
- if(duration <= 0) {
941
- map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
942
- } else {
943
- map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), duration, null);
938
+ public void setMinZoomLevel(float minZoomLevel) {
939
+ this.minZoomLevel = minZoomLevel;
940
+ if (map != null) {
941
+ map.setMinZoomPreference(minZoomLevel);
942
+ }
944
943
  }
945
- }
946
944
 
947
- public void fitToElements(ReadableMap edgePadding, boolean animated) {
948
- if (map == null) return;
945
+ public void setPitchEnabled(boolean pitchEnabled) {
946
+ this.pitchEnabled = pitchEnabled;
947
+ if (map != null) {
948
+ map.getUiSettings().setTiltGesturesEnabled(pitchEnabled);
949
+ }
950
+ }
949
951
 
950
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
952
+ public void setShowsCompass(boolean showsCompass) {
953
+ this.showsCompass = showsCompass;
954
+ if (map != null) {
955
+ map.getUiSettings().setCompassEnabled(showsCompass);
956
+ }
957
+ }
951
958
 
952
- boolean addedPosition = false;
959
+ public void setRotateEnabled(boolean rotateEnabled) {
960
+ this.rotateEnabled = rotateEnabled;
961
+ if (map != null) {
962
+ map.getUiSettings().setRotateGesturesEnabled(rotateEnabled);
963
+ }
964
+ }
953
965
 
954
- for (MapFeature feature : features) {
955
- if (feature instanceof MapMarker) {
956
- Marker marker = (Marker) feature.getFeature();
957
- builder.include(marker.getPosition());
958
- addedPosition = true;
959
- }
960
- // TODO(lmr): may want to include shapes / etc.
966
+ public void setZoomEnabled(boolean zoomEnabled) {
967
+ this.zoomEnabled = zoomEnabled;
968
+ if (map != null) {
969
+ map.getUiSettings().setZoomGesturesEnabled(zoomEnabled);
970
+ }
961
971
  }
962
- if (addedPosition) {
963
- LatLngBounds bounds = builder.build();
964
- CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
965
972
 
966
- if (edgePadding != null) {
967
- appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
968
- edgePadding.getInt("right"), edgePadding.getInt("bottom"));
969
- }
973
+ public void setZoomControlEnabled(boolean zoomControlEnabled) {
974
+ this.zoomControlEnabled = zoomControlEnabled;
975
+ if (map != null) {
976
+ map.getUiSettings().setZoomControlsEnabled(zoomControlEnabled);
977
+ }
978
+ }
970
979
 
971
- if (animated) {
972
- map.animateCamera(cu);
973
- } else {
974
- map.moveCamera(cu);
975
- }
976
- // Move the google logo to the default base padding value.
977
- map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
980
+ public void setScrollDuringRotateOrZoomEnabled(boolean scrollDuringRotateOrZoomEnabled) {
981
+ this.scrollDuringRotateOrZoomEnabled = scrollDuringRotateOrZoomEnabled;
982
+ if (map != null) {
983
+ map.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(scrollDuringRotateOrZoomEnabled);
984
+ }
985
+ }
986
+
987
+ public void setScrollEnabled(boolean scrollEnabled) {
988
+ this.scrollEnabled = scrollEnabled;
989
+ if (map != null) {
990
+ map.getUiSettings().setScrollGesturesEnabled(scrollEnabled);
991
+ }
978
992
  }
979
- }
980
993
 
981
- public void fitToSuppliedMarkers(ReadableArray markerIDsArray, ReadableMap edgePadding, boolean animated) {
982
- if (map == null) return;
994
+ public void setShowIndoors(boolean showIndoors) {
995
+ this.showIndoors = showIndoors;
996
+ if (map != null) {
997
+ map.setIndoorEnabled(showIndoors);
998
+ }
999
+ }
983
1000
 
984
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
1001
+ public void setShowsIndoorLevelPicker(boolean showsIndoorLevelPicker) {
1002
+ this.showsIndoorLevelPicker = showsIndoorLevelPicker;
1003
+ if (map != null) {
1004
+ map.getUiSettings().setIndoorLevelPickerEnabled(showsIndoorLevelPicker);
1005
+ }
1006
+ }
985
1007
 
986
- String[] markerIDs = new String[markerIDsArray.size()];
987
- for (int i = 0; i < markerIDsArray.size(); i++) {
988
- markerIDs[i] = markerIDsArray.getString(i);
1008
+ public void setShowBuildings(boolean showBuildings) {
1009
+ this.setShowBuildings = showBuildings;
1010
+ if (map != null) {
1011
+ map.setBuildingsEnabled(showBuildings);
1012
+ }
989
1013
  }
990
1014
 
991
- boolean addedPosition = false;
992
1015
 
993
- List<String> markerIDList = Arrays.asList(markerIDs);
1016
+ public void setLoadingBackgroundColor(Integer loadingBackgroundColor) {
1017
+ this.loadingBackgroundColor = loadingBackgroundColor;
994
1018
 
995
- for (MapFeature feature : features) {
996
- if (feature instanceof MapMarker) {
997
- String identifier = ((MapMarker) feature).getIdentifier();
998
- Marker marker = (Marker) feature.getFeature();
999
- if (markerIDList.contains(identifier)) {
1000
- builder.include(marker.getPosition());
1001
- addedPosition = true;
1019
+ if (this.mapLoadingLayout != null) {
1020
+ if (loadingBackgroundColor == null) {
1021
+ this.mapLoadingLayout.setBackgroundColor(Color.WHITE);
1022
+ } else {
1023
+ this.mapLoadingLayout.setBackgroundColor(this.loadingBackgroundColor);
1024
+ }
1002
1025
  }
1003
- }
1004
1026
  }
1005
1027
 
1006
- if (addedPosition) {
1007
- LatLngBounds bounds = builder.build();
1008
- CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
1028
+ public void setLoadingIndicatorColor(Integer loadingIndicatorColor) {
1029
+ this.loadingIndicatorColor = loadingIndicatorColor;
1030
+ if (this.mapLoadingProgressBar != null) {
1031
+ Integer color = loadingIndicatorColor;
1032
+ if (color == null) {
1033
+ color = Color.parseColor("#606060");
1034
+ }
1035
+
1036
+ ColorStateList progressTintList = ColorStateList.valueOf(loadingIndicatorColor);
1037
+ ColorStateList secondaryProgressTintList = ColorStateList.valueOf(loadingIndicatorColor);
1038
+ ColorStateList indeterminateTintList = ColorStateList.valueOf(loadingIndicatorColor);
1009
1039
 
1010
- if (edgePadding != null) {
1011
- appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
1012
- edgePadding.getInt("right"), edgePadding.getInt("bottom"));
1013
- }
1040
+ this.mapLoadingProgressBar.setProgressTintList(progressTintList);
1041
+ this.mapLoadingProgressBar.setSecondaryProgressTintList(secondaryProgressTintList);
1042
+ this.mapLoadingProgressBar.setIndeterminateTintList(indeterminateTintList);
1043
+ }
1044
+ }
1014
1045
 
1015
- if (animated) {
1016
- map.animateCamera(cu);
1017
- } else {
1046
+ public void setHandlePanDrag(boolean handlePanDrag) {
1047
+ this.handlePanDrag = handlePanDrag;
1048
+ }
1049
+
1050
+ public void addFeature(View child, int index) {
1051
+ // Our desired API is to pass up annotations/overlays as children to the mapview component.
1052
+ // This is where we intercept them and do the appropriate underlying mapview action.
1053
+ if (child instanceof MapMarker) {
1054
+ MapMarker annotation = (MapMarker) child;
1055
+ annotation.addToMap(markerCollection);
1056
+ features.add(index, annotation);
1057
+
1058
+ // Allow visibility event to be triggered later
1059
+ int visibility = annotation.getVisibility();
1060
+ annotation.setVisibility(INVISIBLE);
1061
+
1062
+ // Remove from a view group if already present, prevent "specified child
1063
+ // already had a parent" error.
1064
+ ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1065
+ if (annotationParent != null) {
1066
+ annotationParent.removeView(annotation);
1067
+ }
1068
+
1069
+ // Add to the parent group
1070
+ attacherGroup.addView(annotation);
1071
+
1072
+ // Trigger visibility event if necessary.
1073
+ // With some testing, seems like it is not always
1074
+ // triggered just by being added to a parent view.
1075
+ annotation.setVisibility(visibility);
1076
+
1077
+ Marker marker = (Marker) annotation.getFeature();
1078
+ markerMap.put(marker, annotation);
1079
+ } else if (child instanceof MapPolyline) {
1080
+ MapPolyline polylineView = (MapPolyline) child;
1081
+ polylineView.addToMap(polylineCollection);
1082
+ features.add(index, polylineView);
1083
+ Polyline polyline = (Polyline) polylineView.getFeature();
1084
+ polylineMap.put(polyline, polylineView);
1085
+ } else if (child instanceof MapGradientPolyline) {
1086
+ MapGradientPolyline polylineView = (MapGradientPolyline) child;
1087
+ polylineView.addToMap(map);
1088
+ features.add(index, polylineView);
1089
+ TileOverlay tileOverlay = (TileOverlay) polylineView.getFeature();
1090
+ gradientPolylineMap.put(tileOverlay, polylineView);
1091
+ } else if (child instanceof MapPolygon) {
1092
+ MapPolygon polygonView = (MapPolygon) child;
1093
+ polygonView.addToMap(polygonCollection);
1094
+ features.add(index, polygonView);
1095
+ Polygon polygon = (Polygon) polygonView.getFeature();
1096
+ polygonMap.put(polygon, polygonView);
1097
+ } else if (child instanceof MapCircle) {
1098
+ MapCircle circleView = (MapCircle) child;
1099
+ circleView.addToMap(circleCollection);
1100
+ features.add(index, circleView);
1101
+ } else if (child instanceof MapUrlTile) {
1102
+ MapUrlTile urlTileView = (MapUrlTile) child;
1103
+ urlTileView.addToMap(map);
1104
+ features.add(index, urlTileView);
1105
+ } else if (child instanceof MapWMSTile) {
1106
+ MapWMSTile urlTileView = (MapWMSTile) child;
1107
+ urlTileView.addToMap(map);
1108
+ features.add(index, urlTileView);
1109
+ } else if (child instanceof MapLocalTile) {
1110
+ MapLocalTile localTileView = (MapLocalTile) child;
1111
+ localTileView.addToMap(map);
1112
+ features.add(index, localTileView);
1113
+ } else if (child instanceof MapOverlay) {
1114
+ MapOverlay overlayView = (MapOverlay) child;
1115
+ overlayView.addToMap(groundOverlayCollection);
1116
+ features.add(index, overlayView);
1117
+ GroundOverlay overlay = (GroundOverlay) overlayView.getFeature();
1118
+ overlayMap.put(overlay, overlayView);
1119
+ } else if (child instanceof MapHeatmap) {
1120
+ MapHeatmap heatmapView = (MapHeatmap) child;
1121
+ heatmapView.addToMap(map);
1122
+ features.add(index, heatmapView);
1123
+ TileOverlay heatmap = (TileOverlay) heatmapView.getFeature();
1124
+ heatmapMap.put(heatmap, heatmapView);
1125
+ } else if (child instanceof ViewGroup) {
1126
+ ViewGroup children = (ViewGroup) child;
1127
+ for (int i = 0; i < children.getChildCount(); i++) {
1128
+ addFeature(children.getChildAt(i), index);
1129
+ }
1130
+ } else {
1131
+ addView(child, index);
1132
+ }
1133
+ }
1134
+
1135
+ public int getFeatureCount() {
1136
+ return features.size();
1137
+ }
1138
+
1139
+ public View getFeatureAt(int index) {
1140
+ return features.get(index);
1141
+ }
1142
+
1143
+ public void removeFeatureAt(int index) {
1144
+ MapFeature feature = features.remove(index);
1145
+ if (feature instanceof MapMarker) {
1146
+ markerMap.remove(feature.getFeature());
1147
+ feature.removeFromMap(markerCollection);
1148
+ attacherGroup.removeView(feature);
1149
+ } else if (feature instanceof MapHeatmap) {
1150
+ heatmapMap.remove(feature.getFeature());
1151
+ feature.removeFromMap(map);
1152
+ } else if (feature instanceof MapCircle) {
1153
+ feature.removeFromMap(circleCollection);
1154
+ } else if (feature instanceof MapOverlay) {
1155
+ feature.removeFromMap(groundOverlayCollection);
1156
+ } else if (feature instanceof MapPolygon) {
1157
+ feature.removeFromMap(polygonCollection);
1158
+ } else if (feature instanceof MapPolyline) {
1159
+ feature.removeFromMap(polylineCollection);
1160
+ } else {
1161
+ feature.removeFromMap(map);
1162
+ }
1163
+ }
1164
+
1165
+ public WritableMap makeClickEventData(LatLng point) {
1166
+ WritableMap event = new WritableNativeMap();
1167
+
1168
+ WritableMap coordinate = new WritableNativeMap();
1169
+ coordinate.putDouble("latitude", point.latitude);
1170
+ coordinate.putDouble("longitude", point.longitude);
1171
+ event.putMap("coordinate", coordinate);
1172
+
1173
+ Projection projection = map.getProjection();
1174
+ Point screenPoint = projection.toScreenLocation(point);
1175
+
1176
+ WritableMap position = new WritableNativeMap();
1177
+ position.putDouble("x", screenPoint.x);
1178
+ position.putDouble("y", screenPoint.y);
1179
+ event.putMap("position", position);
1180
+
1181
+ return event;
1182
+ }
1183
+
1184
+ public void updateExtraData(Object extraData) {
1185
+ if (setPaddingDeferred && super.getHeight() > 0 && super.getWidth() > 0) {
1186
+ CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
1187
+
1188
+ map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1189
+ edgeTopPadding + baseTopMapPadding,
1190
+ edgeRightPadding + baseRightMapPadding,
1191
+ edgeBottomPadding + baseBottomMapPadding);
1192
+ map.moveCamera(cu);
1193
+
1194
+ // Move the google logo to the default base padding value.
1195
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
1196
+
1197
+ setPaddingDeferred = false;
1198
+ }
1199
+
1200
+ // if boundsToMove is not null, we now have the MapView's width/height, so we can apply
1201
+ // a proper camera move
1202
+ if (boundsToMove != null) {
1203
+ HashMap<String, Float> data = (HashMap<String, Float>) extraData;
1204
+ int width = data.get("width") == null ? 0 : data.get("width").intValue();
1205
+ int height = data.get("height") == null ? 0 : data.get("height").intValue();
1206
+
1207
+ //fix for https://github.com/react-native-maps/react-native-maps/issues/245,
1208
+ //it's not guaranteed the passed-in height and width would be greater than 0.
1209
+ if (width <= 0 || height <= 0) {
1210
+ map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsToMove, 0));
1211
+ } else {
1212
+ map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsToMove, width, height, 0));
1213
+ }
1214
+
1215
+ boundsToMove = null;
1216
+ cameraToSet = null;
1217
+ } else if (cameraToSet != null) {
1218
+ map.moveCamera(cameraToSet);
1219
+ cameraToSet = null;
1220
+ }
1221
+ }
1222
+ public void animateToCamera(CameraPosition position, int duration) {
1223
+ if (map == null) return;
1224
+ CameraUpdate update = CameraUpdateFactory.newCameraPosition(position);
1225
+ if (duration <= 0) {
1226
+ map.moveCamera(update);
1227
+ } else {
1228
+ map.animateCamera(update, duration, null);
1229
+ }
1230
+ }
1231
+
1232
+ public void animateToCamera(ReadableMap camera, int duration) {
1233
+ if (map == null) return;
1234
+ CameraPosition.Builder builder = new CameraPosition.Builder(map.getCameraPosition());
1235
+ if (camera.hasKey("zoom")) {
1236
+ builder.zoom((float) camera.getDouble("zoom"));
1237
+ }
1238
+ if (camera.hasKey("heading")) {
1239
+ builder.bearing((float) camera.getDouble("heading"));
1240
+ }
1241
+ if (camera.hasKey("pitch")) {
1242
+ builder.tilt((float) camera.getDouble("pitch"));
1243
+ }
1244
+ if (camera.hasKey("center")) {
1245
+ ReadableMap center = camera.getMap("center");
1246
+ builder.target(new LatLng(center.getDouble("latitude"), center.getDouble("longitude")));
1247
+ }
1248
+ animateToCamera(builder.build(), duration);
1249
+ }
1250
+
1251
+ public void animateToRegion(LatLngBounds bounds, int duration) {
1252
+ if (map == null) return;
1253
+ if (duration <= 0) {
1254
+ map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
1255
+ } else {
1256
+ map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), duration, null);
1257
+ }
1258
+ }
1259
+
1260
+ public void fitToElements(ReadableMap edgePadding, boolean animated) {
1261
+ if (map == null) return;
1262
+
1263
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
1264
+
1265
+ boolean addedPosition = false;
1266
+ if (features.size() > 0) {
1267
+ for (MapFeature feature : features) {
1268
+ if (feature instanceof MapMarker) {
1269
+ Marker marker = (Marker) feature.getFeature();
1270
+ builder.include(marker.getPosition());
1271
+ addedPosition = true;
1272
+ }
1273
+ // TODO(lmr): may want to include shapes / etc.
1274
+ }
1275
+ }
1276
+ if (addedPosition) {
1277
+ LatLngBounds bounds = builder.build();
1278
+ CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
1279
+
1280
+ if (edgePadding != null) {
1281
+ appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
1282
+ edgePadding.getInt("right"), edgePadding.getInt("bottom"));
1283
+ }
1284
+
1285
+ if (animated) {
1286
+ map.animateCamera(cu);
1287
+ } else {
1288
+ map.moveCamera(cu);
1289
+ }
1290
+ // Move the google logo to the default base padding value.
1291
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
1292
+ }
1293
+ }
1294
+
1295
+ public void fitToSuppliedMarkers(ReadableArray markerIDsArray, ReadableMap edgePadding, boolean animated) {
1296
+ if (map == null) return;
1297
+
1298
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
1299
+
1300
+ String[] markerIDs = new String[markerIDsArray.size()];
1301
+ for (int i = 0; i < markerIDsArray.size(); i++) {
1302
+ markerIDs[i] = markerIDsArray.getString(i);
1303
+ }
1304
+
1305
+ boolean addedPosition = false;
1306
+
1307
+ List<String> markerIDList = Arrays.asList(markerIDs);
1308
+
1309
+ for (MapFeature feature : features) {
1310
+ if (feature instanceof MapMarker) {
1311
+ String identifier = ((MapMarker) feature).getIdentifier();
1312
+ Marker marker = (Marker) feature.getFeature();
1313
+ if (markerIDList.contains(identifier)) {
1314
+ builder.include(marker.getPosition());
1315
+ addedPosition = true;
1316
+ }
1317
+ }
1318
+ }
1319
+
1320
+ if (addedPosition) {
1321
+ LatLngBounds bounds = builder.build();
1322
+ CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
1323
+
1324
+ if (edgePadding != null) {
1325
+ appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
1326
+ edgePadding.getInt("right"), edgePadding.getInt("bottom"));
1327
+ }
1328
+
1329
+ if (animated) {
1330
+ map.animateCamera(cu);
1331
+ } else {
1332
+ map.moveCamera(cu);
1333
+ }
1334
+ // Move the google logo to the default base padding value.
1335
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
1336
+ }
1337
+ }
1338
+
1339
+ // padding configured by 'mapPadding' property
1340
+ int baseLeftMapPadding;
1341
+ int baseRightMapPadding;
1342
+ int baseTopMapPadding;
1343
+ int baseBottomMapPadding;
1344
+ // extra padding specified by 'edgePadding' option of fitToElements/fitToSuppliedMarkers/fitToCoordinates
1345
+ int edgeLeftPadding;
1346
+ int edgeRightPadding;
1347
+ int edgeTopPadding;
1348
+ int edgeBottomPadding;
1349
+
1350
+ public void applyBaseMapPadding(int left, int top, int right, int bottom) {
1351
+ if (super.getHeight() <= 0 || super.getWidth() <= 0) {
1352
+ // the map is not laid out yet and calling setPadding() now has no effect
1353
+ baseLeftMapPadding = left;
1354
+ baseRightMapPadding = right;
1355
+ baseTopMapPadding = top;
1356
+ baseBottomMapPadding = bottom;
1357
+ setPaddingDeferred = true;
1358
+ return;
1359
+ }
1360
+
1361
+ // retrieve current camera with current edge paddings configured
1362
+ map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1363
+ edgeTopPadding + baseTopMapPadding,
1364
+ edgeRightPadding + baseRightMapPadding,
1365
+ edgeBottomPadding + baseBottomMapPadding);
1366
+ CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
1367
+
1368
+ baseLeftMapPadding = left;
1369
+ baseRightMapPadding = right;
1370
+ baseTopMapPadding = top;
1371
+ baseBottomMapPadding = bottom;
1372
+
1373
+ // apply base paddings and restore center position of the map
1374
+ map.setPadding(edgeLeftPadding + left,
1375
+ edgeTopPadding + top,
1376
+ edgeRightPadding + right,
1377
+ edgeBottomPadding + bottom);
1018
1378
  map.moveCamera(cu);
1019
- }
1020
- // Move the google logo to the default base padding value.
1021
- map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
1022
- }
1023
- }
1024
-
1025
- // padding configured by 'mapPadding' property
1026
- int baseLeftMapPadding;
1027
- int baseRightMapPadding;
1028
- int baseTopMapPadding;
1029
- int baseBottomMapPadding;
1030
- // extra padding specified by 'edgePadding' option of fitToElements/fitToSuppliedMarkers/fitToCoordinates
1031
- int edgeLeftPadding;
1032
- int edgeRightPadding;
1033
- int edgeTopPadding;
1034
- int edgeBottomPadding;
1035
-
1036
- public void applyBaseMapPadding(int left, int top, int right, int bottom){
1037
- if (super.getHeight() <= 0 || super.getWidth() <= 0) {
1038
- // the map is not laid out yet and calling setPadding() now has no effect
1039
- baseLeftMapPadding = left;
1040
- baseRightMapPadding = right;
1041
- baseTopMapPadding = top;
1042
- baseBottomMapPadding = bottom;
1043
- setPaddingDeferred = true;
1044
- return;
1045
- }
1046
-
1047
- // retrieve current camera with current edge paddings configured
1048
- map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1049
- edgeTopPadding + baseTopMapPadding,
1050
- edgeRightPadding + baseRightMapPadding,
1051
- edgeBottomPadding + baseBottomMapPadding);
1052
- CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
1053
-
1054
- baseLeftMapPadding = left;
1055
- baseRightMapPadding = right;
1056
- baseTopMapPadding = top;
1057
- baseBottomMapPadding = bottom;
1058
-
1059
- // apply base paddings and restore center position of the map
1060
- map.setPadding(edgeLeftPadding + left,
1061
- edgeTopPadding + top,
1062
- edgeRightPadding + right,
1063
- edgeBottomPadding + bottom);
1064
- map.moveCamera(cu);
1065
-
1066
- // Move the google logo to the default base padding value.
1067
- map.setPadding(left, top, right, bottom);
1068
- }
1069
-
1070
- public void fitToCoordinates(ReadableArray coordinatesArray, ReadableMap edgePadding,
1071
- boolean animated) {
1072
- if (map == null) return;
1073
-
1074
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
1075
-
1076
- for (int i = 0; i < coordinatesArray.size(); i++) {
1077
- ReadableMap latLng = coordinatesArray.getMap(i);
1078
- double lat = latLng.getDouble("latitude");
1079
- double lng = latLng.getDouble("longitude");
1080
- builder.include(new LatLng(lat, lng));
1081
- }
1082
-
1083
- LatLngBounds bounds = builder.build();
1084
- CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
1085
-
1086
- if (edgePadding != null) {
1087
- appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"), edgePadding.getInt("right"), edgePadding.getInt("bottom"));
1088
- }
1089
-
1090
- if (animated) {
1091
- map.animateCamera(cu);
1092
- } else {
1093
- map.moveCamera(cu);
1094
- }
1095
- // Move the google logo to the default base padding value.
1096
- map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
1097
- }
1098
-
1099
- private void appendMapPadding(int iLeft,int iTop, int iRight, int iBottom) {
1100
- double density = getResources().getDisplayMetrics().density;
1101
-
1102
- edgeLeftPadding = (int) (iLeft * density);
1103
- edgeTopPadding = (int) (iTop * density);
1104
- edgeRightPadding = (int) (iRight * density);
1105
- edgeBottomPadding = (int) (iBottom * density);
1106
-
1107
- map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1108
- edgeTopPadding + baseTopMapPadding,
1109
- edgeRightPadding + baseRightMapPadding,
1110
- edgeBottomPadding + baseBottomMapPadding);
1111
- }
1112
-
1113
- public double[][] getMapBoundaries() {
1114
- LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
1115
- LatLng northEast = bounds.northeast;
1116
- LatLng southWest = bounds.southwest;
1117
-
1118
- return new double[][] {
1119
- {northEast.longitude, northEast.latitude},
1120
- {southWest.longitude, southWest.latitude}
1121
- };
1122
- }
1123
1379
 
1124
- public void setMapBoundaries(ReadableMap northEast, ReadableMap southWest) {
1125
- if (map == null) return;
1380
+ // Move the google logo to the default base padding value.
1381
+ map.setPadding(left, top, right, bottom);
1382
+ }
1126
1383
 
1127
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
1384
+ public void fitToCoordinates(ReadableArray coordinatesArray, ReadableMap edgePadding,
1385
+ boolean animated) {
1386
+ if (map == null) return;
1128
1387
 
1129
- double latNE = northEast.getDouble("latitude");
1130
- double lngNE = northEast.getDouble("longitude");
1131
- builder.include(new LatLng(latNE, lngNE));
1388
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
1132
1389
 
1133
- double latSW = southWest.getDouble("latitude");
1134
- double lngSW = southWest.getDouble("longitude");
1135
- builder.include(new LatLng(latSW, lngSW));
1390
+ for (int i = 0; i < coordinatesArray.size(); i++) {
1391
+ ReadableMap latLng = coordinatesArray.getMap(i);
1392
+ double lat = latLng.getDouble("latitude");
1393
+ double lng = latLng.getDouble("longitude");
1394
+ builder.include(new LatLng(lat, lng));
1395
+ }
1136
1396
 
1137
- LatLngBounds bounds = builder.build();
1138
-
1139
- map.setLatLngBoundsForCameraTarget(bounds);
1140
- }
1141
-
1142
- // InfoWindowAdapter interface
1143
-
1144
- @Override
1145
- public View getInfoWindow(Marker marker) {
1146
- MapMarker markerView = getMarkerMap(marker);
1147
- return markerView.getCallout();
1148
- }
1149
-
1150
- @Override
1151
- public View getInfoContents(Marker marker) {
1152
- MapMarker markerView = getMarkerMap(marker);
1153
- return markerView.getInfoContents();
1154
- }
1155
-
1156
- @Override
1157
- public boolean dispatchTouchEvent(MotionEvent ev) {
1158
- gestureDetector.onTouchEvent(ev);
1159
-
1160
- int X = (int)ev.getX();
1161
- int Y = (int)ev.getY();
1162
- if(map != null) {
1163
- tapLocation = map.getProjection().fromScreenLocation(new Point(X,Y));
1164
- }
1165
-
1166
- int action = MotionEventCompat.getActionMasked(ev);
1167
-
1168
- switch (action) {
1169
- case (MotionEvent.ACTION_DOWN):
1170
- this.getParent().requestDisallowInterceptTouchEvent(
1171
- map != null && map.getUiSettings().isScrollGesturesEnabled());
1172
- break;
1173
- case (MotionEvent.ACTION_UP):
1174
- // Clear this regardless, since isScrollGesturesEnabled() may have been updated
1175
- this.getParent().requestDisallowInterceptTouchEvent(false);
1176
- break;
1177
- }
1178
- super.dispatchTouchEvent(ev);
1179
- return true;
1180
- }
1181
-
1182
- @Override
1183
- public void onMarkerDragStart(Marker marker) {
1184
- WritableMap event = makeClickEventData(marker.getPosition());
1185
- manager.pushEvent(context, this, "onMarkerDragStart", event);
1186
-
1187
- MapMarker markerView = getMarkerMap(marker);
1188
- event = makeClickEventData(marker.getPosition());
1189
- manager.pushEvent(context, markerView, "onDragStart", event);
1190
- }
1191
-
1192
- @Override
1193
- public void onMarkerDrag(Marker marker) {
1194
- WritableMap event = makeClickEventData(marker.getPosition());
1195
- manager.pushEvent(context, this, "onMarkerDrag", event);
1196
-
1197
- MapMarker markerView = getMarkerMap(marker);
1198
- event = makeClickEventData(marker.getPosition());
1199
- manager.pushEvent(context, markerView, "onDrag", event);
1200
- }
1201
-
1202
- @Override
1203
- public void onMarkerDragEnd(Marker marker) {
1204
- WritableMap event = makeClickEventData(marker.getPosition());
1205
- manager.pushEvent(context, this, "onMarkerDragEnd", event);
1206
-
1207
- MapMarker markerView = getMarkerMap(marker);
1208
- event = makeClickEventData(marker.getPosition());
1209
- manager.pushEvent(context, markerView, "onDragEnd", event);
1210
- }
1211
-
1212
- @Override
1213
- public void onPoiClick(PointOfInterest poi) {
1214
- WritableMap event = makeClickEventData(poi.latLng);
1215
-
1216
- event.putString("placeId", poi.placeId);
1217
- event.putString("name", poi.name);
1218
-
1219
- manager.pushEvent(context, this, "onPoiClick", event);
1220
- }
1221
-
1222
- private ProgressBar getMapLoadingProgressBar() {
1223
- if (this.mapLoadingProgressBar == null) {
1224
- this.mapLoadingProgressBar = new ProgressBar(getContext());
1225
- this.mapLoadingProgressBar.setIndeterminate(true);
1226
- }
1227
- if (this.loadingIndicatorColor != null) {
1228
- this.setLoadingIndicatorColor(this.loadingIndicatorColor);
1229
- }
1230
- return this.mapLoadingProgressBar;
1231
- }
1232
-
1233
- private RelativeLayout getMapLoadingLayoutView() {
1234
- if (this.mapLoadingLayout == null) {
1235
- this.mapLoadingLayout = new RelativeLayout(getContext());
1236
- this.mapLoadingLayout.setBackgroundColor(Color.LTGRAY);
1237
- this.addView(this.mapLoadingLayout,
1238
- new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
1239
- ViewGroup.LayoutParams.MATCH_PARENT));
1240
-
1241
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
1242
- RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
1243
- params.addRule(RelativeLayout.CENTER_IN_PARENT);
1244
- this.mapLoadingLayout.addView(this.getMapLoadingProgressBar(), params);
1245
-
1246
- this.mapLoadingLayout.setVisibility(View.INVISIBLE);
1247
- }
1248
- this.setLoadingBackgroundColor(this.loadingBackgroundColor);
1249
- return this.mapLoadingLayout;
1250
- }
1251
-
1252
- private ImageView getCacheImageView() {
1253
- if (this.cacheImageView == null) {
1254
- this.cacheImageView = new ImageView(getContext());
1255
- this.addView(this.cacheImageView,
1256
- new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
1257
- ViewGroup.LayoutParams.MATCH_PARENT));
1258
- this.cacheImageView.setVisibility(View.INVISIBLE);
1259
- }
1260
- return this.cacheImageView;
1261
- }
1262
-
1263
- private void removeCacheImageView() {
1264
- if (this.cacheImageView != null) {
1265
- ((ViewGroup) this.cacheImageView.getParent()).removeView(this.cacheImageView);
1266
- this.cacheImageView = null;
1267
- }
1268
- }
1269
-
1270
- private void removeMapLoadingProgressBar() {
1271
- if (this.mapLoadingProgressBar != null) {
1272
- ((ViewGroup) this.mapLoadingProgressBar.getParent()).removeView(this.mapLoadingProgressBar);
1273
- this.mapLoadingProgressBar = null;
1274
- }
1275
- }
1276
-
1277
- private void removeMapLoadingLayoutView() {
1278
- this.removeMapLoadingProgressBar();
1279
- if (this.mapLoadingLayout != null) {
1280
- ((ViewGroup) this.mapLoadingLayout.getParent()).removeView(this.mapLoadingLayout);
1281
- this.mapLoadingLayout = null;
1282
- }
1283
- }
1284
-
1285
- private void cacheView() {
1286
- if (this.cacheEnabled) {
1287
- final ImageView cacheImageView = this.getCacheImageView();
1288
- final RelativeLayout mapLoadingLayout = this.getMapLoadingLayoutView();
1289
- cacheImageView.setVisibility(View.INVISIBLE);
1290
- mapLoadingLayout.setVisibility(View.VISIBLE);
1291
- if (this.isMapLoaded) {
1292
- this.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
1293
- @Override public void onSnapshotReady(Bitmap bitmap) {
1294
- cacheImageView.setImageBitmap(bitmap);
1295
- cacheImageView.setVisibility(View.VISIBLE);
1296
- mapLoadingLayout.setVisibility(View.INVISIBLE);
1297
- }
1298
- });
1299
- }
1300
- } else {
1301
- this.removeCacheImageView();
1302
- if (this.isMapLoaded) {
1303
- this.removeMapLoadingLayoutView();
1304
- }
1305
- }
1306
- }
1307
-
1308
- public void onPanDrag(MotionEvent ev) {
1309
- Point point = new Point((int) ev.getX(), (int) ev.getY());
1310
- LatLng coords = this.map.getProjection().fromScreenLocation(point);
1311
- WritableMap event = makeClickEventData(coords);
1312
- manager.pushEvent(context, this, "onPanDrag", event);
1313
- }
1314
-
1315
- public void onDoublePress(MotionEvent ev) {
1316
- if (this.map == null) return;
1317
- Point point = new Point((int) ev.getX(), (int) ev.getY());
1318
- LatLng coords = this.map.getProjection().fromScreenLocation(point);
1319
- WritableMap event = makeClickEventData(coords);
1320
- manager.pushEvent(context, this, "onDoublePress", event);
1321
- }
1322
-
1323
- public void setKmlSrc(String kmlSrc) {
1324
- try {
1325
- InputStream kmlStream = new FileUtil(context).execute(kmlSrc).get();
1326
-
1327
- if (kmlStream == null) {
1328
- return;
1329
- }
1330
-
1331
- KmlLayer kmlLayer = new KmlLayer(map, kmlStream, context, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
1332
- kmlLayer.addLayerToMap();
1333
-
1334
- WritableMap pointers = new WritableNativeMap();
1335
- WritableArray markers = new WritableNativeArray();
1336
-
1337
- if (kmlLayer.getContainers() == null) {
1338
- manager.pushEvent(context, this, "onKmlReady", pointers);
1339
- return;
1340
- }
1341
-
1342
- //Retrieve a nested container within the first container
1343
- KmlContainer container = kmlLayer.getContainers().iterator().next();
1344
- if (container == null || container.getContainers() == null) {
1345
- manager.pushEvent(context, this, "onKmlReady", pointers);
1346
- return;
1347
- }
1348
-
1349
-
1350
- if (container.getContainers().iterator().hasNext()) {
1351
- container = container.getContainers().iterator().next();
1352
- }
1353
-
1354
- int index = 0;
1355
- for (KmlPlacemark placemark : container.getPlacemarks()) {
1356
- MarkerOptions options = new MarkerOptions();
1357
-
1358
- if (placemark.getInlineStyle() != null) {
1359
- options = placemark.getMarkerOptions();
1397
+ LatLngBounds bounds = builder.build();
1398
+ CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
1399
+
1400
+ if (edgePadding != null) {
1401
+ appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"), edgePadding.getInt("right"), edgePadding.getInt("bottom"));
1402
+ }
1403
+
1404
+ if (animated) {
1405
+ map.animateCamera(cu);
1360
1406
  } else {
1361
- options.icon(BitmapDescriptorFactory.defaultMarker());
1407
+ map.moveCamera(cu);
1408
+ }
1409
+ // Move the google logo to the default base padding value.
1410
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
1411
+ }
1412
+
1413
+ private void appendMapPadding(int iLeft, int iTop, int iRight, int iBottom) {
1414
+ double density = getResources().getDisplayMetrics().density;
1415
+
1416
+ edgeLeftPadding = (int) (iLeft * density);
1417
+ edgeTopPadding = (int) (iTop * density);
1418
+ edgeRightPadding = (int) (iRight * density);
1419
+ edgeBottomPadding = (int) (iBottom * density);
1420
+
1421
+ map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1422
+ edgeTopPadding + baseTopMapPadding,
1423
+ edgeRightPadding + baseRightMapPadding,
1424
+ edgeBottomPadding + baseBottomMapPadding);
1425
+ }
1426
+
1427
+ public double[][] getMapBoundaries() {
1428
+ LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
1429
+ LatLng northEast = bounds.northeast;
1430
+ LatLng southWest = bounds.southwest;
1431
+
1432
+ return new double[][]{
1433
+ {northEast.longitude, northEast.latitude},
1434
+ {southWest.longitude, southWest.latitude}
1435
+ };
1436
+ }
1437
+
1438
+ public void setMapBoundaries(ReadableMap northEast, ReadableMap southWest) {
1439
+ if (map == null) return;
1440
+
1441
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
1442
+
1443
+ double latNE = northEast.getDouble("latitude");
1444
+ double lngNE = northEast.getDouble("longitude");
1445
+ builder.include(new LatLng(latNE, lngNE));
1446
+
1447
+ double latSW = southWest.getDouble("latitude");
1448
+ double lngSW = southWest.getDouble("longitude");
1449
+ builder.include(new LatLng(latSW, lngSW));
1450
+
1451
+ LatLngBounds bounds = builder.build();
1452
+
1453
+ map.setLatLngBoundsForCameraTarget(bounds);
1454
+ }
1455
+
1456
+ // InfoWindowAdapter interface
1457
+
1458
+ @Override
1459
+ public View getInfoWindow(Marker marker) {
1460
+ MapMarker markerView = getMarkerMap(marker);
1461
+ return markerView.getCallout();
1462
+ }
1463
+
1464
+ @Override
1465
+ public View getInfoContents(Marker marker) {
1466
+ MapMarker markerView = getMarkerMap(marker);
1467
+ return markerView.getInfoContents();
1468
+ }
1469
+
1470
+ @Override
1471
+ public boolean dispatchTouchEvent(MotionEvent ev) {
1472
+ gestureDetector.onTouchEvent(ev);
1473
+
1474
+ int X = (int) ev.getX();
1475
+ int Y = (int) ev.getY();
1476
+ if (map != null) {
1477
+ tapLocation = map.getProjection().fromScreenLocation(new Point(X, Y));
1362
1478
  }
1363
1479
 
1364
- LatLng latLng = ((LatLng) placemark.getGeometry().getGeometryObject());
1365
- String title = "";
1366
- String snippet = "";
1480
+ int action = MotionEventCompat.getActionMasked(ev);
1481
+
1482
+ switch (action) {
1483
+ case (MotionEvent.ACTION_DOWN):
1484
+ this.getParent().requestDisallowInterceptTouchEvent(
1485
+ map != null && map.getUiSettings().isScrollGesturesEnabled());
1486
+ break;
1487
+ case (MotionEvent.ACTION_UP):
1488
+ // Clear this regardless, since isScrollGesturesEnabled() may have been updated
1489
+ this.getParent().requestDisallowInterceptTouchEvent(false);
1490
+ break;
1491
+ }
1492
+ super.dispatchTouchEvent(ev);
1493
+ return true;
1494
+ }
1367
1495
 
1368
- if (placemark.hasProperty("name")) {
1369
- title = placemark.getProperty("name");
1496
+ @Override
1497
+ public void onMarkerDragStart(Marker marker) {
1498
+ WritableMap event = makeClickEventData(marker.getPosition());
1499
+ dispatchEvent(event, OnMarkerDragStartEvent::new);
1500
+
1501
+ MapMarker markerView = getMarkerMap(marker);
1502
+ event = makeClickEventData(marker.getPosition());
1503
+ dispatchEvent(event, OnMarkerDragStartEvent::new, markerView.getId(), context);
1504
+ }
1505
+
1506
+ @Override
1507
+ public void onMarkerDrag(Marker marker) {
1508
+ WritableMap event = makeClickEventData(marker.getPosition());
1509
+ dispatchEvent(event, OnMarkerDragEvent::new);
1510
+
1511
+ MapMarker markerView = getMarkerMap(marker);
1512
+ event = makeClickEventData(marker.getPosition());
1513
+ dispatchEvent(event, OnMarkerDragEvent::new, markerView.getId(), context);
1514
+ }
1515
+
1516
+ @Override
1517
+ public void onMarkerDragEnd(Marker marker) {
1518
+ WritableMap event = makeClickEventData(marker.getPosition());
1519
+ dispatchEvent(event, OnMarkerDragEndEvent::new);
1520
+ MapMarker markerView = getMarkerMap(marker);
1521
+ event = makeClickEventData(marker.getPosition());
1522
+ dispatchEvent(event, OnMarkerDragEndEvent::new, markerView.getId(), context);
1523
+ }
1524
+
1525
+ @Override
1526
+ public void onPoiClick(PointOfInterest poi) {
1527
+ WritableMap event = makeClickEventData(poi.latLng);
1528
+
1529
+ event.putString("placeId", poi.placeId);
1530
+ event.putString("name", poi.name);
1531
+ dispatchEvent(event, OnPoiClickEvent::new);
1532
+ }
1533
+
1534
+ private ProgressBar getMapLoadingProgressBar() {
1535
+ if (this.mapLoadingProgressBar == null) {
1536
+ this.mapLoadingProgressBar = new ProgressBar(getContext());
1537
+ this.mapLoadingProgressBar.setIndeterminate(true);
1370
1538
  }
1539
+ if (this.loadingIndicatorColor != null) {
1540
+ this.setLoadingIndicatorColor(this.loadingIndicatorColor);
1541
+ }
1542
+ return this.mapLoadingProgressBar;
1543
+ }
1544
+
1545
+ private RelativeLayout getMapLoadingLayoutView() {
1546
+ if (this.mapLoadingLayout == null) {
1547
+ this.mapLoadingLayout = new RelativeLayout(getContext());
1548
+ this.mapLoadingLayout.setBackgroundColor(Color.LTGRAY);
1549
+ this.addView(this.mapLoadingLayout,
1550
+ new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
1551
+ ViewGroup.LayoutParams.MATCH_PARENT));
1552
+
1553
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
1554
+ RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
1555
+ params.addRule(RelativeLayout.CENTER_IN_PARENT);
1556
+ this.mapLoadingLayout.addView(this.getMapLoadingProgressBar(), params);
1557
+
1558
+ this.mapLoadingLayout.setVisibility(View.INVISIBLE);
1559
+ }
1560
+ this.setLoadingBackgroundColor(this.loadingBackgroundColor);
1561
+ return this.mapLoadingLayout;
1562
+ }
1371
1563
 
1372
- if (placemark.hasProperty("description")) {
1373
- snippet = placemark.getProperty("description");
1564
+ private ImageView getCacheImageView() {
1565
+ if (this.cacheImageView == null) {
1566
+ this.cacheImageView = new ImageView(getContext());
1567
+ this.addView(this.cacheImageView,
1568
+ new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
1569
+ ViewGroup.LayoutParams.MATCH_PARENT));
1570
+ this.cacheImageView.setVisibility(View.INVISIBLE);
1374
1571
  }
1572
+ return this.cacheImageView;
1573
+ }
1375
1574
 
1376
- options.position(latLng);
1377
- options.title(title);
1378
- options.snippet(snippet);
1575
+ private void removeCacheImageView() {
1576
+ if (this.cacheImageView != null) {
1577
+ ((ViewGroup) this.cacheImageView.getParent()).removeView(this.cacheImageView);
1578
+ this.cacheImageView = null;
1579
+ }
1580
+ }
1379
1581
 
1582
+ private void removeMapLoadingProgressBar() {
1583
+ if (this.mapLoadingProgressBar != null) {
1584
+ ((ViewGroup) this.mapLoadingProgressBar.getParent()).removeView(this.mapLoadingProgressBar);
1585
+ this.mapLoadingProgressBar = null;
1586
+ }
1587
+ }
1588
+
1589
+ private void removeMapLoadingLayoutView() {
1590
+ this.removeMapLoadingProgressBar();
1591
+ if (this.mapLoadingLayout != null) {
1592
+ ((ViewGroup) this.mapLoadingLayout.getParent()).removeView(this.mapLoadingLayout);
1593
+ this.mapLoadingLayout = null;
1594
+ }
1595
+ }
1596
+
1597
+ private void cacheView() {
1598
+ if (this.cacheEnabled) {
1599
+ final ImageView cacheImageView = this.getCacheImageView();
1600
+ final RelativeLayout mapLoadingLayout = this.getMapLoadingLayoutView();
1601
+ cacheImageView.setVisibility(View.INVISIBLE);
1602
+ mapLoadingLayout.setVisibility(View.VISIBLE);
1603
+ if (this.isMapLoaded) {
1604
+ this.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
1605
+ @Override
1606
+ public void onSnapshotReady(Bitmap bitmap) {
1607
+ cacheImageView.setImageBitmap(bitmap);
1608
+ cacheImageView.setVisibility(View.VISIBLE);
1609
+ mapLoadingLayout.setVisibility(View.INVISIBLE);
1610
+ }
1611
+ });
1612
+ }
1613
+ } else {
1614
+ this.removeCacheImageView();
1615
+ if (this.isMapLoaded) {
1616
+ this.removeMapLoadingLayoutView();
1617
+ }
1618
+ }
1619
+ }
1620
+
1621
+ public void onPanDrag(MotionEvent ev) {
1622
+ Point point = new Point((int) ev.getX(), (int) ev.getY());
1623
+ LatLng coords = this.map.getProjection().fromScreenLocation(point);
1624
+ WritableMap event = makeClickEventData(coords);
1625
+ dispatchEvent(event, OnPanDragEvent::new);
1626
+ }
1627
+
1628
+ public void onDoublePress(MotionEvent ev) {
1629
+ if (this.map == null) return;
1630
+ Point point = new Point((int) ev.getX(), (int) ev.getY());
1631
+ LatLng coords = this.map.getProjection().fromScreenLocation(point);
1632
+ WritableMap event = makeClickEventData(coords);
1633
+ dispatchEvent(event, OnDoublePressEvent::new);
1634
+
1635
+ }
1636
+
1637
+ public void setKmlSrc(String kmlSrc) {
1638
+ if (isMapReady) {
1639
+ try {
1640
+ InputStream kmlStream = new FileUtil(context).execute(kmlSrc).get();
1641
+
1642
+ if (kmlStream == null) {
1643
+ return;
1644
+ }
1645
+
1646
+ KmlLayer kmlLayer = new KmlLayer(map, kmlStream, context, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
1647
+
1648
+ kmlLayer.addLayerToMap();
1649
+
1650
+ WritableMap pointers = new WritableNativeMap();
1651
+ WritableArray markers = new WritableNativeArray();
1652
+
1653
+ if (kmlLayer.getContainers() == null) {
1654
+ dispatchEvent(pointers, OnKmlReadyEvent::new);
1655
+ return;
1656
+ }
1657
+
1658
+ //Retrieve a nested container within the first container
1659
+ KmlContainer container = kmlLayer.getContainers().iterator().next();
1660
+ if (container == null || container.getContainers() == null) {
1661
+ dispatchEvent(pointers, OnKmlReadyEvent::new);
1662
+ return;
1663
+ }
1664
+
1665
+
1666
+ if (container.getContainers().iterator().hasNext()) {
1667
+ container = container.getContainers().iterator().next();
1668
+ }
1669
+
1670
+ int index = 0;
1671
+ for (KmlPlacemark placemark : container.getPlacemarks()) {
1672
+ MarkerOptions options = new MarkerOptions();
1673
+
1674
+ if (placemark.getInlineStyle() != null) {
1675
+ options = placemark.getMarkerOptions();
1676
+ } else {
1677
+ options.icon(BitmapDescriptorFactory.defaultMarker());
1678
+ }
1679
+
1680
+ LatLng latLng = ((LatLng) placemark.getGeometry().getGeometryObject());
1681
+ String title = "";
1682
+ String snippet = "";
1683
+
1684
+ if (placemark.hasProperty("name")) {
1685
+ title = placemark.getProperty("name");
1686
+ }
1687
+
1688
+ if (placemark.hasProperty("description")) {
1689
+ snippet = placemark.getProperty("description");
1690
+ }
1691
+
1692
+ options.position(latLng);
1693
+ options.title(title);
1694
+ options.snippet(snippet);
1695
+ // FIXME: get markerManager from somewhere
1696
+ /*
1380
1697
  MapMarker marker = new MapMarker(context, options, this.manager.getMarkerManager());
1381
1698
 
1382
1699
  if (placemark.getInlineStyle() != null
@@ -1393,127 +1710,123 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
1393
1710
 
1394
1711
  addFeature(marker, index++);
1395
1712
 
1713
+
1396
1714
  WritableMap loadedMarker = makeClickEventData(latLng);
1397
1715
  loadedMarker.putString("id", identifier);
1398
1716
  loadedMarker.putString("title", title);
1399
1717
  loadedMarker.putString("description", snippet);
1400
1718
 
1401
1719
  markers.pushMap(loadedMarker);
1402
- }
1403
-
1404
- pointers.putArray("markers", markers);
1405
-
1406
- manager.pushEvent(context, this, "onKmlReady", pointers);
1407
-
1408
- } catch (XmlPullParserException | IOException | InterruptedException | ExecutionException e) {
1409
- e.printStackTrace();
1410
- }
1411
- }
1412
-
1413
- @Override
1414
- public void onIndoorBuildingFocused() {
1415
- IndoorBuilding building = this.map.getFocusedBuilding();
1416
- if (building != null) {
1417
- List<IndoorLevel> levels = building.getLevels();
1418
- int index = 0;
1419
- WritableArray levelsArray = Arguments.createArray();
1420
- for (IndoorLevel level : levels) {
1421
- WritableMap levelMap = Arguments.createMap();
1422
- levelMap.putInt("index", index);
1423
- levelMap.putString("name", level.getName());
1424
- levelMap.putString("shortName", level.getShortName());
1425
- levelsArray.pushMap(levelMap);
1426
- index++;
1427
- }
1428
- WritableMap event = Arguments.createMap();
1429
- WritableMap indoorBuilding = Arguments.createMap();
1430
- indoorBuilding.putArray("levels", levelsArray);
1431
- indoorBuilding.putInt("activeLevelIndex", building.getActiveLevelIndex());
1432
- indoorBuilding.putBoolean("underground", building.isUnderground());
1433
-
1434
- event.putMap("IndoorBuilding", indoorBuilding);
1435
-
1436
- manager.pushEvent(context, this, "onIndoorBuildingFocused", event);
1437
- } else {
1438
- WritableMap event = Arguments.createMap();
1439
- WritableArray levelsArray = Arguments.createArray();
1440
- WritableMap indoorBuilding = Arguments.createMap();
1441
- indoorBuilding.putArray("levels", levelsArray);
1442
- indoorBuilding.putInt("activeLevelIndex", 0);
1443
- indoorBuilding.putBoolean("underground", false);
1444
-
1445
- event.putMap("IndoorBuilding", indoorBuilding);
1446
-
1447
- manager.pushEvent(context, this, "onIndoorBuildingFocused", event);
1448
- }
1449
- }
1450
-
1451
- @Override
1452
- public void onIndoorLevelActivated(IndoorBuilding building) {
1453
- if (building == null) {
1454
- return;
1455
- }
1456
- int activeLevelIndex = building.getActiveLevelIndex();
1457
- if (activeLevelIndex < 0 || activeLevelIndex >= building.getLevels().size()) {
1458
- return;
1459
- }
1460
- IndoorLevel level = building.getLevels().get(activeLevelIndex);
1461
-
1462
- WritableMap event = Arguments.createMap();
1463
- WritableMap indoorlevel = Arguments.createMap();
1464
-
1465
- indoorlevel.putInt("activeLevelIndex", activeLevelIndex);
1466
- indoorlevel.putString("name", level.getName());
1467
- indoorlevel.putString("shortName", level.getShortName());
1468
-
1469
- event.putMap("IndoorLevel", indoorlevel);
1470
-
1471
- manager.pushEvent(context, this, "onIndoorLevelActivated", event);
1472
- }
1473
-
1474
- public void setIndoorActiveLevelIndex(int activeLevelIndex) {
1475
- IndoorBuilding building = this.map.getFocusedBuilding();
1476
- if (building != null) {
1477
- if (activeLevelIndex >= 0 && activeLevelIndex < building.getLevels().size()) {
1478
- IndoorLevel level = building.getLevels().get(activeLevelIndex);
1479
- if (level != null) {
1480
- level.activate();
1720
+ */
1721
+ }
1722
+
1723
+ pointers.putArray("markers", markers);
1724
+ dispatchEvent(new WritableNativeMap(), OnKmlReadyEvent::new);
1725
+
1726
+ } catch (XmlPullParserException | IOException | InterruptedException |
1727
+ ExecutionException e) {
1728
+ e.printStackTrace();
1729
+ }
1730
+ } else {
1731
+ this.kmlSrc = kmlSrc;
1481
1732
  }
1482
- }
1483
1733
  }
1484
- }
1485
1734
 
1486
- private MapMarker getMarkerMap(Marker marker) {
1487
- MapMarker airMarker = markerMap.get(marker);
1735
+ @Override
1736
+ public void onIndoorBuildingFocused() {
1737
+ IndoorBuilding building = this.map.getFocusedBuilding();
1738
+ if (building != null) {
1739
+ List<IndoorLevel> levels = building.getLevels();
1740
+ int index = 0;
1741
+ WritableArray levelsArray = Arguments.createArray();
1742
+ for (IndoorLevel level : levels) {
1743
+ WritableMap levelMap = Arguments.createMap();
1744
+ levelMap.putInt("index", index);
1745
+ levelMap.putString("name", level.getName());
1746
+ levelMap.putString("shortName", level.getShortName());
1747
+ levelsArray.pushMap(levelMap);
1748
+ index++;
1749
+ }
1750
+ WritableMap indoorBuilding = Arguments.createMap();
1751
+ indoorBuilding.putArray("levels", levelsArray);
1752
+ indoorBuilding.putInt("activeLevelIndex", building.getActiveLevelIndex());
1753
+ indoorBuilding.putBoolean("underground", building.isUnderground());
1754
+
1755
+ dispatchEvent(indoorBuilding, OnIndoorBuildingFocusedEvent::new);
1756
+ } else {
1757
+ WritableArray levelsArray = Arguments.createArray();
1758
+ WritableMap indoorBuilding = Arguments.createMap();
1759
+ indoorBuilding.putArray("levels", levelsArray);
1760
+ indoorBuilding.putInt("activeLevelIndex", 0);
1761
+ indoorBuilding.putBoolean("underground", false);
1488
1762
 
1489
- if (airMarker != null) {
1490
- return airMarker;
1763
+ dispatchEvent(indoorBuilding, OnIndoorBuildingFocusedEvent::new);
1764
+ }
1491
1765
  }
1492
1766
 
1493
- for (Map.Entry<Marker, MapMarker> entryMarker : markerMap.entrySet()) {
1494
- if (entryMarker.getKey().getPosition().equals(marker.getPosition())
1495
- && entryMarker.getKey().getTitle().equals(marker.getTitle())) {
1496
- airMarker = entryMarker.getValue();
1497
- break;
1498
- }
1767
+ @Override
1768
+ public void onIndoorLevelActivated(IndoorBuilding building) {
1769
+ if (building == null) {
1770
+ return;
1771
+ }
1772
+ int activeLevelIndex = building.getActiveLevelIndex();
1773
+ if (activeLevelIndex < 0 || activeLevelIndex >= building.getLevels().size()) {
1774
+ return;
1775
+ }
1776
+ IndoorLevel level = building.getLevels().get(activeLevelIndex);
1777
+
1778
+ WritableMap indoorlevel = Arguments.createMap();
1779
+
1780
+ indoorlevel.putInt("activeLevelIndex", activeLevelIndex);
1781
+ indoorlevel.putString("name", level.getName());
1782
+ indoorlevel.putString("shortName", level.getShortName());
1783
+
1784
+ dispatchEvent(indoorlevel, OnIndoorLevelActivatedEvent::new);
1499
1785
  }
1500
1786
 
1501
- return airMarker;
1502
- }
1787
+ public void setIndoorActiveLevelIndex(int activeLevelIndex) {
1788
+ IndoorBuilding building = this.map.getFocusedBuilding();
1789
+ if (building != null) {
1790
+ if (activeLevelIndex >= 0 && activeLevelIndex < building.getLevels().size()) {
1791
+ IndoorLevel level = building.getLevels().get(activeLevelIndex);
1792
+ if (level != null) {
1793
+ level.activate();
1794
+ }
1795
+ }
1796
+ }
1797
+ }
1798
+
1799
+ private MapMarker getMarkerMap(Marker marker) {
1800
+ MapMarker airMarker = markerMap.get(marker);
1801
+
1802
+ if (airMarker != null) {
1803
+ return airMarker;
1804
+ }
1805
+
1806
+ for (Map.Entry<Marker, MapMarker> entryMarker : markerMap.entrySet()) {
1807
+ if (entryMarker.getKey().getPosition().equals(marker.getPosition())
1808
+ && entryMarker.getKey().getTitle().equals(marker.getTitle())) {
1809
+ airMarker = entryMarker.getValue();
1810
+ break;
1811
+ }
1812
+ }
1503
1813
 
1504
- @Override
1505
- public void requestLayout() {
1506
- super.requestLayout();
1507
- post(measureAndLayout);
1508
- }
1814
+ return airMarker;
1815
+ }
1509
1816
 
1510
- private final Runnable measureAndLayout = new Runnable() {
1511
1817
  @Override
1512
- public void run() {
1513
- measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
1514
- MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
1515
- layout(getLeft(), getTop(), getRight(), getBottom());
1818
+ public void requestLayout() {
1819
+ super.requestLayout();
1820
+ post(measureAndLayout);
1516
1821
  }
1517
- };
1822
+
1823
+ private final Runnable measureAndLayout = new Runnable() {
1824
+ @Override
1825
+ public void run() {
1826
+ measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
1827
+ MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
1828
+ layout(getLeft(), getTop(), getRight(), getBottom());
1829
+ }
1830
+ };
1518
1831
 
1519
1832
  }