react-native-maps 1.21.0-alpha.7 → 1.21.0-alpha.71

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