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