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