react-native-map4d-map-dtqg 0.1.2 → 0.1.3

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 (195) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +133 -133
  3. package/android/build.gradle +60 -60
  4. package/android/src/main/AndroidManifest.xml +4 -4
  5. package/android/src/main/java/com/reactnativemap4dmap/ImageUtils.java +87 -87
  6. package/android/src/main/java/com/reactnativemap4dmap/Map4dMapModule.java +298 -298
  7. package/android/src/main/java/com/reactnativemap4dmap/Map4dMapPackage.java +35 -35
  8. package/android/src/main/java/com/reactnativemap4dmap/Map4dMapViewManager.java +31 -31
  9. package/android/src/main/java/com/reactnativemap4dmap/RMFBuilding.java +167 -167
  10. package/android/src/main/java/com/reactnativemap4dmap/RMFBuildingManager.java +121 -121
  11. package/android/src/main/java/com/reactnativemap4dmap/RMFCircle.java +105 -105
  12. package/android/src/main/java/com/reactnativemap4dmap/RMFCircleManager.java +121 -121
  13. package/android/src/main/java/com/reactnativemap4dmap/RMFDirectionsRenderer.java +502 -502
  14. package/android/src/main/java/com/reactnativemap4dmap/RMFDirectionsRendererManager.java +143 -143
  15. package/android/src/main/java/com/reactnativemap4dmap/RMFFeature.java +17 -17
  16. package/android/src/main/java/com/reactnativemap4dmap/RMFMapView.java +1172 -1172
  17. package/android/src/main/java/com/reactnativemap4dmap/RMFMapViewManager.java +231 -231
  18. package/android/src/main/java/com/reactnativemap4dmap/RMFMarker.java +412 -412
  19. package/android/src/main/java/com/reactnativemap4dmap/RMFMarkerManager.java +211 -211
  20. package/android/src/main/java/com/reactnativemap4dmap/RMFPOI.java +222 -222
  21. package/android/src/main/java/com/reactnativemap4dmap/RMFPOIManager.java +119 -119
  22. package/android/src/main/java/com/reactnativemap4dmap/RMFPolygon.java +172 -172
  23. package/android/src/main/java/com/reactnativemap4dmap/RMFPolygonManager.java +147 -147
  24. package/android/src/main/java/com/reactnativemap4dmap/RMFPolyline.java +146 -146
  25. package/android/src/main/java/com/reactnativemap4dmap/RMFPolylineManager.java +137 -137
  26. package/android/src/main/java/com/reactnativemap4dmap/RMFTileOverlay.java +95 -95
  27. package/android/src/main/java/com/reactnativemap4dmap/RMFTileOverlayManager.java +64 -64
  28. package/android/src/main/java/com/reactnativemap4dmap/SizeReportingShadowNode.java +31 -31
  29. package/android/src/main/java/com/reactnativemap4dmap/ViewAttacherGroup.java +31 -31
  30. package/android/src/main/java/com/reactnativemap4dmap/ViewChangesTracker.java +70 -70
  31. package/android/src/main/java/vn/map4d/map/annotations/RMFBitmapDescriptor.java +9 -9
  32. package/ios/Map4dMap.h +7 -7
  33. package/ios/Map4dMap.m +14 -14
  34. package/ios/Map4dMap.xcodeproj/project.pbxproj +2 -2
  35. package/ios/Map4dMapViewManager.m +34 -34
  36. package/ios/RCTConvert+Map4dMap.h +33 -33
  37. package/ios/RCTConvert+Map4dMap.m +112 -112
  38. package/ios/RMFCircle.h +37 -37
  39. package/ios/RMFCircle.m +100 -100
  40. package/ios/RMFCircleManager.h +18 -18
  41. package/ios/RMFCircleManager.m +155 -155
  42. package/ios/RMFCircleMap4d.h +23 -23
  43. package/ios/RMFCircleMap4d.m +13 -13
  44. package/ios/RMFCoordinate.h +22 -22
  45. package/ios/RMFCoordinate.m +13 -13
  46. package/ios/RMFDirectionsMarkerOptions.h +24 -24
  47. package/ios/RMFDirectionsMarkerOptions.m +23 -23
  48. package/ios/RMFDirectionsRenderer.h +47 -47
  49. package/ios/RMFDirectionsRenderer.m +182 -182
  50. package/ios/RMFDirectionsRendererManager.h +17 -17
  51. package/ios/RMFDirectionsRendererManager.m +84 -84
  52. package/ios/RMFDirectionsRendererMap4d.h +21 -21
  53. package/ios/RMFDirectionsRendererMap4d.m +12 -12
  54. package/ios/RMFDummyView.h +6 -6
  55. package/ios/RMFDummyView.m +12 -12
  56. package/ios/RMFEventResponse.h +39 -39
  57. package/ios/RMFEventResponse.m +98 -98
  58. package/ios/RMFIcon.h +24 -24
  59. package/ios/RMFIcon.m +35 -35
  60. package/ios/RMFMapView.h +84 -84
  61. package/ios/RMFMapView.m +376 -376
  62. package/ios/RMFMapViewManager.h +17 -17
  63. package/ios/RMFMapViewManager.m +509 -508
  64. package/ios/RMFMarker.h +57 -57
  65. package/ios/RMFMarker.m +267 -267
  66. package/ios/RMFMarkerManager.h +17 -17
  67. package/ios/RMFMarkerManager.m +156 -156
  68. package/ios/RMFMarkerMap4d.h +19 -19
  69. package/ios/RMFMarkerMap4d.m +13 -13
  70. package/ios/RMFPOI.h +38 -38
  71. package/ios/RMFPOI.m +123 -123
  72. package/ios/RMFPOIManager.h +18 -18
  73. package/ios/RMFPOIManager.m +168 -168
  74. package/ios/RMFPOIMap4d.h +22 -22
  75. package/ios/RMFPOIMap4d.m +12 -12
  76. package/ios/RMFPolygon.h +41 -41
  77. package/ios/RMFPolygon.m +106 -106
  78. package/ios/RMFPolygonManager.h +18 -18
  79. package/ios/RMFPolygonManager.m +141 -141
  80. package/ios/RMFPolygonMap4d.h +23 -23
  81. package/ios/RMFPolygonMap4d.m +15 -15
  82. package/ios/RMFPolyline.h +38 -38
  83. package/ios/RMFPolyline.m +101 -101
  84. package/ios/RMFPolylineManager.h +18 -18
  85. package/ios/RMFPolylineManager.m +139 -139
  86. package/ios/RMFPolylineMap4d.h +22 -22
  87. package/ios/RMFPolylineMap4d.m +15 -15
  88. package/ios/building/RMFBuilding.h +41 -41
  89. package/ios/building/RMFBuilding.m +104 -104
  90. package/ios/building/RMFBuildingManager.h +19 -19
  91. package/ios/building/RMFBuildingManager.m +133 -133
  92. package/ios/building/RMFBuildingMap4d.h +23 -23
  93. package/ios/building/RMFBuildingMap4d.m +15 -15
  94. package/ios/overlays/RMFTileOverlay.h +36 -36
  95. package/ios/overlays/RMFTileOverlay.m +64 -64
  96. package/ios/overlays/RMFTileOverlayManager.h +17 -17
  97. package/ios/overlays/RMFTileOverlayManager.m +27 -27
  98. package/lib/commonjs/components/MFBanDoSo.js.map +1 -1
  99. package/lib/commonjs/components/MFBuilding.js +26 -26
  100. package/lib/commonjs/components/MFBuilding.js.map +1 -1
  101. package/lib/commonjs/components/MFCircle.js +20 -20
  102. package/lib/commonjs/components/MFCircle.js.map +1 -1
  103. package/lib/commonjs/components/MFDirectionsRenderer.js +32 -32
  104. package/lib/commonjs/components/MFDirectionsRenderer.js.map +1 -1
  105. package/lib/commonjs/components/MFMapView.js +69 -69
  106. package/lib/commonjs/components/MFMapView.js.map +1 -1
  107. package/lib/commonjs/components/MFMarker.js +35 -35
  108. package/lib/commonjs/components/MFMarker.js.map +1 -1
  109. package/lib/commonjs/components/MFPOI.js +20 -20
  110. package/lib/commonjs/components/MFPOI.js.map +1 -1
  111. package/lib/commonjs/components/MFPolygon.js +22 -22
  112. package/lib/commonjs/components/MFPolygon.js.map +1 -1
  113. package/lib/commonjs/components/MFPolyline.js +18 -18
  114. package/lib/commonjs/components/MFPolyline.js.map +1 -1
  115. package/lib/commonjs/components/MFTileOverlay.js +9 -9
  116. package/lib/commonjs/components/MFTileOverlay.js.map +1 -1
  117. package/lib/commonjs/components/Map4dMapView.js.map +1 -1
  118. package/lib/commonjs/components/extends/AreaFocusManager.js +16 -16
  119. package/lib/commonjs/components/extends/AreaFocusManager.js.map +1 -1
  120. package/lib/commonjs/components/extends/AreaFocuser.js +2 -2
  121. package/lib/commonjs/components/extends/AreaFocuser.js.map +1 -1
  122. package/lib/commonjs/components/extends/BoundHelper.js.map +1 -1
  123. package/lib/commonjs/components/extends/area/AreaFocusAreas.js.map +1 -1
  124. package/lib/commonjs/components/extends/area/AreaFocusGeometryUtils.js.map +1 -1
  125. package/lib/commonjs/components/extends/area/AreaFocusSession.js.map +1 -1
  126. package/lib/commonjs/components/extends/area/AreaFocusTypes.js +18 -18
  127. package/lib/commonjs/components/extends/area/AreaFocusTypes.js.map +1 -1
  128. package/lib/commonjs/components/internal/DefaultRoadmapStyle.js.map +1 -1
  129. package/lib/commonjs/components/internal/GeojsonStyleUtils.js.map +1 -1
  130. package/lib/commonjs/index.js.map +1 -1
  131. package/lib/module/components/MFBanDoSo.js.map +1 -1
  132. package/lib/module/components/MFBuilding.js +26 -26
  133. package/lib/module/components/MFBuilding.js.map +1 -1
  134. package/lib/module/components/MFCircle.js +20 -20
  135. package/lib/module/components/MFCircle.js.map +1 -1
  136. package/lib/module/components/MFDirectionsRenderer.js +32 -32
  137. package/lib/module/components/MFDirectionsRenderer.js.map +1 -1
  138. package/lib/module/components/MFMapView.js +69 -69
  139. package/lib/module/components/MFMapView.js.map +1 -1
  140. package/lib/module/components/MFMarker.js +35 -35
  141. package/lib/module/components/MFMarker.js.map +1 -1
  142. package/lib/module/components/MFPOI.js +20 -20
  143. package/lib/module/components/MFPOI.js.map +1 -1
  144. package/lib/module/components/MFPolygon.js +22 -22
  145. package/lib/module/components/MFPolygon.js.map +1 -1
  146. package/lib/module/components/MFPolyline.js +18 -18
  147. package/lib/module/components/MFPolyline.js.map +1 -1
  148. package/lib/module/components/MFTileOverlay.js +9 -9
  149. package/lib/module/components/MFTileOverlay.js.map +1 -1
  150. package/lib/module/components/Map4dMapView.js.map +1 -1
  151. package/lib/module/components/extends/AreaFocusManager.js +16 -16
  152. package/lib/module/components/extends/AreaFocusManager.js.map +1 -1
  153. package/lib/module/components/extends/AreaFocuser.js +2 -2
  154. package/lib/module/components/extends/AreaFocuser.js.map +1 -1
  155. package/lib/module/components/extends/BoundHelper.js.map +1 -1
  156. package/lib/module/components/extends/area/AreaFocusAreas.js.map +1 -1
  157. package/lib/module/components/extends/area/AreaFocusGeometryUtils.js.map +1 -1
  158. package/lib/module/components/extends/area/AreaFocusSession.js.map +1 -1
  159. package/lib/module/components/extends/area/AreaFocusTypes.js +18 -18
  160. package/lib/module/components/extends/area/AreaFocusTypes.js.map +1 -1
  161. package/lib/module/components/internal/DefaultRoadmapStyle.js.map +1 -1
  162. package/lib/module/components/internal/GeojsonStyleUtils.js.map +1 -1
  163. package/lib/module/index.js.map +1 -1
  164. package/lib/typescript/components/Map4dMapView.d.ts +7 -7
  165. package/package.json +152 -152
  166. package/react-native-map4d-map.podspec +20 -20
  167. package/src/components/MFBanDoSo.js +124 -124
  168. package/src/components/MFBuilding.js +187 -187
  169. package/src/components/MFCircle.js +173 -173
  170. package/src/components/MFDirectionsRenderer.js +237 -237
  171. package/src/components/MFMapView.js +464 -464
  172. package/src/components/MFMarker.js +246 -246
  173. package/src/components/MFPOI.js +184 -184
  174. package/src/components/MFPolygon.js +186 -186
  175. package/src/components/MFPolyline.js +172 -172
  176. package/src/components/MFTileOverlay.js +45 -45
  177. package/src/components/Map4dMapView.tsx +26 -26
  178. package/src/components/extends/AreaFocusManager.js +196 -196
  179. package/src/components/extends/AreaFocuser.js +61 -61
  180. package/src/components/extends/BoundHelper.js +31 -31
  181. package/src/components/extends/area/AreaFocusAreas.js +164 -164
  182. package/src/components/extends/area/AreaFocusGeometryUtils.js +164 -164
  183. package/src/components/extends/area/AreaFocusSession.js +100 -100
  184. package/src/components/extends/area/AreaFocusTypes.js +36 -36
  185. package/src/components/internal/DefaultRoadmapStyle.js +3365 -3365
  186. package/src/components/internal/GeojsonStyleUtils.js +143 -143
  187. package/src/index.js +25 -25
  188. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  189. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  190. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  191. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  192. package/android/.gradle/8.9/gc.properties +0 -0
  193. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  194. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  195. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -1,1172 +1,1172 @@
1
- package com.reactnativemap4dmap;
2
-
3
- import static androidx.core.content.PermissionChecker.checkSelfPermission;
4
-
5
- import android.content.Context;
6
- import android.graphics.Point;
7
- import android.view.MotionEvent;
8
- import android.view.View;
9
- import android.view.ViewGroup;
10
-
11
- import androidx.annotation.NonNull;
12
- import androidx.core.content.PermissionChecker;
13
-
14
- import com.facebook.react.bridge.LifecycleEventListener;
15
- import com.facebook.react.bridge.ReactApplicationContext;
16
- import com.facebook.react.bridge.WritableMap;
17
- import com.facebook.react.bridge.WritableNativeMap;
18
- import com.facebook.react.bridge.ReadableMap;
19
- import com.facebook.react.uimanager.ThemedReactContext;
20
-
21
- import java.util.Date;
22
- import java.util.ArrayList;
23
- import java.util.HashMap;
24
- import java.util.List;
25
- import java.util.Map;
26
-
27
- import vn.map4d.map.core.*;
28
- import vn.map4d.map.camera.*;
29
- import vn.map4d.map.annotations.*;
30
- import vn.map4d.map.overlays.MFTileOverlay;
31
- import vn.map4d.types.MFLocationCoordinate;
32
- import vn.map4d.utils.android.collections.MFMarkerManager;
33
-
34
- public class RMFMapView extends MFMapView implements OnMapReadyCallback {
35
-
36
- public Map4D map;
37
-
38
- private boolean showUserLocation = false;
39
-
40
- private static final String[] PERMISSIONS = new String[]{
41
- "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"};
42
-
43
- private RMFMapViewManager manager;
44
- private LifecycleEventListener lifecycleListener;
45
- private boolean paused = false;
46
- private boolean destroyed = false;
47
- private final ThemedReactContext context;
48
- private final List<RMFFeature> features = new ArrayList<>();
49
- private final Map<MFMarker, RMFMarker> markerMap = new HashMap<>();
50
- private final Map<MFCircle, RMFCircle> circleMap = new HashMap<>();
51
- private final Map<MFPolyline, RMFPolyline> polylineMap = new HashMap<>();
52
- private final Map<MFPolygon, RMFPolygon> polygonMap = new HashMap<>();
53
- private final Map<MFBuilding, RMFBuilding> buildingMap = new HashMap<>();
54
- private final Map<Long, RMFPOI> poiMap = new HashMap<>();
55
- private final Map<MFTileOverlay, RMFTileOverlay> tileOverlayMap = new HashMap<>();
56
- private final Map<MFDirectionsRenderer, RMFDirectionsRenderer> directionsRendererMap = new HashMap<>();
57
-
58
- private MFMarkerManager.Collection markerCollection;
59
-
60
- private ViewAttacherGroup attacherGroup;
61
-
62
- private float touchPointX = 0.f;
63
- private float touchPointY = 0.f;
64
- private float dragPointX = 0.f;
65
- private float dragPointY = 0.f;
66
-
67
- private static boolean contextHasBug(Context context) {
68
- return context == null ||
69
- context.getResources() == null ||
70
- context.getResources().getConfiguration() == null;
71
- }
72
-
73
- private static Context getNonBuggyContext(ThemedReactContext reactContext,
74
- ReactApplicationContext appContext) {
75
- Context superContext = reactContext;
76
- if (!contextHasBug(appContext.getCurrentActivity())) {
77
- superContext = appContext.getCurrentActivity();
78
- } else if (contextHasBug(superContext)) {
79
- // we have the bug! let's try to find a better context to use
80
- if (!contextHasBug(reactContext.getCurrentActivity())) {
81
- superContext = reactContext.getCurrentActivity();
82
- } else if (!contextHasBug(reactContext.getApplicationContext())) {
83
- superContext = reactContext.getApplicationContext();
84
- } else {
85
- }
86
- }
87
- return superContext;
88
- }
89
-
90
- public RMFMapView(ThemedReactContext reactContext, ReactApplicationContext appContext, RMFMapViewManager manager) {
91
- super(getNonBuggyContext(reactContext, appContext), null);
92
- this.manager = manager;
93
- this.context = reactContext;
94
-
95
- super.onCreate(null);
96
- super.onStart();
97
- this.getMapAsync(this);
98
-
99
- // Set up a parent view for triggering visibility in subviews that depend on it.
100
- // Mainly ReactImageView depends on Fresco which depends on onVisibilityChanged() event
101
- attacherGroup = new ViewAttacherGroup(context);
102
- LayoutParams attacherLayoutParams = new LayoutParams(0, 0);
103
- attacherLayoutParams.width = 0;
104
- attacherLayoutParams.height = 0;
105
- attacherLayoutParams.leftMargin = 99999999;
106
- attacherLayoutParams.topMargin = 99999999;
107
- attacherGroup.setLayoutParams(attacherLayoutParams);
108
- addView(attacherGroup);
109
- }
110
-
111
- @Override
112
- public boolean onTouchEvent(MotionEvent event) {
113
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
114
- touchPointX = event.getX();
115
- touchPointY = event.getY();
116
- }
117
- if (event.getAction() == MotionEvent.ACTION_MOVE) {
118
- dragPointX = event.getX();
119
- dragPointY = event.getY();
120
- }
121
- return super.onTouchEvent(event);
122
- }
123
-
124
- @Override
125
- public void onMapReady(final Map4D map) {
126
- if (destroyed) {
127
- return;
128
- }
129
- this.map = map;
130
- final RMFMapView view = this;
131
- MFMarkerManager markerManager = new MFMarkerManager(map);
132
- markerCollection = markerManager.newCollection();
133
-
134
- manager.pushEvent(getContext(), this, "onMapReady", new WritableNativeMap());
135
-
136
- markerCollection.setOnMarkerDragListener((new Map4D.OnMarkerDragListener() {
137
- @Override
138
- public void onMarkerDrag(MFMarker marker) {
139
- RMFMarker rctMarker = markerMap.get(marker);
140
- if (rctMarker == null) {
141
- return;
142
- }
143
-
144
- //Event for MFMapView
145
- WritableMap event = getMarkerEventData(marker, dragPointX, dragPointY);
146
- event.putString("action", "marker-drag");
147
- manager.pushEvent(getContext(), view, "onMarkerDrag", event);
148
-
149
- //Event for MFMarker
150
- event = getMarkerEventData(marker, dragPointX, dragPointY);
151
- event.putString("action", "marker-drag");
152
- manager.pushEvent(getContext(), rctMarker, "onDrag", event);
153
- }
154
-
155
- @Override
156
- public void onMarkerDragEnd(MFMarker marker) {
157
- RMFMarker rctMarker = markerMap.get(marker);
158
- if (rctMarker == null) {
159
- return;
160
- }
161
- WritableMap event = getMarkerEventData(marker, dragPointX, dragPointY);
162
- event.putString("action", "marker-drag-end");
163
- manager.pushEvent(getContext(), view, "onMarkerDrag", event);
164
-
165
- event = getMarkerEventData(marker, dragPointX, dragPointY);
166
- event.putString("action", "marker-drag-end");
167
- manager.pushEvent(getContext(), rctMarker, "onDragEnd", event);
168
- }
169
-
170
- @Override
171
- public void onMarkerDragStart(MFMarker marker) {
172
- RMFMarker rctMarker = markerMap.get(marker);
173
- if (rctMarker == null) {
174
- return;
175
- }
176
- WritableMap event = getMarkerEventData(marker, touchPointX, touchPointY);
177
- event.putString("action", "marker-drag-start");
178
- manager.pushEvent(getContext(), view, "onMarkerDrag", event);
179
-
180
- event = getMarkerEventData(marker, touchPointX, touchPointY);
181
- event.putString("action", "marker-drag-start");
182
- manager.pushEvent(getContext(), rctMarker, "onDragStart", event);
183
- }
184
- }));
185
-
186
- markerCollection.setOnMarkerClickListener(new Map4D.OnMarkerClickListener() {
187
- @Override
188
- public boolean onMarkerClick(MFMarker marker) {
189
- RMFMarker rctMarker = markerMap.get(marker);
190
- if (rctMarker == null) {
191
- return false;
192
- }
193
- WritableMap event = getMarkerEventData(marker, touchPointX, touchPointY);
194
- event.putString("action", "marker-press");
195
- manager.pushEvent(getContext(), view, "onMarkerPress", event);
196
-
197
- event = getMarkerEventData(marker, touchPointX, touchPointY);
198
- event.putString("action", "marker-press");
199
- manager.pushEvent(getContext(), rctMarker, "onPress", event);
200
- return false;
201
- }
202
- });
203
-
204
- markerCollection.setOnInfoWindowClickListener(new Map4D.OnInfoWindowClickListener() {
205
- @Override
206
- public void onInfoWindowClick(@NonNull MFMarker marker) {
207
- RMFMarker rctMarker = markerMap.get(marker);
208
- if (rctMarker == null) {
209
- return;
210
- }
211
- WritableMap event = getMarkerEventData(marker, touchPointX, touchPointY);
212
- event.putString("action", "marker-info-window-press");
213
- manager.pushEvent(getContext(), rctMarker, "onPressInfoWindow", event);
214
- }
215
- });
216
-
217
- map.setOnPolylineClickListener(new Map4D.OnPolylineClickListener() {
218
- @Override
219
- public void onPolylineClick(MFPolyline polyline) {
220
- RMFPolyline rctPolyline = polylineMap.get(polyline);
221
- if (rctPolyline == null) {
222
- return;
223
- }
224
- WritableMap event = getPolylineEventData(polyline);
225
- event.putString("action", "polyline-press");
226
- manager.pushEvent(getContext(), rctPolyline, "onPress", event);
227
- }
228
- });
229
-
230
- map.setOnPolygonClickListener(new Map4D.OnPolygonClickListener() {
231
- @Override
232
- public void onPolygonClick(final MFPolygon polygon) {
233
- RMFPolygon rctPolygon = polygonMap.get(polygon);
234
- if (rctPolygon == null) {
235
- return;
236
- }
237
- WritableMap event = getPolygonEventData(polygon);
238
- event.putString("action", "polygon-press");
239
- manager.pushEvent(getContext(), rctPolygon, "onPress", event);
240
- }
241
- });
242
-
243
- map.setOnDirectionsClickListener(new Map4D.OnDirectionsClickListener() {
244
- @Override
245
- public void onDirectionsClick(MFDirectionsRenderer directionsRenderer, int i) {
246
- RMFDirectionsRenderer rctDirectionsRenderer = directionsRendererMap.get(directionsRenderer);
247
- if (rctDirectionsRenderer == null) {
248
- return;
249
- }
250
- WritableMap event = getDirectionsRendererEventData(directionsRenderer, i);
251
- event.putString("action", "directions-press");
252
- manager.pushEvent(getContext(), rctDirectionsRenderer, "onPress", event);
253
- }
254
- });
255
-
256
- map.setOnCircleClickListener(new Map4D.OnCircleClickListener() {
257
- @Override
258
- public void onCircleClick(MFCircle circle) {
259
- RMFCircle rctCircle = circleMap.get(circle);
260
- if (rctCircle == null) {
261
- return;
262
- }
263
-
264
- WritableMap event = getCircleEventData(circle);
265
- event.putString("action", "circle-press");
266
- manager.pushEvent(getContext(), rctCircle, "onPress", event);
267
- }
268
- });
269
-
270
- map.setOnUserBuildingClickListener(building -> {
271
- RMFBuilding rctBuilding = buildingMap.get(building);
272
- if (rctBuilding == null) {
273
- return;
274
- }
275
-
276
- WritableMap event = getBuildingEventData(building);
277
- event.putString("action", "building-press");
278
- manager.pushEvent(getContext(), rctBuilding, "onPress", event);
279
- });
280
-
281
- map.setOnUserPOIClickListener(new Map4D.OnUserPOIClickListener() {
282
- @Override
283
- public void onUserPOIClick(MFPOI poi) {
284
- RMFPOI rctPOI = poiMap.get(poi.getId());
285
- if (rctPOI == null) {
286
- return;
287
- }
288
-
289
- WritableMap event = getPOIEventData(poi);
290
- event.putString("action", "poi-press");
291
- manager.pushEvent(getContext(), rctPOI, "onPress", event);
292
- }
293
- });
294
-
295
- map.setOnPOIClickListener(new Map4D.OnPOIClickListener() {
296
- @Override
297
- public void onPOIClick(String placeId, String title, MFLocationCoordinate location) {
298
- WritableMap event = new WritableNativeMap();
299
- WritableMap locationMap = new WritableNativeMap();
300
-
301
- event.putString("action", "map-poi-press");
302
-
303
- WritableMap poiData = new WritableNativeMap();
304
- poiData.putString("id", placeId);
305
- poiData.putString("title", title);
306
- WritableMap poiLocation = new WritableNativeMap();
307
- poiLocation.putDouble("latitude", location.getLatitude());
308
- poiLocation.putDouble("longitude", location.getLongitude());
309
- poiData.putMap("location", poiLocation);
310
-
311
- WritableMap screenCoordinate = new WritableNativeMap();
312
- screenCoordinate.putDouble("x", touchPointX);
313
- screenCoordinate.putDouble("y", touchPointY);
314
-
315
- MFLocationCoordinate coordinate =
316
- map.getProjection().coordinateForPoint(
317
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
318
- );
319
-
320
- locationMap.putDouble("latitude", coordinate.getLatitude());
321
- locationMap.putDouble("longitude", coordinate.getLongitude());
322
-
323
- event.putMap("poi", poiData);
324
- event.putMap("location", locationMap);
325
- event.putMap("pixel", screenCoordinate);
326
-
327
- manager.pushEvent(getContext(), view, "onPoiPress", event);
328
- }
329
- });
330
-
331
- map.setOnBuildingClickListener(new Map4D.OnBuildingClickListener() {
332
- @Override
333
- public void onBuildingClick(String buildingId, String name, MFLocationCoordinate location) {
334
- WritableMap event = new WritableNativeMap();
335
- WritableMap locationMap = new WritableNativeMap();
336
-
337
- event.putString("action", "map-building-press");
338
-
339
- WritableMap buildingData = new WritableNativeMap();
340
- buildingData.putString("id", buildingId);
341
- buildingData.putString("name", name);
342
- WritableMap buildingLocation = new WritableNativeMap();
343
- buildingLocation.putDouble("latitude", location.getLatitude());
344
- buildingLocation.putDouble("longitude", location.getLongitude());
345
- buildingData.putMap("location", buildingLocation);
346
-
347
- WritableMap screenCoordinate = new WritableNativeMap();
348
- screenCoordinate.putDouble("x", touchPointX);
349
- screenCoordinate.putDouble("y", touchPointY);
350
-
351
- MFLocationCoordinate coordinate =
352
- map.getProjection().coordinateForPoint(
353
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
354
- );
355
-
356
- locationMap.putDouble("latitude", coordinate.getLatitude());
357
- locationMap.putDouble("longitude", coordinate.getLongitude());
358
-
359
- event.putMap("building", buildingData);
360
- event.putMap("location", locationMap);
361
- event.putMap("pixel", screenCoordinate);
362
-
363
- manager.pushEvent(getContext(), view, "onBuildingPress", event);
364
- }
365
- });
366
-
367
- map.setOnPlaceClickListener(new Map4D.OnPlaceClickListener() {
368
- @Override
369
- public void onPlaceClick(@NonNull String name, @NonNull MFLocationCoordinate location) {
370
- WritableMap event = new WritableNativeMap();
371
- WritableMap locationMap = new WritableNativeMap();
372
- event.putString("action", "map-place-press");
373
-
374
- WritableMap placeData = new WritableNativeMap();
375
- placeData.putString("name", name);
376
- WritableMap placeLocation = new WritableNativeMap();
377
- placeLocation.putDouble("latitude", location.getLatitude());
378
- placeLocation.putDouble("longitude", location.getLongitude());
379
- placeData.putMap("location", placeLocation);
380
-
381
- WritableMap screenCoordinate = new WritableNativeMap();
382
- screenCoordinate.putDouble("x", touchPointX);
383
- screenCoordinate.putDouble("y", touchPointY);
384
-
385
- MFLocationCoordinate coordinate =
386
- map.getProjection().coordinateForPoint(
387
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
388
- );
389
-
390
- locationMap.putDouble("latitude", coordinate.getLatitude());
391
- locationMap.putDouble("longitude", coordinate.getLongitude());
392
-
393
- event.putMap("place", placeData);
394
- event.putMap("location", locationMap);
395
- event.putMap("pixel", screenCoordinate);
396
-
397
- manager.pushEvent(getContext(), view, "onPlacePress", event);
398
- }
399
- });
400
-
401
- map.setOnDataSourceFeatureClickListener(new Map4D.OnDataSourceFeatureClickListener() {
402
- @Override
403
- public void onDataSourceFeatureClick(@NonNull MFDataSourceFeature dataSourceFeature,
404
- @NonNull MFLocationCoordinate location) {
405
- WritableMap event = new WritableNativeMap();
406
- event.putString("action", "data-source-feature-press");
407
- MFLocationCoordinate coordinate =
408
- map.getProjection().coordinateForPoint(
409
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
410
- );
411
- WritableMap locationMap = new WritableNativeMap();
412
- locationMap.putDouble("latitude", coordinate.getLatitude());
413
- locationMap.putDouble("longitude", coordinate.getLongitude());
414
- event.putMap("location", locationMap);
415
-
416
- WritableMap screenCoordinate = new WritableNativeMap();
417
- screenCoordinate.putDouble("x", touchPointX);
418
- screenCoordinate.putDouble("y", touchPointY);
419
- event.putMap("pixel", screenCoordinate);
420
-
421
- WritableMap feature = new WritableNativeMap();
422
-
423
- feature.putString("source", dataSourceFeature.getSource());
424
- feature.putString("sourceLayer", dataSourceFeature.getSourceLayer());
425
- feature.putString("layerType", dataSourceFeature.getLayerType());
426
-
427
- WritableMap propertiesMap = new WritableNativeMap();
428
- Map<String, Object> properties = dataSourceFeature.getProperties();
429
- for (String key: properties.keySet()) {
430
- Object value = properties.get(key);
431
- if (value instanceof String) {
432
- propertiesMap.putString(key, (String) value);
433
- }
434
- else if (value instanceof Boolean) {
435
- propertiesMap.putBoolean(key, (Boolean) value);
436
- }
437
- else if (value instanceof Integer) {
438
- propertiesMap.putInt(key, (Integer) value);
439
- }
440
- else if (value instanceof Double) {
441
- propertiesMap.putDouble(key, (Double) value);
442
- }
443
- }
444
- feature.putMap("properties", propertiesMap);
445
-
446
- WritableMap featureLocation = new WritableNativeMap();
447
- featureLocation.putDouble("latitude", location.getLatitude());
448
- featureLocation.putDouble("longitude", location.getLongitude());
449
- feature.putMap("location", featureLocation);
450
-
451
- event.putMap("feature", feature);
452
- manager.pushEvent(getContext(), view, "onDataSourceFeaturePress", event);
453
- }
454
- });
455
-
456
- map.setOnMapClickListener(new Map4D.OnMapClickListener() {
457
- @Override
458
- public void onMapClick(MFLocationCoordinate mfLocationCoordinate) {
459
- WritableMap event = new WritableNativeMap();
460
- WritableMap location = new WritableNativeMap();
461
- event.putString("action", "map-press");
462
- location.putDouble("latitude", mfLocationCoordinate.getLatitude());
463
- location.putDouble("longitude", mfLocationCoordinate.getLongitude());
464
-
465
- WritableMap screenCoordinate = new WritableNativeMap();
466
- screenCoordinate.putDouble("x", touchPointX);
467
- screenCoordinate.putDouble("y", touchPointY);
468
-
469
- event.putMap("location", location);
470
- event.putMap("pixel", screenCoordinate);
471
- manager.pushEvent(getContext(), view, "onPress", event);
472
- }
473
- });
474
-
475
- map.setOnCameraMoveListener(new Map4D.OnCameraMoveListener() {
476
- @Override
477
- public void onCameraMove() {
478
- WritableMap event = getCameraMap();
479
- event.putString("action", "camera-move");
480
- manager.pushEvent(getContext(), view, "onCameraMove", event);
481
- }
482
- });
483
-
484
- map.setOnCameraIdleListener(new Map4D.OnCameraIdleListener() {
485
- @Override
486
- public void onCameraIdle() {
487
- WritableMap event = getCameraMap();
488
- event.putString("action", "camera-idle");
489
- manager.pushEvent(getContext(), view, "onCameraIdle", event);
490
- }
491
- });
492
-
493
- map.setOnCameraMoveStartedListener(new Map4D.OnCameraMoveStartedListener() {
494
- @Override
495
- public void onCameraMoveStarted(int reason) {
496
- WritableMap event = getCameraMap();
497
- event.putString("action", "camera-move-started");
498
- event.putBoolean("gesture", reason == 1);
499
- manager.pushEvent(getContext(), view, "onCameraMoveStart", event);
500
- }
501
- });
502
-
503
- map.setOnMyLocationButtonClickListener(new Map4D.OnMyLocationButtonClickListener() {
504
- @Override
505
- public boolean onMyLocationButtonClick() {
506
- WritableMap event = new WritableNativeMap();
507
- event.putString("action", "my-location-button-press");
508
- manager.pushEvent(getContext(), view, "onMyLocationButtonPress", event);
509
- return false;
510
- }
511
- });
512
-
513
- // We need to be sure to disable location-tracking when app enters background, in-case some
514
- // other module
515
- // has acquired a wake-lock and is controlling location-updates, otherwise, location-manager
516
- // will be left
517
- // updating location constantly, killing the battery, even though some other location-mgmt
518
- // module may
519
- // desire to shut-down location-services.
520
- lifecycleListener = new LifecycleEventListener() {
521
- @Override
522
- public void onHostResume() {
523
- if (hasPermissions() && map != null) {
524
- //noinspection MissingPermission
525
- map.setMyLocationEnabled(showUserLocation);
526
- }
527
- synchronized (RMFMapView.this) {
528
- if (!destroyed) {
529
- RMFMapView.this.onStart();
530
- }
531
- paused = false;
532
- }
533
- }
534
-
535
- @Override
536
- public void onHostPause() {
537
- if (hasPermissions() && map != null) {
538
- //noinspection MissingPermission
539
- map.setMyLocationEnabled(false);
540
- }
541
- synchronized (RMFMapView.this) {
542
- if (!destroyed) {
543
- RMFMapView.this.onStop();
544
- }
545
- paused = true;
546
- }
547
- }
548
-
549
- @Override
550
- public void onHostDestroy() {
551
- RMFMapView.this.doDestroy();
552
- }
553
- };
554
-
555
- context.addLifecycleEventListener(lifecycleListener);
556
- }
557
-
558
- private boolean hasPermissions() {
559
- return checkSelfPermission(getContext(), PERMISSIONS[0]) == PermissionChecker.PERMISSION_GRANTED ||
560
- checkSelfPermission(getContext(), PERMISSIONS[1]) == PermissionChecker.PERMISSION_GRANTED;
561
- }
562
-
563
- public synchronized void doDestroy() {
564
- if (destroyed) {
565
- return;
566
- }
567
- destroyed = true;
568
-
569
- if (lifecycleListener != null && context != null) {
570
- context.removeLifecycleEventListener(lifecycleListener);
571
- lifecycleListener = null;
572
- }
573
- if (!paused) {
574
- onStop();
575
- paused = true;
576
- }
577
- map = null;
578
- onDestroy();
579
- }
580
-
581
- private WritableMap getCircleEventData(MFCircle circle) {
582
- WritableMap event = new WritableNativeMap();
583
- WritableMap location = new WritableNativeMap();
584
-
585
- WritableMap circleData = new WritableNativeMap();
586
- WritableMap circleCenter = new WritableNativeMap();
587
- circleCenter.putDouble("latitude", circle.getCenter().getLatitude());
588
- circleCenter.putDouble("longitude", circle.getCenter().getLongitude());
589
- circleData.putMap("center", circleCenter);
590
- circleData.putDouble("radius", circle.getRadius());
591
- Object userData = circle.getUserData();
592
- if (userData != null) {
593
- String userDataByString = "";
594
- userDataByString = userData.toString();
595
- int begin = userDataByString.indexOf(":") + 2;
596
- int end = userDataByString.length() - 2;
597
- userDataByString = userDataByString.substring(begin, end);
598
- circleData.putString("userData", userDataByString);
599
- }
600
- else {
601
- circleData.putMap("userData", new WritableNativeMap());
602
- }
603
-
604
- WritableMap screenCoordinate = new WritableNativeMap();
605
- screenCoordinate.putDouble("x", touchPointX);
606
- screenCoordinate.putDouble("y", touchPointY);
607
-
608
- MFLocationCoordinate coordinate =
609
- map.getProjection().coordinateForPoint(
610
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
611
- );
612
- location.putDouble("latitude", coordinate.getLatitude());
613
- location.putDouble("longitude", coordinate.getLongitude());
614
-
615
- event.putMap("circle", circleData);
616
- event.putMap("location", location);
617
- event.putMap("pixel", screenCoordinate);
618
-
619
- return event;
620
- }
621
-
622
- private WritableMap getPOIEventData(MFPOI poi) {
623
- WritableMap event = new WritableNativeMap();
624
- WritableMap location = new WritableNativeMap();
625
-
626
- WritableMap poiData = new WritableNativeMap();
627
- poiData.putString("title", poi.getTitle());
628
- WritableMap poiLocation = new WritableNativeMap();
629
- poiLocation.putDouble("latitude", poi.getPosition().getLatitude());
630
- poiLocation.putDouble("longitude", poi.getPosition().getLongitude());
631
- poiData.putMap("location", poiLocation);
632
- Object userData = poi.getUserData();
633
- if (userData != null) {
634
- String userDataByString = "";
635
- userDataByString = userData.toString();
636
- int begin = userDataByString.indexOf(":") + 2;
637
- int end = userDataByString.length() - 2;
638
- userDataByString = userDataByString.substring(begin, end);
639
- poiData.putString("userData", userDataByString);
640
- }
641
- else {
642
- poiData.putMap("userData", new WritableNativeMap());
643
- }
644
-
645
- WritableMap screenCoordinate = new WritableNativeMap();
646
- screenCoordinate.putDouble("x", touchPointX);
647
- screenCoordinate.putDouble("y", touchPointY);
648
-
649
- MFLocationCoordinate coordinate =
650
- map.getProjection().coordinateForPoint(
651
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
652
- );
653
- location.putDouble("latitude", coordinate.getLatitude());
654
- location.putDouble("longitude", coordinate.getLongitude());
655
-
656
- event.putMap("poi", poiData);
657
- event.putMap("location", location);
658
- event.putMap("pixel", screenCoordinate);
659
-
660
- return event;
661
- }
662
-
663
-
664
- private WritableMap getMarkerEventData(MFMarker marker, float touchPointX, float touchPointY) {
665
- WritableMap event = new WritableNativeMap();
666
- WritableMap location = new WritableNativeMap();
667
-
668
- WritableMap markerData = new WritableNativeMap();
669
- WritableMap markerLocation = new WritableNativeMap();
670
- markerLocation.putDouble("latitude", marker.getPosition().getLatitude());
671
- markerLocation.putDouble("longitude", marker.getPosition().getLongitude());
672
- markerData.putMap("location", markerLocation);
673
- Object userData = marker.getUserData();
674
- if (userData != null) {
675
- String userDataByString = "";
676
- userDataByString = userData.toString();
677
- int begin = userDataByString.indexOf(":") + 2;
678
- int end = userDataByString.length() - 2;
679
- userDataByString = userDataByString.substring(begin, end);
680
- markerData.putString("userData", userDataByString);
681
- }
682
- else {
683
- markerData.putMap("userData", new WritableNativeMap());
684
- }
685
-
686
- WritableMap screenCoordinate = new WritableNativeMap();
687
- screenCoordinate.putDouble("x", touchPointX);
688
- screenCoordinate.putDouble("y", touchPointY);
689
-
690
- MFLocationCoordinate coordinate =
691
- map.getProjection().coordinateForPoint(
692
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
693
- );
694
- location.putDouble("latitude", coordinate.getLatitude());
695
- location.putDouble("longitude", coordinate.getLongitude());
696
-
697
- event.putMap("marker", markerData);
698
- event.putMap("location", location);
699
- event.putMap("pixel", screenCoordinate);
700
-
701
- return event;
702
- }
703
-
704
- private WritableMap getPolylineEventData(MFPolyline polyline) {
705
- WritableMap event = new WritableNativeMap();
706
- WritableMap location = new WritableNativeMap();
707
-
708
- WritableMap polylineData = new WritableNativeMap();
709
- Object userData = polyline.getUserData();
710
- if (userData != null) {
711
- String userDataByString = "";
712
- userDataByString = userData.toString();
713
- int begin = userDataByString.indexOf(":") + 2;
714
- int end = userDataByString.length() - 2;
715
- userDataByString = userDataByString.substring(begin, end);
716
- polylineData.putString("userData", userDataByString);
717
- }
718
- else {
719
- polylineData.putMap("userData", new WritableNativeMap());
720
- }
721
-
722
- WritableMap screenCoordinate = new WritableNativeMap();
723
- screenCoordinate.putDouble("x", touchPointX);
724
- screenCoordinate.putDouble("y", touchPointY);
725
-
726
- MFLocationCoordinate coordinate =
727
- map.getProjection().coordinateForPoint(
728
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
729
- );
730
- location.putDouble("latitude", coordinate.getLatitude());
731
- location.putDouble("longitude", coordinate.getLongitude());
732
-
733
- event.putMap("polyline", polylineData);
734
- event.putMap("location", location);
735
- event.putMap("pixel", screenCoordinate);
736
-
737
- return event;
738
- }
739
-
740
- private WritableMap getPolygonEventData(MFPolygon polygon) {
741
- WritableMap event = new WritableNativeMap();
742
- WritableMap location = new WritableNativeMap();
743
-
744
- WritableMap polygonData = new WritableNativeMap();
745
- Object userData = polygon.getUserData();
746
- if (userData != null) {
747
- String userDataByString = "";
748
- userDataByString = userData.toString();
749
- int begin = userDataByString.indexOf(":") + 2;
750
- int end = userDataByString.length() - 2;
751
- userDataByString = userDataByString.substring(begin, end);
752
- polygonData.putString("userData", userDataByString);
753
- }
754
- else {
755
- polygonData.putMap("userData", new WritableNativeMap());
756
- }
757
-
758
- WritableMap screenCoordinate = new WritableNativeMap();
759
- screenCoordinate.putDouble("x", touchPointX);
760
- screenCoordinate.putDouble("y", touchPointY);
761
-
762
- MFLocationCoordinate coordinate =
763
- map.getProjection().coordinateForPoint(
764
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
765
- );
766
- location.putDouble("latitude", coordinate.getLatitude());
767
- location.putDouble("longitude", coordinate.getLongitude());
768
-
769
- event.putMap("polygon", polygonData);
770
- event.putMap("location", location);
771
- event.putMap("pixel", screenCoordinate);
772
-
773
- return event;
774
- }
775
-
776
- private WritableMap getDirectionsRendererEventData(MFDirectionsRenderer directionsRenderer, int i) {
777
- WritableMap event = new WritableNativeMap();
778
- WritableMap location = new WritableNativeMap();
779
-
780
- WritableMap screenCoordinate = new WritableNativeMap();
781
- screenCoordinate.putDouble("x", touchPointX);
782
- screenCoordinate.putDouble("y", touchPointY);
783
-
784
- MFLocationCoordinate coordinate =
785
- map.getProjection().coordinateForPoint(
786
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
787
- );
788
- location.putDouble("latitude", coordinate.getLatitude());
789
- location.putDouble("longitude", coordinate.getLongitude());
790
-
791
- event.putMap("location", location);
792
- event.putMap("pixel", screenCoordinate);
793
- event.putInt("routeIndex", i);
794
-
795
- return event;
796
- }
797
-
798
- private WritableMap getBuildingEventData(MFBuilding building) {
799
- WritableMap event = new WritableNativeMap();
800
- WritableMap location = new WritableNativeMap();
801
-
802
- WritableMap buildingData = new WritableNativeMap();
803
- buildingData.putString("name", building.getName());
804
- WritableMap buildingLocation = new WritableNativeMap();
805
- buildingLocation.putDouble("latitude", building.getLocation().getLatitude());
806
- buildingLocation.putDouble("longitude", building.getLocation().getLongitude());
807
- buildingData.putMap("location", buildingLocation);
808
- Object userData = building.getUserData();
809
- if (userData != null) {
810
- String userDataByString = "";
811
- userDataByString = userData.toString();
812
- int begin = userDataByString.indexOf(":") + 2;
813
- int end = userDataByString.length() - 2;
814
- userDataByString = userDataByString.substring(begin, end);
815
- buildingData.putString("userData", userDataByString);
816
- }
817
- else {
818
- buildingData.putMap("userData", new WritableNativeMap());
819
- }
820
-
821
- WritableMap screenCoordinate = new WritableNativeMap();
822
- screenCoordinate.putDouble("x", touchPointX);
823
- screenCoordinate.putDouble("y", touchPointY);
824
-
825
- MFLocationCoordinate coordinate =
826
- map.getProjection().coordinateForPoint(
827
- new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
828
- );
829
- location.putDouble("latitude", coordinate.getLatitude());
830
- location.putDouble("longitude", coordinate.getLongitude());
831
-
832
- event.putMap("building", buildingData);
833
- event.putMap("location", location);
834
- event.putMap("pixel", screenCoordinate);
835
-
836
- return event;
837
- }
838
-
839
- private WritableMap getCameraMap() {
840
- WritableMap event = new WritableNativeMap();
841
- MFCameraPosition pos = map.getCameraPosition();
842
- event.putDouble("zoom", pos.getZoom());
843
- event.putDouble("bearing", pos.getBearing());
844
- event.putDouble("tilt", pos.getTilt());
845
- WritableMap target = new WritableNativeMap();
846
- target.putDouble("latitude", pos.getTarget().getLatitude());
847
- target.putDouble("longitude", pos.getTarget().getLongitude());
848
- event.putMap("center", target);
849
- return event;
850
- }
851
-
852
- private MFCameraPosition parseCamera(ReadableMap camera) {
853
- MFCameraPosition.Builder builder = new MFCameraPosition.Builder(map.getCameraPosition());
854
- if (camera.hasKey("zoom")) {
855
- builder.zoom(camera.getDouble("zoom"));
856
- }
857
- if (camera.hasKey("bearing")) {
858
- builder.bearing(camera.getDouble("bearing"));
859
- }
860
- if (camera.hasKey("tilt")) {
861
- builder.tilt(camera.getDouble("tilt"));
862
- }
863
- if (camera.hasKey("center")) {
864
- ReadableMap center = camera.getMap("center");
865
- builder.target(new MFLocationCoordinate(center.getDouble("latitude"), center.getDouble("longitude")));
866
- }
867
- return builder.build();
868
- }
869
-
870
- public void moveCamera(ReadableMap camera) {
871
- if (map == null) return;
872
- MFCameraPosition cameraPosition = parseCamera(camera);
873
- MFCameraUpdate cameraUpdate = MFCameraUpdateFactory.newCameraPosition(cameraPosition);
874
- map.moveCamera(cameraUpdate);
875
- }
876
-
877
- public void animateCamera(ReadableMap camera) {
878
- if (map == null) return;
879
- MFCameraPosition cameraPosition = parseCamera(camera);
880
- MFCameraUpdate cameraUpdate = MFCameraUpdateFactory.newCameraPosition(cameraPosition);
881
- map.animateCamera(cameraUpdate);
882
- }
883
-
884
- public void setMapType(String mapType) {
885
- if (map == null) return;
886
- if (mapType.equals("roadmap")) {
887
- map.setMapType(MFMapType.ROADMAP);
888
- }
889
- else if (mapType.equals("satellite")) {
890
- map.setMapType(MFMapType.SATELLITE);
891
- }
892
- else if (mapType.equals("hybrid")) {
893
- map.setMapType(MFMapType.HYBRID);
894
- }
895
- }
896
-
897
- public void setMapId(String mapId) {
898
- if (map == null) return;
899
- map.setMapId(mapId);
900
- }
901
-
902
- public void setMapStyle(String style) {
903
- if (map == null) return;
904
- map.setMapStyle(new MFMapStyleOptions(style));
905
- }
906
-
907
- public void setZoomGesturesEnabled(boolean enable) {
908
- if (map == null) return;
909
- map.setZoomGesturesEnabled(enable);
910
- }
911
-
912
- public void setScrollGesturesEnabled(boolean enable) {
913
- if (map == null) return;
914
- map.setScrollGesturesEnabled(enable);
915
- }
916
-
917
- public void setRotateGesturesEnabled(boolean enable) {
918
- if (map == null) return;
919
- map.setRotateGesturesEnabled(enable);
920
- }
921
-
922
- public void setTiltGesturesEnabled(boolean enable) {
923
- if (map == null) return;
924
- map.setTiltGesturesEnabled(enable);
925
- }
926
-
927
- public void setAllGesturesEnabled(boolean enable) {
928
- if (map == null) return;
929
- map.setAllGesturesEnabled(enable);
930
- }
931
-
932
- public void setPOIsEnabled(Boolean enable) {
933
- if (map == null) return;
934
- map.setPOIsEnabled(enable);
935
- }
936
-
937
- public void setMyLocationEnabled(Boolean enable) {
938
- this.showUserLocation = enable; // hold onto this for lifecycle handling
939
- if (map == null) return;
940
- if (hasPermissions()) {
941
- map.setMyLocationEnabled(enable);
942
- }
943
- }
944
-
945
- public void setShowsMyLocationButton(boolean showMyLocationButton) {
946
- if (map == null) return;
947
- if (hasPermissions()) {
948
- map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
949
- }
950
- }
951
-
952
- public void setBuildingsEnabled(boolean buildingsEnable) {
953
- if (map == null) return;
954
- map.setBuildingsEnabled(buildingsEnable);
955
- }
956
-
957
- public void setTime(double time) {
958
- if (map == null) return;
959
- map.setTime(new Date((long) time));
960
- }
961
-
962
- public void fitBounds(ReadableMap boundData) {
963
- if (map == null) return;
964
- ReadableMap bounds = boundData.getMap("bounds");
965
- ReadableMap southWest = bounds.getMap("southWest");
966
- ReadableMap northEast = bounds.getMap("northEast");
967
-
968
- MFCoordinateBounds.Builder builder = new MFCoordinateBounds.Builder();
969
- double southWestLat = southWest.getDouble("latitude");
970
- double southWestLng = southWest.getDouble("longitude");
971
- builder.include(new MFLocationCoordinate(southWestLat, southWestLng));
972
-
973
- double northEastLat = northEast.getDouble("latitude");
974
- double northEastLng = northEast.getDouble("longitude");
975
- builder.include(new MFLocationCoordinate(northEastLat, northEastLng));
976
-
977
- int paddingDefault = 10;
978
- int paddingLeft = paddingDefault;
979
- int paddingRight = paddingDefault;
980
- int paddingTop = paddingDefault;
981
- int paddingBottom = paddingDefault;
982
- if (boundData.hasKey("padding")) {
983
- ReadableMap padding = boundData.getMap("padding");
984
- if (padding.hasKey("left")) {
985
- paddingLeft = padding.getInt("left");
986
- }
987
- if (padding.hasKey("right")) {
988
- paddingRight = padding.getInt("right");
989
- }
990
- if (padding.hasKey("top")) {
991
- paddingTop = padding.getInt("top");
992
- }
993
- if (padding.hasKey("bottom")) {
994
- paddingBottom = padding.getInt("bottom");
995
- }
996
- }
997
- MFCameraPosition cameraPosition = map.getCameraPositionForBounds(
998
- builder.build(), paddingLeft, paddingTop, paddingRight, paddingBottom);
999
- map.moveCamera(MFCameraUpdateFactory.newCameraPosition(cameraPosition));
1000
- }
1001
-
1002
- public void addFeature(View child, int index) {
1003
- if (child instanceof RMFMarker) {
1004
- RMFMarker annotation = (RMFMarker) child;
1005
- /** Must set marker collection first then add RMFMarker to map **/
1006
- annotation.setMarkerCollection(markerCollection);
1007
- annotation.addToMap(map);
1008
- features.add(index, annotation);
1009
-
1010
- // Remove from a view group if already present, prevent "specified child
1011
- // already had a parent" error.
1012
- ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1013
- if (annotationParent != null) {
1014
- annotationParent.removeView(annotation);
1015
- }
1016
-
1017
- // Add to the parent group
1018
- attacherGroup.addView(annotation);
1019
-
1020
- MFMarker marker = (MFMarker) annotation.getFeature();
1021
- markerMap.put(marker, annotation);
1022
- } else if (child instanceof RMFCircle) {
1023
- RMFCircle annotation = (RMFCircle) child;
1024
- annotation.addToMap(map);
1025
- features.add(index, annotation);
1026
-
1027
- // Remove from a view group if already present, prevent "specified child
1028
- // already had a parent" error.
1029
- ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1030
- if (annotationParent != null) {
1031
- annotationParent.removeView(annotation);
1032
- }
1033
-
1034
- MFCircle circle = (MFCircle) annotation.getFeature();
1035
- circleMap.put(circle, annotation);
1036
- } else if (child instanceof RMFPolyline) {
1037
- RMFPolyline annotation = (RMFPolyline) child;
1038
- annotation.addToMap(map);
1039
- features.add(index, annotation);
1040
-
1041
- // Remove from a view group if already present, prevent "specified child
1042
- // already had a parent" error.
1043
- ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1044
- if (annotationParent != null) {
1045
- annotationParent.removeView(annotation);
1046
- }
1047
-
1048
- MFPolyline polyline = (MFPolyline) annotation.getFeature();
1049
- polylineMap.put(polyline, annotation);
1050
- } else if (child instanceof RMFPolygon) {
1051
- RMFPolygon annotation = (RMFPolygon) child;
1052
- annotation.addToMap(map);
1053
- features.add(index, annotation);
1054
-
1055
- // Remove from a view group if already present, prevent "specified child
1056
- // already had a parent" error.
1057
- ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1058
- if (annotationParent != null) {
1059
- annotationParent.removeView(annotation);
1060
- }
1061
-
1062
- MFPolygon polygon = (MFPolygon) annotation.getFeature();
1063
- polygonMap.put(polygon, annotation);
1064
- } else if (child instanceof RMFBuilding) {
1065
- RMFBuilding annotation = (RMFBuilding) child;
1066
- annotation.addToMap(map);
1067
- features.add(index, annotation);
1068
-
1069
- // Remove from a view group if already present, prevent "specified child
1070
- // already had a parent" error.
1071
- ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1072
- if (annotationParent != null) {
1073
- annotationParent.removeView(annotation);
1074
- }
1075
-
1076
- MFBuilding building = (MFBuilding) annotation.getFeature();
1077
- buildingMap.put(building, annotation);
1078
- } else if (child instanceof RMFPOI) {
1079
- RMFPOI annotation = (RMFPOI) child;
1080
- annotation.addToMap(map);
1081
- features.add(index, annotation);
1082
-
1083
- // Remove from a view group if already present, prevent "specified child
1084
- // already had a parent" error.
1085
- ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1086
- if (annotationParent != null) {
1087
- annotationParent.removeView(annotation);
1088
- }
1089
-
1090
- MFPOI poi = (MFPOI) annotation.getFeature();
1091
- poiMap.put(poi.getId(), annotation);
1092
- }
1093
- else if (child instanceof RMFDirectionsRenderer) {
1094
- RMFDirectionsRenderer annotation = (RMFDirectionsRenderer) child;
1095
- annotation.addToMap(map);
1096
- features.add(index, annotation);
1097
-
1098
- // Remove from a view group if already present, prevent "specified child
1099
- // already had a parent" error.
1100
- ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1101
- if (annotationParent != null) {
1102
- annotationParent.removeView(annotation);
1103
- }
1104
-
1105
- MFDirectionsRenderer directionsRenderer = (MFDirectionsRenderer) annotation.getFeature();
1106
- directionsRendererMap.put(directionsRenderer, annotation);
1107
- }
1108
- else if (child instanceof RMFTileOverlay) {
1109
- RMFTileOverlay annotation = (RMFTileOverlay) child;
1110
- annotation.addToMap(map);
1111
- features.add(index, annotation);
1112
-
1113
- // Remove from a view group if already present, prevent "specified child
1114
- // already had a parent" error.
1115
- ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1116
- if (annotationParent != null) {
1117
- annotationParent.removeView(annotation);
1118
-
1119
- MFTileOverlay tileOverlay = (MFTileOverlay) annotation.getFeature();
1120
- tileOverlayMap.put(tileOverlay, annotation);
1121
- }
1122
- }
1123
- else if (child instanceof ViewGroup) {
1124
- ViewGroup children = (ViewGroup) child;
1125
- for (int i = 0; i < children.getChildCount(); i++) {
1126
- addFeature(children.getChildAt(i), index);
1127
- }
1128
- } else {
1129
- addView(child, index);
1130
- }
1131
- }
1132
-
1133
- public int getFeatureCount() {
1134
- return features.size();
1135
- }
1136
-
1137
- public View getFeatureAt(int index) {
1138
- return features.get(index);
1139
- }
1140
-
1141
- public void removeFeatureAt(int index) {
1142
- if (destroyed) {
1143
- return;
1144
- }
1145
- RMFFeature feature = features.remove(index);
1146
- if (feature instanceof RMFMarker) {
1147
- markerMap.remove(feature.getFeature());
1148
- } else if (feature instanceof RMFCircle) {
1149
- circleMap.remove(feature.getFeature());
1150
- }
1151
- else if (feature instanceof RMFPolyline) {
1152
- polylineMap.remove(feature.getFeature());
1153
- }
1154
- else if (feature instanceof RMFPolygon) {
1155
- polygonMap.remove(feature.getFeature());
1156
- }
1157
- else if (feature instanceof RMFBuilding) {
1158
- buildingMap.remove(feature.getFeature());
1159
- }
1160
- else if (feature instanceof RMFPOI) {
1161
- MFPOI poi = (MFPOI) feature.getFeature();
1162
- poiMap.remove(poi.getId());
1163
- }
1164
- else if (feature instanceof RMFTileOverlay) {
1165
- tileOverlayMap.remove(feature.getFeature());
1166
- }
1167
- else if (feature instanceof RMFDirectionsRenderer) {
1168
- directionsRendererMap.remove(feature.getFeature());
1169
- }
1170
- feature.removeFromMap(map);
1171
- }
1172
- }
1
+ package com.reactnativemap4dmap;
2
+
3
+ import static androidx.core.content.PermissionChecker.checkSelfPermission;
4
+
5
+ import android.content.Context;
6
+ import android.graphics.Point;
7
+ import android.view.MotionEvent;
8
+ import android.view.View;
9
+ import android.view.ViewGroup;
10
+
11
+ import androidx.annotation.NonNull;
12
+ import androidx.core.content.PermissionChecker;
13
+
14
+ import com.facebook.react.bridge.LifecycleEventListener;
15
+ import com.facebook.react.bridge.ReactApplicationContext;
16
+ import com.facebook.react.bridge.WritableMap;
17
+ import com.facebook.react.bridge.WritableNativeMap;
18
+ import com.facebook.react.bridge.ReadableMap;
19
+ import com.facebook.react.uimanager.ThemedReactContext;
20
+
21
+ import java.util.Date;
22
+ import java.util.ArrayList;
23
+ import java.util.HashMap;
24
+ import java.util.List;
25
+ import java.util.Map;
26
+
27
+ import vn.map4d.map.core.*;
28
+ import vn.map4d.map.camera.*;
29
+ import vn.map4d.map.annotations.*;
30
+ import vn.map4d.map.overlays.MFTileOverlay;
31
+ import vn.map4d.types.MFLocationCoordinate;
32
+ import vn.map4d.utils.android.collections.MFMarkerManager;
33
+
34
+ public class RMFMapView extends MFMapView implements OnMapReadyCallback {
35
+
36
+ public Map4D map;
37
+
38
+ private boolean showUserLocation = false;
39
+
40
+ private static final String[] PERMISSIONS = new String[]{
41
+ "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"};
42
+
43
+ private RMFMapViewManager manager;
44
+ private LifecycleEventListener lifecycleListener;
45
+ private boolean paused = false;
46
+ private boolean destroyed = false;
47
+ private final ThemedReactContext context;
48
+ private final List<RMFFeature> features = new ArrayList<>();
49
+ private final Map<MFMarker, RMFMarker> markerMap = new HashMap<>();
50
+ private final Map<MFCircle, RMFCircle> circleMap = new HashMap<>();
51
+ private final Map<MFPolyline, RMFPolyline> polylineMap = new HashMap<>();
52
+ private final Map<MFPolygon, RMFPolygon> polygonMap = new HashMap<>();
53
+ private final Map<MFBuilding, RMFBuilding> buildingMap = new HashMap<>();
54
+ private final Map<Long, RMFPOI> poiMap = new HashMap<>();
55
+ private final Map<MFTileOverlay, RMFTileOverlay> tileOverlayMap = new HashMap<>();
56
+ private final Map<MFDirectionsRenderer, RMFDirectionsRenderer> directionsRendererMap = new HashMap<>();
57
+
58
+ private MFMarkerManager.Collection markerCollection;
59
+
60
+ private ViewAttacherGroup attacherGroup;
61
+
62
+ private float touchPointX = 0.f;
63
+ private float touchPointY = 0.f;
64
+ private float dragPointX = 0.f;
65
+ private float dragPointY = 0.f;
66
+
67
+ private static boolean contextHasBug(Context context) {
68
+ return context == null ||
69
+ context.getResources() == null ||
70
+ context.getResources().getConfiguration() == null;
71
+ }
72
+
73
+ private static Context getNonBuggyContext(ThemedReactContext reactContext,
74
+ ReactApplicationContext appContext) {
75
+ Context superContext = reactContext;
76
+ if (!contextHasBug(appContext.getCurrentActivity())) {
77
+ superContext = appContext.getCurrentActivity();
78
+ } else if (contextHasBug(superContext)) {
79
+ // we have the bug! let's try to find a better context to use
80
+ if (!contextHasBug(reactContext.getCurrentActivity())) {
81
+ superContext = reactContext.getCurrentActivity();
82
+ } else if (!contextHasBug(reactContext.getApplicationContext())) {
83
+ superContext = reactContext.getApplicationContext();
84
+ } else {
85
+ }
86
+ }
87
+ return superContext;
88
+ }
89
+
90
+ public RMFMapView(ThemedReactContext reactContext, ReactApplicationContext appContext, RMFMapViewManager manager) {
91
+ super(getNonBuggyContext(reactContext, appContext), null);
92
+ this.manager = manager;
93
+ this.context = reactContext;
94
+
95
+ super.onCreate(null);
96
+ super.onStart();
97
+ this.getMapAsync(this);
98
+
99
+ // Set up a parent view for triggering visibility in subviews that depend on it.
100
+ // Mainly ReactImageView depends on Fresco which depends on onVisibilityChanged() event
101
+ attacherGroup = new ViewAttacherGroup(context);
102
+ LayoutParams attacherLayoutParams = new LayoutParams(0, 0);
103
+ attacherLayoutParams.width = 0;
104
+ attacherLayoutParams.height = 0;
105
+ attacherLayoutParams.leftMargin = 99999999;
106
+ attacherLayoutParams.topMargin = 99999999;
107
+ attacherGroup.setLayoutParams(attacherLayoutParams);
108
+ addView(attacherGroup);
109
+ }
110
+
111
+ @Override
112
+ public boolean onTouchEvent(MotionEvent event) {
113
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
114
+ touchPointX = event.getX();
115
+ touchPointY = event.getY();
116
+ }
117
+ if (event.getAction() == MotionEvent.ACTION_MOVE) {
118
+ dragPointX = event.getX();
119
+ dragPointY = event.getY();
120
+ }
121
+ return super.onTouchEvent(event);
122
+ }
123
+
124
+ @Override
125
+ public void onMapReady(final Map4D map) {
126
+ if (destroyed) {
127
+ return;
128
+ }
129
+ this.map = map;
130
+ final RMFMapView view = this;
131
+ MFMarkerManager markerManager = new MFMarkerManager(map);
132
+ markerCollection = markerManager.newCollection();
133
+
134
+ manager.pushEvent(getContext(), this, "onMapReady", new WritableNativeMap());
135
+
136
+ markerCollection.setOnMarkerDragListener((new Map4D.OnMarkerDragListener() {
137
+ @Override
138
+ public void onMarkerDrag(MFMarker marker) {
139
+ RMFMarker rctMarker = markerMap.get(marker);
140
+ if (rctMarker == null) {
141
+ return;
142
+ }
143
+
144
+ //Event for MFMapView
145
+ WritableMap event = getMarkerEventData(marker, dragPointX, dragPointY);
146
+ event.putString("action", "marker-drag");
147
+ manager.pushEvent(getContext(), view, "onMarkerDrag", event);
148
+
149
+ //Event for MFMarker
150
+ event = getMarkerEventData(marker, dragPointX, dragPointY);
151
+ event.putString("action", "marker-drag");
152
+ manager.pushEvent(getContext(), rctMarker, "onDrag", event);
153
+ }
154
+
155
+ @Override
156
+ public void onMarkerDragEnd(MFMarker marker) {
157
+ RMFMarker rctMarker = markerMap.get(marker);
158
+ if (rctMarker == null) {
159
+ return;
160
+ }
161
+ WritableMap event = getMarkerEventData(marker, dragPointX, dragPointY);
162
+ event.putString("action", "marker-drag-end");
163
+ manager.pushEvent(getContext(), view, "onMarkerDrag", event);
164
+
165
+ event = getMarkerEventData(marker, dragPointX, dragPointY);
166
+ event.putString("action", "marker-drag-end");
167
+ manager.pushEvent(getContext(), rctMarker, "onDragEnd", event);
168
+ }
169
+
170
+ @Override
171
+ public void onMarkerDragStart(MFMarker marker) {
172
+ RMFMarker rctMarker = markerMap.get(marker);
173
+ if (rctMarker == null) {
174
+ return;
175
+ }
176
+ WritableMap event = getMarkerEventData(marker, touchPointX, touchPointY);
177
+ event.putString("action", "marker-drag-start");
178
+ manager.pushEvent(getContext(), view, "onMarkerDrag", event);
179
+
180
+ event = getMarkerEventData(marker, touchPointX, touchPointY);
181
+ event.putString("action", "marker-drag-start");
182
+ manager.pushEvent(getContext(), rctMarker, "onDragStart", event);
183
+ }
184
+ }));
185
+
186
+ markerCollection.setOnMarkerClickListener(new Map4D.OnMarkerClickListener() {
187
+ @Override
188
+ public boolean onMarkerClick(MFMarker marker) {
189
+ RMFMarker rctMarker = markerMap.get(marker);
190
+ if (rctMarker == null) {
191
+ return false;
192
+ }
193
+ WritableMap event = getMarkerEventData(marker, touchPointX, touchPointY);
194
+ event.putString("action", "marker-press");
195
+ manager.pushEvent(getContext(), view, "onMarkerPress", event);
196
+
197
+ event = getMarkerEventData(marker, touchPointX, touchPointY);
198
+ event.putString("action", "marker-press");
199
+ manager.pushEvent(getContext(), rctMarker, "onPress", event);
200
+ return false;
201
+ }
202
+ });
203
+
204
+ markerCollection.setOnInfoWindowClickListener(new Map4D.OnInfoWindowClickListener() {
205
+ @Override
206
+ public void onInfoWindowClick(@NonNull MFMarker marker) {
207
+ RMFMarker rctMarker = markerMap.get(marker);
208
+ if (rctMarker == null) {
209
+ return;
210
+ }
211
+ WritableMap event = getMarkerEventData(marker, touchPointX, touchPointY);
212
+ event.putString("action", "marker-info-window-press");
213
+ manager.pushEvent(getContext(), rctMarker, "onPressInfoWindow", event);
214
+ }
215
+ });
216
+
217
+ map.setOnPolylineClickListener(new Map4D.OnPolylineClickListener() {
218
+ @Override
219
+ public void onPolylineClick(MFPolyline polyline) {
220
+ RMFPolyline rctPolyline = polylineMap.get(polyline);
221
+ if (rctPolyline == null) {
222
+ return;
223
+ }
224
+ WritableMap event = getPolylineEventData(polyline);
225
+ event.putString("action", "polyline-press");
226
+ manager.pushEvent(getContext(), rctPolyline, "onPress", event);
227
+ }
228
+ });
229
+
230
+ map.setOnPolygonClickListener(new Map4D.OnPolygonClickListener() {
231
+ @Override
232
+ public void onPolygonClick(final MFPolygon polygon) {
233
+ RMFPolygon rctPolygon = polygonMap.get(polygon);
234
+ if (rctPolygon == null) {
235
+ return;
236
+ }
237
+ WritableMap event = getPolygonEventData(polygon);
238
+ event.putString("action", "polygon-press");
239
+ manager.pushEvent(getContext(), rctPolygon, "onPress", event);
240
+ }
241
+ });
242
+
243
+ map.setOnDirectionsClickListener(new Map4D.OnDirectionsClickListener() {
244
+ @Override
245
+ public void onDirectionsClick(MFDirectionsRenderer directionsRenderer, int i) {
246
+ RMFDirectionsRenderer rctDirectionsRenderer = directionsRendererMap.get(directionsRenderer);
247
+ if (rctDirectionsRenderer == null) {
248
+ return;
249
+ }
250
+ WritableMap event = getDirectionsRendererEventData(directionsRenderer, i);
251
+ event.putString("action", "directions-press");
252
+ manager.pushEvent(getContext(), rctDirectionsRenderer, "onPress", event);
253
+ }
254
+ });
255
+
256
+ map.setOnCircleClickListener(new Map4D.OnCircleClickListener() {
257
+ @Override
258
+ public void onCircleClick(MFCircle circle) {
259
+ RMFCircle rctCircle = circleMap.get(circle);
260
+ if (rctCircle == null) {
261
+ return;
262
+ }
263
+
264
+ WritableMap event = getCircleEventData(circle);
265
+ event.putString("action", "circle-press");
266
+ manager.pushEvent(getContext(), rctCircle, "onPress", event);
267
+ }
268
+ });
269
+
270
+ map.setOnUserBuildingClickListener(building -> {
271
+ RMFBuilding rctBuilding = buildingMap.get(building);
272
+ if (rctBuilding == null) {
273
+ return;
274
+ }
275
+
276
+ WritableMap event = getBuildingEventData(building);
277
+ event.putString("action", "building-press");
278
+ manager.pushEvent(getContext(), rctBuilding, "onPress", event);
279
+ });
280
+
281
+ map.setOnUserPOIClickListener(new Map4D.OnUserPOIClickListener() {
282
+ @Override
283
+ public void onUserPOIClick(MFPOI poi) {
284
+ RMFPOI rctPOI = poiMap.get(poi.getId());
285
+ if (rctPOI == null) {
286
+ return;
287
+ }
288
+
289
+ WritableMap event = getPOIEventData(poi);
290
+ event.putString("action", "poi-press");
291
+ manager.pushEvent(getContext(), rctPOI, "onPress", event);
292
+ }
293
+ });
294
+
295
+ map.setOnPOIClickListener(new Map4D.OnPOIClickListener() {
296
+ @Override
297
+ public void onPOIClick(String placeId, String title, MFLocationCoordinate location) {
298
+ WritableMap event = new WritableNativeMap();
299
+ WritableMap locationMap = new WritableNativeMap();
300
+
301
+ event.putString("action", "map-poi-press");
302
+
303
+ WritableMap poiData = new WritableNativeMap();
304
+ poiData.putString("id", placeId);
305
+ poiData.putString("title", title);
306
+ WritableMap poiLocation = new WritableNativeMap();
307
+ poiLocation.putDouble("latitude", location.getLatitude());
308
+ poiLocation.putDouble("longitude", location.getLongitude());
309
+ poiData.putMap("location", poiLocation);
310
+
311
+ WritableMap screenCoordinate = new WritableNativeMap();
312
+ screenCoordinate.putDouble("x", touchPointX);
313
+ screenCoordinate.putDouble("y", touchPointY);
314
+
315
+ MFLocationCoordinate coordinate =
316
+ map.getProjection().coordinateForPoint(
317
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
318
+ );
319
+
320
+ locationMap.putDouble("latitude", coordinate.getLatitude());
321
+ locationMap.putDouble("longitude", coordinate.getLongitude());
322
+
323
+ event.putMap("poi", poiData);
324
+ event.putMap("location", locationMap);
325
+ event.putMap("pixel", screenCoordinate);
326
+
327
+ manager.pushEvent(getContext(), view, "onPoiPress", event);
328
+ }
329
+ });
330
+
331
+ map.setOnBuildingClickListener(new Map4D.OnBuildingClickListener() {
332
+ @Override
333
+ public void onBuildingClick(String buildingId, String name, MFLocationCoordinate location) {
334
+ WritableMap event = new WritableNativeMap();
335
+ WritableMap locationMap = new WritableNativeMap();
336
+
337
+ event.putString("action", "map-building-press");
338
+
339
+ WritableMap buildingData = new WritableNativeMap();
340
+ buildingData.putString("id", buildingId);
341
+ buildingData.putString("name", name);
342
+ WritableMap buildingLocation = new WritableNativeMap();
343
+ buildingLocation.putDouble("latitude", location.getLatitude());
344
+ buildingLocation.putDouble("longitude", location.getLongitude());
345
+ buildingData.putMap("location", buildingLocation);
346
+
347
+ WritableMap screenCoordinate = new WritableNativeMap();
348
+ screenCoordinate.putDouble("x", touchPointX);
349
+ screenCoordinate.putDouble("y", touchPointY);
350
+
351
+ MFLocationCoordinate coordinate =
352
+ map.getProjection().coordinateForPoint(
353
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
354
+ );
355
+
356
+ locationMap.putDouble("latitude", coordinate.getLatitude());
357
+ locationMap.putDouble("longitude", coordinate.getLongitude());
358
+
359
+ event.putMap("building", buildingData);
360
+ event.putMap("location", locationMap);
361
+ event.putMap("pixel", screenCoordinate);
362
+
363
+ manager.pushEvent(getContext(), view, "onBuildingPress", event);
364
+ }
365
+ });
366
+
367
+ map.setOnPlaceClickListener(new Map4D.OnPlaceClickListener() {
368
+ @Override
369
+ public void onPlaceClick(@NonNull String name, @NonNull MFLocationCoordinate location) {
370
+ WritableMap event = new WritableNativeMap();
371
+ WritableMap locationMap = new WritableNativeMap();
372
+ event.putString("action", "map-place-press");
373
+
374
+ WritableMap placeData = new WritableNativeMap();
375
+ placeData.putString("name", name);
376
+ WritableMap placeLocation = new WritableNativeMap();
377
+ placeLocation.putDouble("latitude", location.getLatitude());
378
+ placeLocation.putDouble("longitude", location.getLongitude());
379
+ placeData.putMap("location", placeLocation);
380
+
381
+ WritableMap screenCoordinate = new WritableNativeMap();
382
+ screenCoordinate.putDouble("x", touchPointX);
383
+ screenCoordinate.putDouble("y", touchPointY);
384
+
385
+ MFLocationCoordinate coordinate =
386
+ map.getProjection().coordinateForPoint(
387
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
388
+ );
389
+
390
+ locationMap.putDouble("latitude", coordinate.getLatitude());
391
+ locationMap.putDouble("longitude", coordinate.getLongitude());
392
+
393
+ event.putMap("place", placeData);
394
+ event.putMap("location", locationMap);
395
+ event.putMap("pixel", screenCoordinate);
396
+
397
+ manager.pushEvent(getContext(), view, "onPlacePress", event);
398
+ }
399
+ });
400
+
401
+ map.setOnDataSourceFeatureClickListener(new Map4D.OnDataSourceFeatureClickListener() {
402
+ @Override
403
+ public void onDataSourceFeatureClick(@NonNull MFDataSourceFeature dataSourceFeature,
404
+ @NonNull MFLocationCoordinate location) {
405
+ WritableMap event = new WritableNativeMap();
406
+ event.putString("action", "data-source-feature-press");
407
+ MFLocationCoordinate coordinate =
408
+ map.getProjection().coordinateForPoint(
409
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
410
+ );
411
+ WritableMap locationMap = new WritableNativeMap();
412
+ locationMap.putDouble("latitude", coordinate.getLatitude());
413
+ locationMap.putDouble("longitude", coordinate.getLongitude());
414
+ event.putMap("location", locationMap);
415
+
416
+ WritableMap screenCoordinate = new WritableNativeMap();
417
+ screenCoordinate.putDouble("x", touchPointX);
418
+ screenCoordinate.putDouble("y", touchPointY);
419
+ event.putMap("pixel", screenCoordinate);
420
+
421
+ WritableMap feature = new WritableNativeMap();
422
+
423
+ feature.putString("source", dataSourceFeature.getSource());
424
+ feature.putString("sourceLayer", dataSourceFeature.getSourceLayer());
425
+ feature.putString("layerType", dataSourceFeature.getLayerType());
426
+
427
+ WritableMap propertiesMap = new WritableNativeMap();
428
+ Map<String, Object> properties = dataSourceFeature.getProperties();
429
+ for (String key: properties.keySet()) {
430
+ Object value = properties.get(key);
431
+ if (value instanceof String) {
432
+ propertiesMap.putString(key, (String) value);
433
+ }
434
+ else if (value instanceof Boolean) {
435
+ propertiesMap.putBoolean(key, (Boolean) value);
436
+ }
437
+ else if (value instanceof Integer) {
438
+ propertiesMap.putInt(key, (Integer) value);
439
+ }
440
+ else if (value instanceof Double) {
441
+ propertiesMap.putDouble(key, (Double) value);
442
+ }
443
+ }
444
+ feature.putMap("properties", propertiesMap);
445
+
446
+ WritableMap featureLocation = new WritableNativeMap();
447
+ featureLocation.putDouble("latitude", location.getLatitude());
448
+ featureLocation.putDouble("longitude", location.getLongitude());
449
+ feature.putMap("location", featureLocation);
450
+
451
+ event.putMap("feature", feature);
452
+ manager.pushEvent(getContext(), view, "onDataSourceFeaturePress", event);
453
+ }
454
+ });
455
+
456
+ map.setOnMapClickListener(new Map4D.OnMapClickListener() {
457
+ @Override
458
+ public void onMapClick(MFLocationCoordinate mfLocationCoordinate) {
459
+ WritableMap event = new WritableNativeMap();
460
+ WritableMap location = new WritableNativeMap();
461
+ event.putString("action", "map-press");
462
+ location.putDouble("latitude", mfLocationCoordinate.getLatitude());
463
+ location.putDouble("longitude", mfLocationCoordinate.getLongitude());
464
+
465
+ WritableMap screenCoordinate = new WritableNativeMap();
466
+ screenCoordinate.putDouble("x", touchPointX);
467
+ screenCoordinate.putDouble("y", touchPointY);
468
+
469
+ event.putMap("location", location);
470
+ event.putMap("pixel", screenCoordinate);
471
+ manager.pushEvent(getContext(), view, "onPress", event);
472
+ }
473
+ });
474
+
475
+ map.setOnCameraMoveListener(new Map4D.OnCameraMoveListener() {
476
+ @Override
477
+ public void onCameraMove() {
478
+ WritableMap event = getCameraMap();
479
+ event.putString("action", "camera-move");
480
+ manager.pushEvent(getContext(), view, "onCameraMove", event);
481
+ }
482
+ });
483
+
484
+ map.setOnCameraIdleListener(new Map4D.OnCameraIdleListener() {
485
+ @Override
486
+ public void onCameraIdle() {
487
+ WritableMap event = getCameraMap();
488
+ event.putString("action", "camera-idle");
489
+ manager.pushEvent(getContext(), view, "onCameraIdle", event);
490
+ }
491
+ });
492
+
493
+ map.setOnCameraMoveStartedListener(new Map4D.OnCameraMoveStartedListener() {
494
+ @Override
495
+ public void onCameraMoveStarted(int reason) {
496
+ WritableMap event = getCameraMap();
497
+ event.putString("action", "camera-move-started");
498
+ event.putBoolean("gesture", reason == 1);
499
+ manager.pushEvent(getContext(), view, "onCameraMoveStart", event);
500
+ }
501
+ });
502
+
503
+ map.setOnMyLocationButtonClickListener(new Map4D.OnMyLocationButtonClickListener() {
504
+ @Override
505
+ public boolean onMyLocationButtonClick() {
506
+ WritableMap event = new WritableNativeMap();
507
+ event.putString("action", "my-location-button-press");
508
+ manager.pushEvent(getContext(), view, "onMyLocationButtonPress", event);
509
+ return false;
510
+ }
511
+ });
512
+
513
+ // We need to be sure to disable location-tracking when app enters background, in-case some
514
+ // other module
515
+ // has acquired a wake-lock and is controlling location-updates, otherwise, location-manager
516
+ // will be left
517
+ // updating location constantly, killing the battery, even though some other location-mgmt
518
+ // module may
519
+ // desire to shut-down location-services.
520
+ lifecycleListener = new LifecycleEventListener() {
521
+ @Override
522
+ public void onHostResume() {
523
+ if (hasPermissions() && map != null) {
524
+ //noinspection MissingPermission
525
+ map.setMyLocationEnabled(showUserLocation);
526
+ }
527
+ synchronized (RMFMapView.this) {
528
+ if (!destroyed) {
529
+ RMFMapView.this.onStart();
530
+ }
531
+ paused = false;
532
+ }
533
+ }
534
+
535
+ @Override
536
+ public void onHostPause() {
537
+ if (hasPermissions() && map != null) {
538
+ //noinspection MissingPermission
539
+ map.setMyLocationEnabled(false);
540
+ }
541
+ synchronized (RMFMapView.this) {
542
+ if (!destroyed) {
543
+ RMFMapView.this.onStop();
544
+ }
545
+ paused = true;
546
+ }
547
+ }
548
+
549
+ @Override
550
+ public void onHostDestroy() {
551
+ RMFMapView.this.doDestroy();
552
+ }
553
+ };
554
+
555
+ context.addLifecycleEventListener(lifecycleListener);
556
+ }
557
+
558
+ private boolean hasPermissions() {
559
+ return checkSelfPermission(getContext(), PERMISSIONS[0]) == PermissionChecker.PERMISSION_GRANTED ||
560
+ checkSelfPermission(getContext(), PERMISSIONS[1]) == PermissionChecker.PERMISSION_GRANTED;
561
+ }
562
+
563
+ public synchronized void doDestroy() {
564
+ if (destroyed) {
565
+ return;
566
+ }
567
+ destroyed = true;
568
+
569
+ if (lifecycleListener != null && context != null) {
570
+ context.removeLifecycleEventListener(lifecycleListener);
571
+ lifecycleListener = null;
572
+ }
573
+ if (!paused) {
574
+ onStop();
575
+ paused = true;
576
+ }
577
+ map = null;
578
+ onDestroy();
579
+ }
580
+
581
+ private WritableMap getCircleEventData(MFCircle circle) {
582
+ WritableMap event = new WritableNativeMap();
583
+ WritableMap location = new WritableNativeMap();
584
+
585
+ WritableMap circleData = new WritableNativeMap();
586
+ WritableMap circleCenter = new WritableNativeMap();
587
+ circleCenter.putDouble("latitude", circle.getCenter().getLatitude());
588
+ circleCenter.putDouble("longitude", circle.getCenter().getLongitude());
589
+ circleData.putMap("center", circleCenter);
590
+ circleData.putDouble("radius", circle.getRadius());
591
+ Object userData = circle.getUserData();
592
+ if (userData != null) {
593
+ String userDataByString = "";
594
+ userDataByString = userData.toString();
595
+ int begin = userDataByString.indexOf(":") + 2;
596
+ int end = userDataByString.length() - 2;
597
+ userDataByString = userDataByString.substring(begin, end);
598
+ circleData.putString("userData", userDataByString);
599
+ }
600
+ else {
601
+ circleData.putMap("userData", new WritableNativeMap());
602
+ }
603
+
604
+ WritableMap screenCoordinate = new WritableNativeMap();
605
+ screenCoordinate.putDouble("x", touchPointX);
606
+ screenCoordinate.putDouble("y", touchPointY);
607
+
608
+ MFLocationCoordinate coordinate =
609
+ map.getProjection().coordinateForPoint(
610
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
611
+ );
612
+ location.putDouble("latitude", coordinate.getLatitude());
613
+ location.putDouble("longitude", coordinate.getLongitude());
614
+
615
+ event.putMap("circle", circleData);
616
+ event.putMap("location", location);
617
+ event.putMap("pixel", screenCoordinate);
618
+
619
+ return event;
620
+ }
621
+
622
+ private WritableMap getPOIEventData(MFPOI poi) {
623
+ WritableMap event = new WritableNativeMap();
624
+ WritableMap location = new WritableNativeMap();
625
+
626
+ WritableMap poiData = new WritableNativeMap();
627
+ poiData.putString("title", poi.getTitle());
628
+ WritableMap poiLocation = new WritableNativeMap();
629
+ poiLocation.putDouble("latitude", poi.getPosition().getLatitude());
630
+ poiLocation.putDouble("longitude", poi.getPosition().getLongitude());
631
+ poiData.putMap("location", poiLocation);
632
+ Object userData = poi.getUserData();
633
+ if (userData != null) {
634
+ String userDataByString = "";
635
+ userDataByString = userData.toString();
636
+ int begin = userDataByString.indexOf(":") + 2;
637
+ int end = userDataByString.length() - 2;
638
+ userDataByString = userDataByString.substring(begin, end);
639
+ poiData.putString("userData", userDataByString);
640
+ }
641
+ else {
642
+ poiData.putMap("userData", new WritableNativeMap());
643
+ }
644
+
645
+ WritableMap screenCoordinate = new WritableNativeMap();
646
+ screenCoordinate.putDouble("x", touchPointX);
647
+ screenCoordinate.putDouble("y", touchPointY);
648
+
649
+ MFLocationCoordinate coordinate =
650
+ map.getProjection().coordinateForPoint(
651
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
652
+ );
653
+ location.putDouble("latitude", coordinate.getLatitude());
654
+ location.putDouble("longitude", coordinate.getLongitude());
655
+
656
+ event.putMap("poi", poiData);
657
+ event.putMap("location", location);
658
+ event.putMap("pixel", screenCoordinate);
659
+
660
+ return event;
661
+ }
662
+
663
+
664
+ private WritableMap getMarkerEventData(MFMarker marker, float touchPointX, float touchPointY) {
665
+ WritableMap event = new WritableNativeMap();
666
+ WritableMap location = new WritableNativeMap();
667
+
668
+ WritableMap markerData = new WritableNativeMap();
669
+ WritableMap markerLocation = new WritableNativeMap();
670
+ markerLocation.putDouble("latitude", marker.getPosition().getLatitude());
671
+ markerLocation.putDouble("longitude", marker.getPosition().getLongitude());
672
+ markerData.putMap("location", markerLocation);
673
+ Object userData = marker.getUserData();
674
+ if (userData != null) {
675
+ String userDataByString = "";
676
+ userDataByString = userData.toString();
677
+ int begin = userDataByString.indexOf(":") + 2;
678
+ int end = userDataByString.length() - 2;
679
+ userDataByString = userDataByString.substring(begin, end);
680
+ markerData.putString("userData", userDataByString);
681
+ }
682
+ else {
683
+ markerData.putMap("userData", new WritableNativeMap());
684
+ }
685
+
686
+ WritableMap screenCoordinate = new WritableNativeMap();
687
+ screenCoordinate.putDouble("x", touchPointX);
688
+ screenCoordinate.putDouble("y", touchPointY);
689
+
690
+ MFLocationCoordinate coordinate =
691
+ map.getProjection().coordinateForPoint(
692
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
693
+ );
694
+ location.putDouble("latitude", coordinate.getLatitude());
695
+ location.putDouble("longitude", coordinate.getLongitude());
696
+
697
+ event.putMap("marker", markerData);
698
+ event.putMap("location", location);
699
+ event.putMap("pixel", screenCoordinate);
700
+
701
+ return event;
702
+ }
703
+
704
+ private WritableMap getPolylineEventData(MFPolyline polyline) {
705
+ WritableMap event = new WritableNativeMap();
706
+ WritableMap location = new WritableNativeMap();
707
+
708
+ WritableMap polylineData = new WritableNativeMap();
709
+ Object userData = polyline.getUserData();
710
+ if (userData != null) {
711
+ String userDataByString = "";
712
+ userDataByString = userData.toString();
713
+ int begin = userDataByString.indexOf(":") + 2;
714
+ int end = userDataByString.length() - 2;
715
+ userDataByString = userDataByString.substring(begin, end);
716
+ polylineData.putString("userData", userDataByString);
717
+ }
718
+ else {
719
+ polylineData.putMap("userData", new WritableNativeMap());
720
+ }
721
+
722
+ WritableMap screenCoordinate = new WritableNativeMap();
723
+ screenCoordinate.putDouble("x", touchPointX);
724
+ screenCoordinate.putDouble("y", touchPointY);
725
+
726
+ MFLocationCoordinate coordinate =
727
+ map.getProjection().coordinateForPoint(
728
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
729
+ );
730
+ location.putDouble("latitude", coordinate.getLatitude());
731
+ location.putDouble("longitude", coordinate.getLongitude());
732
+
733
+ event.putMap("polyline", polylineData);
734
+ event.putMap("location", location);
735
+ event.putMap("pixel", screenCoordinate);
736
+
737
+ return event;
738
+ }
739
+
740
+ private WritableMap getPolygonEventData(MFPolygon polygon) {
741
+ WritableMap event = new WritableNativeMap();
742
+ WritableMap location = new WritableNativeMap();
743
+
744
+ WritableMap polygonData = new WritableNativeMap();
745
+ Object userData = polygon.getUserData();
746
+ if (userData != null) {
747
+ String userDataByString = "";
748
+ userDataByString = userData.toString();
749
+ int begin = userDataByString.indexOf(":") + 2;
750
+ int end = userDataByString.length() - 2;
751
+ userDataByString = userDataByString.substring(begin, end);
752
+ polygonData.putString("userData", userDataByString);
753
+ }
754
+ else {
755
+ polygonData.putMap("userData", new WritableNativeMap());
756
+ }
757
+
758
+ WritableMap screenCoordinate = new WritableNativeMap();
759
+ screenCoordinate.putDouble("x", touchPointX);
760
+ screenCoordinate.putDouble("y", touchPointY);
761
+
762
+ MFLocationCoordinate coordinate =
763
+ map.getProjection().coordinateForPoint(
764
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
765
+ );
766
+ location.putDouble("latitude", coordinate.getLatitude());
767
+ location.putDouble("longitude", coordinate.getLongitude());
768
+
769
+ event.putMap("polygon", polygonData);
770
+ event.putMap("location", location);
771
+ event.putMap("pixel", screenCoordinate);
772
+
773
+ return event;
774
+ }
775
+
776
+ private WritableMap getDirectionsRendererEventData(MFDirectionsRenderer directionsRenderer, int i) {
777
+ WritableMap event = new WritableNativeMap();
778
+ WritableMap location = new WritableNativeMap();
779
+
780
+ WritableMap screenCoordinate = new WritableNativeMap();
781
+ screenCoordinate.putDouble("x", touchPointX);
782
+ screenCoordinate.putDouble("y", touchPointY);
783
+
784
+ MFLocationCoordinate coordinate =
785
+ map.getProjection().coordinateForPoint(
786
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
787
+ );
788
+ location.putDouble("latitude", coordinate.getLatitude());
789
+ location.putDouble("longitude", coordinate.getLongitude());
790
+
791
+ event.putMap("location", location);
792
+ event.putMap("pixel", screenCoordinate);
793
+ event.putInt("routeIndex", i);
794
+
795
+ return event;
796
+ }
797
+
798
+ private WritableMap getBuildingEventData(MFBuilding building) {
799
+ WritableMap event = new WritableNativeMap();
800
+ WritableMap location = new WritableNativeMap();
801
+
802
+ WritableMap buildingData = new WritableNativeMap();
803
+ buildingData.putString("name", building.getName());
804
+ WritableMap buildingLocation = new WritableNativeMap();
805
+ buildingLocation.putDouble("latitude", building.getLocation().getLatitude());
806
+ buildingLocation.putDouble("longitude", building.getLocation().getLongitude());
807
+ buildingData.putMap("location", buildingLocation);
808
+ Object userData = building.getUserData();
809
+ if (userData != null) {
810
+ String userDataByString = "";
811
+ userDataByString = userData.toString();
812
+ int begin = userDataByString.indexOf(":") + 2;
813
+ int end = userDataByString.length() - 2;
814
+ userDataByString = userDataByString.substring(begin, end);
815
+ buildingData.putString("userData", userDataByString);
816
+ }
817
+ else {
818
+ buildingData.putMap("userData", new WritableNativeMap());
819
+ }
820
+
821
+ WritableMap screenCoordinate = new WritableNativeMap();
822
+ screenCoordinate.putDouble("x", touchPointX);
823
+ screenCoordinate.putDouble("y", touchPointY);
824
+
825
+ MFLocationCoordinate coordinate =
826
+ map.getProjection().coordinateForPoint(
827
+ new Point((int) (touchPointX / MapContext.getDensity()), (int) (touchPointY / MapContext.getDensity()))
828
+ );
829
+ location.putDouble("latitude", coordinate.getLatitude());
830
+ location.putDouble("longitude", coordinate.getLongitude());
831
+
832
+ event.putMap("building", buildingData);
833
+ event.putMap("location", location);
834
+ event.putMap("pixel", screenCoordinate);
835
+
836
+ return event;
837
+ }
838
+
839
+ private WritableMap getCameraMap() {
840
+ WritableMap event = new WritableNativeMap();
841
+ MFCameraPosition pos = map.getCameraPosition();
842
+ event.putDouble("zoom", pos.getZoom());
843
+ event.putDouble("bearing", pos.getBearing());
844
+ event.putDouble("tilt", pos.getTilt());
845
+ WritableMap target = new WritableNativeMap();
846
+ target.putDouble("latitude", pos.getTarget().getLatitude());
847
+ target.putDouble("longitude", pos.getTarget().getLongitude());
848
+ event.putMap("center", target);
849
+ return event;
850
+ }
851
+
852
+ private MFCameraPosition parseCamera(ReadableMap camera) {
853
+ MFCameraPosition.Builder builder = new MFCameraPosition.Builder(map.getCameraPosition());
854
+ if (camera.hasKey("zoom")) {
855
+ builder.zoom(camera.getDouble("zoom"));
856
+ }
857
+ if (camera.hasKey("bearing")) {
858
+ builder.bearing(camera.getDouble("bearing"));
859
+ }
860
+ if (camera.hasKey("tilt")) {
861
+ builder.tilt(camera.getDouble("tilt"));
862
+ }
863
+ if (camera.hasKey("center")) {
864
+ ReadableMap center = camera.getMap("center");
865
+ builder.target(new MFLocationCoordinate(center.getDouble("latitude"), center.getDouble("longitude")));
866
+ }
867
+ return builder.build();
868
+ }
869
+
870
+ public void moveCamera(ReadableMap camera) {
871
+ if (map == null) return;
872
+ MFCameraPosition cameraPosition = parseCamera(camera);
873
+ MFCameraUpdate cameraUpdate = MFCameraUpdateFactory.newCameraPosition(cameraPosition);
874
+ map.moveCamera(cameraUpdate);
875
+ }
876
+
877
+ public void animateCamera(ReadableMap camera) {
878
+ if (map == null) return;
879
+ MFCameraPosition cameraPosition = parseCamera(camera);
880
+ MFCameraUpdate cameraUpdate = MFCameraUpdateFactory.newCameraPosition(cameraPosition);
881
+ map.animateCamera(cameraUpdate);
882
+ }
883
+
884
+ public void setMapType(String mapType) {
885
+ if (map == null) return;
886
+ if (mapType.equals("roadmap")) {
887
+ map.setMapType(MFMapType.ROADMAP);
888
+ }
889
+ else if (mapType.equals("satellite")) {
890
+ map.setMapType(MFMapType.SATELLITE);
891
+ }
892
+ else if (mapType.equals("hybrid")) {
893
+ map.setMapType(MFMapType.HYBRID);
894
+ }
895
+ }
896
+
897
+ public void setMapId(String mapId) {
898
+ if (map == null) return;
899
+ map.setMapId(mapId);
900
+ }
901
+
902
+ public void setMapStyle(String style) {
903
+ if (map == null) return;
904
+ map.setMapStyle(new MFMapStyleOptions(style));
905
+ }
906
+
907
+ public void setZoomGesturesEnabled(boolean enable) {
908
+ if (map == null) return;
909
+ map.setZoomGesturesEnabled(enable);
910
+ }
911
+
912
+ public void setScrollGesturesEnabled(boolean enable) {
913
+ if (map == null) return;
914
+ map.setScrollGesturesEnabled(enable);
915
+ }
916
+
917
+ public void setRotateGesturesEnabled(boolean enable) {
918
+ if (map == null) return;
919
+ map.setRotateGesturesEnabled(enable);
920
+ }
921
+
922
+ public void setTiltGesturesEnabled(boolean enable) {
923
+ if (map == null) return;
924
+ map.setTiltGesturesEnabled(enable);
925
+ }
926
+
927
+ public void setAllGesturesEnabled(boolean enable) {
928
+ if (map == null) return;
929
+ map.setAllGesturesEnabled(enable);
930
+ }
931
+
932
+ public void setPOIsEnabled(Boolean enable) {
933
+ if (map == null) return;
934
+ map.setPOIsEnabled(enable);
935
+ }
936
+
937
+ public void setMyLocationEnabled(Boolean enable) {
938
+ this.showUserLocation = enable; // hold onto this for lifecycle handling
939
+ if (map == null) return;
940
+ if (hasPermissions()) {
941
+ map.setMyLocationEnabled(enable);
942
+ }
943
+ }
944
+
945
+ public void setShowsMyLocationButton(boolean showMyLocationButton) {
946
+ if (map == null) return;
947
+ if (hasPermissions()) {
948
+ map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
949
+ }
950
+ }
951
+
952
+ public void setBuildingsEnabled(boolean buildingsEnable) {
953
+ if (map == null) return;
954
+ map.setBuildingsEnabled(buildingsEnable);
955
+ }
956
+
957
+ public void setTime(double time) {
958
+ if (map == null) return;
959
+ map.setTime(new Date((long) time));
960
+ }
961
+
962
+ public void fitBounds(ReadableMap boundData) {
963
+ if (map == null) return;
964
+ ReadableMap bounds = boundData.getMap("bounds");
965
+ ReadableMap southWest = bounds.getMap("southWest");
966
+ ReadableMap northEast = bounds.getMap("northEast");
967
+
968
+ MFCoordinateBounds.Builder builder = new MFCoordinateBounds.Builder();
969
+ double southWestLat = southWest.getDouble("latitude");
970
+ double southWestLng = southWest.getDouble("longitude");
971
+ builder.include(new MFLocationCoordinate(southWestLat, southWestLng));
972
+
973
+ double northEastLat = northEast.getDouble("latitude");
974
+ double northEastLng = northEast.getDouble("longitude");
975
+ builder.include(new MFLocationCoordinate(northEastLat, northEastLng));
976
+
977
+ int paddingDefault = 10;
978
+ int paddingLeft = paddingDefault;
979
+ int paddingRight = paddingDefault;
980
+ int paddingTop = paddingDefault;
981
+ int paddingBottom = paddingDefault;
982
+ if (boundData.hasKey("padding")) {
983
+ ReadableMap padding = boundData.getMap("padding");
984
+ if (padding.hasKey("left")) {
985
+ paddingLeft = padding.getInt("left");
986
+ }
987
+ if (padding.hasKey("right")) {
988
+ paddingRight = padding.getInt("right");
989
+ }
990
+ if (padding.hasKey("top")) {
991
+ paddingTop = padding.getInt("top");
992
+ }
993
+ if (padding.hasKey("bottom")) {
994
+ paddingBottom = padding.getInt("bottom");
995
+ }
996
+ }
997
+ MFCameraPosition cameraPosition = map.getCameraPositionForBounds(
998
+ builder.build(), paddingLeft, paddingTop, paddingRight, paddingBottom);
999
+ map.moveCamera(MFCameraUpdateFactory.newCameraPosition(cameraPosition));
1000
+ }
1001
+
1002
+ public void addFeature(View child, int index) {
1003
+ if (child instanceof RMFMarker) {
1004
+ RMFMarker annotation = (RMFMarker) child;
1005
+ /** Must set marker collection first then add RMFMarker to map **/
1006
+ annotation.setMarkerCollection(markerCollection);
1007
+ annotation.addToMap(map);
1008
+ features.add(index, annotation);
1009
+
1010
+ // Remove from a view group if already present, prevent "specified child
1011
+ // already had a parent" error.
1012
+ ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1013
+ if (annotationParent != null) {
1014
+ annotationParent.removeView(annotation);
1015
+ }
1016
+
1017
+ // Add to the parent group
1018
+ attacherGroup.addView(annotation);
1019
+
1020
+ MFMarker marker = (MFMarker) annotation.getFeature();
1021
+ markerMap.put(marker, annotation);
1022
+ } else if (child instanceof RMFCircle) {
1023
+ RMFCircle annotation = (RMFCircle) child;
1024
+ annotation.addToMap(map);
1025
+ features.add(index, annotation);
1026
+
1027
+ // Remove from a view group if already present, prevent "specified child
1028
+ // already had a parent" error.
1029
+ ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1030
+ if (annotationParent != null) {
1031
+ annotationParent.removeView(annotation);
1032
+ }
1033
+
1034
+ MFCircle circle = (MFCircle) annotation.getFeature();
1035
+ circleMap.put(circle, annotation);
1036
+ } else if (child instanceof RMFPolyline) {
1037
+ RMFPolyline annotation = (RMFPolyline) child;
1038
+ annotation.addToMap(map);
1039
+ features.add(index, annotation);
1040
+
1041
+ // Remove from a view group if already present, prevent "specified child
1042
+ // already had a parent" error.
1043
+ ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1044
+ if (annotationParent != null) {
1045
+ annotationParent.removeView(annotation);
1046
+ }
1047
+
1048
+ MFPolyline polyline = (MFPolyline) annotation.getFeature();
1049
+ polylineMap.put(polyline, annotation);
1050
+ } else if (child instanceof RMFPolygon) {
1051
+ RMFPolygon annotation = (RMFPolygon) child;
1052
+ annotation.addToMap(map);
1053
+ features.add(index, annotation);
1054
+
1055
+ // Remove from a view group if already present, prevent "specified child
1056
+ // already had a parent" error.
1057
+ ViewGroup annotationParent = (ViewGroup)annotation.getParent();
1058
+ if (annotationParent != null) {
1059
+ annotationParent.removeView(annotation);
1060
+ }
1061
+
1062
+ MFPolygon polygon = (MFPolygon) annotation.getFeature();
1063
+ polygonMap.put(polygon, annotation);
1064
+ } else if (child instanceof RMFBuilding) {
1065
+ RMFBuilding annotation = (RMFBuilding) child;
1066
+ annotation.addToMap(map);
1067
+ features.add(index, annotation);
1068
+
1069
+ // Remove from a view group if already present, prevent "specified child
1070
+ // already had a parent" error.
1071
+ ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1072
+ if (annotationParent != null) {
1073
+ annotationParent.removeView(annotation);
1074
+ }
1075
+
1076
+ MFBuilding building = (MFBuilding) annotation.getFeature();
1077
+ buildingMap.put(building, annotation);
1078
+ } else if (child instanceof RMFPOI) {
1079
+ RMFPOI annotation = (RMFPOI) child;
1080
+ annotation.addToMap(map);
1081
+ features.add(index, annotation);
1082
+
1083
+ // Remove from a view group if already present, prevent "specified child
1084
+ // already had a parent" error.
1085
+ ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1086
+ if (annotationParent != null) {
1087
+ annotationParent.removeView(annotation);
1088
+ }
1089
+
1090
+ MFPOI poi = (MFPOI) annotation.getFeature();
1091
+ poiMap.put(poi.getId(), annotation);
1092
+ }
1093
+ else if (child instanceof RMFDirectionsRenderer) {
1094
+ RMFDirectionsRenderer annotation = (RMFDirectionsRenderer) child;
1095
+ annotation.addToMap(map);
1096
+ features.add(index, annotation);
1097
+
1098
+ // Remove from a view group if already present, prevent "specified child
1099
+ // already had a parent" error.
1100
+ ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1101
+ if (annotationParent != null) {
1102
+ annotationParent.removeView(annotation);
1103
+ }
1104
+
1105
+ MFDirectionsRenderer directionsRenderer = (MFDirectionsRenderer) annotation.getFeature();
1106
+ directionsRendererMap.put(directionsRenderer, annotation);
1107
+ }
1108
+ else if (child instanceof RMFTileOverlay) {
1109
+ RMFTileOverlay annotation = (RMFTileOverlay) child;
1110
+ annotation.addToMap(map);
1111
+ features.add(index, annotation);
1112
+
1113
+ // Remove from a view group if already present, prevent "specified child
1114
+ // already had a parent" error.
1115
+ ViewGroup annotationParent = (ViewGroup) annotation.getParent();
1116
+ if (annotationParent != null) {
1117
+ annotationParent.removeView(annotation);
1118
+
1119
+ MFTileOverlay tileOverlay = (MFTileOverlay) annotation.getFeature();
1120
+ tileOverlayMap.put(tileOverlay, annotation);
1121
+ }
1122
+ }
1123
+ else if (child instanceof ViewGroup) {
1124
+ ViewGroup children = (ViewGroup) child;
1125
+ for (int i = 0; i < children.getChildCount(); i++) {
1126
+ addFeature(children.getChildAt(i), index);
1127
+ }
1128
+ } else {
1129
+ addView(child, index);
1130
+ }
1131
+ }
1132
+
1133
+ public int getFeatureCount() {
1134
+ return features.size();
1135
+ }
1136
+
1137
+ public View getFeatureAt(int index) {
1138
+ return features.get(index);
1139
+ }
1140
+
1141
+ public void removeFeatureAt(int index) {
1142
+ if (destroyed) {
1143
+ return;
1144
+ }
1145
+ RMFFeature feature = features.remove(index);
1146
+ if (feature instanceof RMFMarker) {
1147
+ markerMap.remove(feature.getFeature());
1148
+ } else if (feature instanceof RMFCircle) {
1149
+ circleMap.remove(feature.getFeature());
1150
+ }
1151
+ else if (feature instanceof RMFPolyline) {
1152
+ polylineMap.remove(feature.getFeature());
1153
+ }
1154
+ else if (feature instanceof RMFPolygon) {
1155
+ polygonMap.remove(feature.getFeature());
1156
+ }
1157
+ else if (feature instanceof RMFBuilding) {
1158
+ buildingMap.remove(feature.getFeature());
1159
+ }
1160
+ else if (feature instanceof RMFPOI) {
1161
+ MFPOI poi = (MFPOI) feature.getFeature();
1162
+ poiMap.remove(poi.getId());
1163
+ }
1164
+ else if (feature instanceof RMFTileOverlay) {
1165
+ tileOverlayMap.remove(feature.getFeature());
1166
+ }
1167
+ else if (feature instanceof RMFDirectionsRenderer) {
1168
+ directionsRendererMap.remove(feature.getFeature());
1169
+ }
1170
+ feature.removeFromMap(map);
1171
+ }
1172
+ }