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