react-native-maps 1.21.0-alpha.9 → 1.21.0-alpha.91
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 +45 -14
- package/android/generated/RCTAppDependencyProvider.h +25 -0
- package/android/generated/RCTAppDependencyProvider.mm +55 -0
- package/android/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
- package/android/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
- package/android/generated/RCTThirdPartyComponentsProvider.h +16 -0
- package/android/generated/RCTThirdPartyComponentsProvider.mm +26 -0
- package/android/generated/ReactAppDependencyProvider.podspec +34 -0
- package/android/generated/java/com/facebook/fbreact/specs/NativeAirMapsModuleSpec.java +63 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerDelegate.java +35 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerInterface.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsCircleManagerDelegate.java +49 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsCircleManagerInterface.java +24 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerDelegate.java +49 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerInterface.java +24 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerDelegate.java +206 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerInterface.java +74 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerDelegate.java +104 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerInterface.java +40 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerDelegate.java +46 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerInterface.java +24 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerDelegate.java +58 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerInterface.java +27 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNMapsSpecs-generated.cpp +68 -0
- package/android/generated/jni/RNMapsSpecs.h +31 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.cpp +29 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.h +31 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/EventEmitters.cpp +984 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/EventEmitters.h +853 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/Props.cpp +193 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/Props.h +1223 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI-generated.cpp +74 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI.h +268 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.cpp +24 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.h +109 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNMapsSpecs/States.h +113 -0
- 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 +235 -2
- 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 +38 -2
- 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 +1653 -1337
- package/ios/AirGoogleMaps/AIRGoogleMap.h +1 -0
- package/ios/AirGoogleMaps/AIRGoogleMap.m +106 -58
- package/ios/AirGoogleMaps/AIRGoogleMapCircle.m +23 -11
- package/ios/AirGoogleMaps/AIRGoogleMapManager.m +3 -1
- package/ios/AirGoogleMaps/AIRGoogleMapMarker.h +2 -0
- package/ios/AirGoogleMaps/AIRGoogleMapMarker.m +347 -243
- package/ios/AirGoogleMaps/AIRGoogleMapPolygon.h +2 -1
- package/ios/AirGoogleMaps/AIRGoogleMapPolygon.m +30 -0
- package/ios/AirGoogleMaps/AIRGoogleMapPolyline.h +0 -1
- package/ios/AirGoogleMaps/AIRGoogleMapPolyline.m +0 -7
- package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.h +1 -1
- package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.m +2 -2
- package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.m +2 -0
- package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +197 -61
- package/ios/AirGoogleMaps/RNMapsGooglePolygonView.h +26 -0
- package/ios/AirGoogleMaps/RNMapsGooglePolygonView.mm +215 -0
- package/ios/AirGoogleMaps/RNMapsGooglePolygonViewManager.mm +25 -0
- package/ios/AirMaps/AIRMap.h +2 -1
- package/ios/AirMaps/AIRMap.m +227 -236
- package/ios/AirMaps/AIRMapManager.m +6 -0
- 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/RNMapsAirModule.h +1 -1
- package/ios/AirMaps/RNMapsAirModule.mm +4 -3
- package/ios/AirMaps/RNMapsAirModuleDelegate.h +24 -0
- package/ios/AirMaps/RNMapsHostVewDelegate.h +17 -0
- package/ios/AirMaps/RNMapsMapView.mm +336 -307
- package/ios/AirMaps/RNMapsMarkerView.h +24 -0
- package/ios/AirMaps/RNMapsMarkerView.mm +427 -0
- package/ios/AirMaps/RNMapsMarkerViewManager.mm +21 -0
- package/ios/AirMaps/UIView +AirMap.m +20 -0
- package/ios/AirMaps/UIView+AirMap.h +11 -0
- package/ios/AirMaps.xcodeproj/project.pbxproj +60 -0
- package/ios/generated/RCTAppDependencyProvider.h +25 -0
- package/ios/generated/RCTAppDependencyProvider.mm +55 -0
- package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
- package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
- package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
- package/ios/generated/RCTThirdPartyComponentsProvider.mm +26 -0
- package/ios/generated/RNMapsSpecs/ComponentDescriptors.cpp +29 -0
- package/ios/generated/RNMapsSpecs/ComponentDescriptors.h +31 -0
- package/ios/generated/RNMapsSpecs/EventEmitters.cpp +984 -0
- package/ios/generated/RNMapsSpecs/EventEmitters.h +853 -0
- package/ios/generated/RNMapsSpecs/Props.cpp +193 -0
- package/ios/generated/RNMapsSpecs/Props.h +1223 -0
- package/ios/generated/RNMapsSpecs/RCTComponentViewHelpers.h +603 -0
- package/ios/generated/RNMapsSpecs/RNMapsSpecs-generated.mm +92 -0
- package/ios/generated/RNMapsSpecs/RNMapsSpecs.h +137 -0
- package/ios/generated/RNMapsSpecs/ShadowNodes.cpp +24 -0
- package/ios/generated/RNMapsSpecs/ShadowNodes.h +109 -0
- package/ios/generated/RNMapsSpecs/States.cpp +16 -0
- package/ios/generated/RNMapsSpecs/States.h +113 -0
- package/ios/generated/RNMapsSpecsJSI-generated.cpp +74 -0
- package/ios/generated/RNMapsSpecsJSI.h +268 -0
- package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
- package/ios/generated/module.modulemap +4 -0
- package/ios/generated/react-native-maps-generated-umbrella.h +14 -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 +58 -9
- package/lib/MapMarkerNativeComponent.js +0 -2
- package/lib/MapOverlay.d.ts +1 -0
- package/lib/MapOverlay.js +21 -9
- package/lib/MapPolygon.d.ts +1 -1
- package/lib/MapPolyline.d.ts +7 -7
- package/lib/MapView.d.ts +15 -27
- package/lib/MapView.js +109 -124
- package/lib/MapView.types.d.ts +1 -1
- package/lib/createFabricMap.d.ts +1 -0
- package/lib/createFabricMap.js +17 -4
- package/lib/decorateMapComponent.js +40 -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 +15 -15
- package/lib/specs/NativeComponentGoogleMapView.js +1 -0
- package/lib/specs/NativeComponentGooglePolygon.d.ts +75 -0
- package/lib/specs/NativeComponentGooglePolygon.js +7 -0
- package/lib/specs/NativeComponentMapView.d.ts +28 -36
- 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 -21
- package/react-native-maps.podspec +61 -16
|
@@ -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,1618 @@ 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
|
+
OnMapReadyEvent.EVENT_NAME, MapBuilder.of("registrationName", OnMapReadyEvent.EVENT_NAME),
|
|
668
|
+
OnUserLocationChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", OnUserLocationChangeEvent.EVENT_NAME),
|
|
669
|
+
OnRegionChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", OnRegionChangeEvent.EVENT_NAME),
|
|
670
|
+
OnIndoorBuildingFocusedEvent.EVENT_NAME, MapBuilder.of("registrationName", OnIndoorBuildingFocusedEvent.EVENT_NAME),
|
|
671
|
+
OnIndoorLevelActivatedEvent.EVENT_NAME, MapBuilder.of("registrationName", OnIndoorLevelActivatedEvent.EVENT_NAME),
|
|
672
|
+
OnKmlReadyEvent.EVENT_NAME, MapBuilder.of("registrationName", OnKmlReadyEvent.EVENT_NAME)
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
/*
|
|
678
|
+
onDestroy is final method so I can't override it.
|
|
679
|
+
*/
|
|
680
|
+
public synchronized void doDestroy() {
|
|
681
|
+
if (destroyed) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
destroyed = true;
|
|
685
|
+
|
|
686
|
+
Activity activity = context.getCurrentActivity();
|
|
687
|
+
if (activity instanceof LifecycleOwner) {
|
|
688
|
+
((LifecycleOwner) activity).getLifecycle().removeObserver(this);
|
|
689
|
+
}
|
|
210
690
|
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();
|
|
691
|
+
onPause();
|
|
692
|
+
paused = true;
|
|
693
|
+
}
|
|
694
|
+
onDestroy();
|
|
695
|
+
}
|
|
269
696
|
|
|
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());
|
|
697
|
+
public void setInitialCameraSet(boolean initialCameraSet) {
|
|
698
|
+
this.initialCameraSet = initialCameraSet;
|
|
699
|
+
}
|
|
279
700
|
|
|
280
|
-
|
|
701
|
+
public void setInitialRegion(ReadableMap initialRegion) {
|
|
702
|
+
this.initialRegion = initialRegion;
|
|
703
|
+
// Theoretically onMapReady might be called before setInitialRegion
|
|
704
|
+
// In that case, trigger moveToRegion manually
|
|
705
|
+
if (!initialRegionSet && map != null) {
|
|
706
|
+
moveToRegion(initialRegion);
|
|
707
|
+
initialRegionSet = true;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
281
710
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
711
|
+
public void setInitialCamera(ReadableMap initialCamera) {
|
|
712
|
+
this.initialCamera = initialCamera;
|
|
713
|
+
if (!initialCameraSet && map != null) {
|
|
714
|
+
moveToCamera(initialCamera);
|
|
715
|
+
initialCameraSet = true;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
285
718
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
719
|
+
private void applyBridgedProps() {
|
|
720
|
+
if (initialRegion != null) {
|
|
721
|
+
moveToRegion(initialRegion);
|
|
722
|
+
initialRegionSet = true;
|
|
723
|
+
} else if (region != null) {
|
|
724
|
+
moveToRegion(region);
|
|
725
|
+
} else if (initialCamera != null) {
|
|
726
|
+
moveToCamera(initialCamera);
|
|
727
|
+
initialCameraSet = true;
|
|
728
|
+
} else if (camera != null) {
|
|
729
|
+
moveToCamera(camera);
|
|
730
|
+
}
|
|
731
|
+
if (customMapStyleString != null) {
|
|
732
|
+
map.setMapStyle(new MapStyleOptions(customMapStyleString));
|
|
733
|
+
}
|
|
734
|
+
this.setPoiClickEnabled(poiClickEnabled);
|
|
735
|
+
}
|
|
290
736
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
737
|
+
public static LatLngBounds latLngBoundsFromRegion(ReadableMap region) {
|
|
738
|
+
if (region == null) return null;
|
|
739
|
+
|
|
740
|
+
double lng = region.getDouble("longitude");
|
|
741
|
+
double lat = region.getDouble("latitude");
|
|
742
|
+
double lngDelta = region.getDouble("longitudeDelta");
|
|
743
|
+
double latDelta = region.getDouble("latitudeDelta");
|
|
744
|
+
return new LatLngBounds(
|
|
745
|
+
new LatLng(lat - latDelta / 2, lng - lngDelta / 2), // southwest
|
|
746
|
+
new LatLng(lat + latDelta / 2, lng + lngDelta / 2) // northeast
|
|
747
|
+
);
|
|
748
|
+
}
|
|
295
749
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
750
|
+
private void moveToRegion(ReadableMap region) {
|
|
751
|
+
LatLngBounds bounds = latLngBoundsFromRegion(region);
|
|
752
|
+
if (bounds == null) return;
|
|
753
|
+
double lng = region.getDouble("longitude");
|
|
754
|
+
double lat = region.getDouble("latitude");
|
|
755
|
+
if (super.getHeight() <= 0 || super.getWidth() <= 0) {
|
|
756
|
+
// in this case, our map has not been laid out yet, so we save the bounds in a local
|
|
757
|
+
// variable, and make a guess of zoomLevel 10. Not to worry, though: as soon as layout
|
|
758
|
+
// occurs, we will move the camera to the saved bounds. Note that if we tried to move
|
|
759
|
+
// to the bounds now, it would trigger an exception.
|
|
760
|
+
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 10));
|
|
761
|
+
boundsToMove = bounds;
|
|
762
|
+
} else {
|
|
763
|
+
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
|
|
764
|
+
boundsToMove = null;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
public void setRegion(ReadableMap region) {
|
|
769
|
+
this.region = region;
|
|
770
|
+
if (region != null && map != null) {
|
|
771
|
+
moveToRegion(region);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
public void setCamera(ReadableMap camera) {
|
|
776
|
+
this.camera = camera;
|
|
777
|
+
if (camera != null && map != null) {
|
|
778
|
+
moveToCamera(camera);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
300
781
|
|
|
301
|
-
|
|
782
|
+
public static CameraPosition cameraPositionFromMap(ReadableMap camera) {
|
|
783
|
+
if (camera == null) return null;
|
|
302
784
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (
|
|
307
|
-
|
|
785
|
+
CameraPosition.Builder builder = new CameraPosition.Builder();
|
|
786
|
+
|
|
787
|
+
ReadableMap center = camera.getMap("center");
|
|
788
|
+
if (center != null) {
|
|
789
|
+
double lng = center.getDouble("longitude");
|
|
790
|
+
double lat = center.getDouble("latitude");
|
|
791
|
+
builder.target(new LatLng(lat, lng));
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
builder.tilt((float) camera.getDouble("pitch"));
|
|
795
|
+
builder.bearing((float) camera.getDouble("heading"));
|
|
796
|
+
builder.zoom((float) camera.getDouble("zoom"));
|
|
797
|
+
|
|
798
|
+
return builder.build();
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
public CameraPosition cameraPositionFromJSON(JSONObject camera) throws JSONException {
|
|
802
|
+
if (camera == null) return null;
|
|
803
|
+
if (map == null) return null;
|
|
804
|
+
|
|
805
|
+
CameraPosition.Builder builder = new CameraPosition.Builder();
|
|
806
|
+
|
|
807
|
+
if (camera.has("center")) {
|
|
808
|
+
JSONObject center = camera.getJSONObject("center");
|
|
809
|
+
if (center != null) {
|
|
810
|
+
double lng = center.getDouble("longitude");
|
|
811
|
+
double lat = center.getDouble("latitude");
|
|
812
|
+
builder.target(new LatLng(lat, lng));
|
|
813
|
+
}
|
|
308
814
|
} 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);
|
|
815
|
+
builder.target(map.getCameraPosition().target);
|
|
816
|
+
}
|
|
339
817
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
818
|
+
if (camera.has("pitch")) {
|
|
819
|
+
builder.tilt((float) camera.getDouble("pitch"));
|
|
820
|
+
} else {
|
|
821
|
+
builder.tilt(map.getCameraPosition().tilt);
|
|
822
|
+
}
|
|
823
|
+
if (camera.has("heading")) {
|
|
824
|
+
builder.bearing((float) camera.getDouble("heading"));
|
|
825
|
+
} else {
|
|
826
|
+
builder.bearing(map.getCameraPosition().bearing);
|
|
827
|
+
}
|
|
828
|
+
if (camera.has("zoom")) {
|
|
829
|
+
builder.zoom((float) camera.getDouble("zoom"));
|
|
830
|
+
} else {
|
|
831
|
+
builder.zoom(map.getCameraPosition().zoom);
|
|
832
|
+
}
|
|
344
833
|
|
|
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;
|
|
834
|
+
return builder.build();
|
|
835
|
+
}
|
|
396
836
|
|
|
397
|
-
|
|
398
|
-
|
|
837
|
+
public void moveToCamera(ReadableMap cameraMap) {
|
|
838
|
+
moveToCamera(cameraPositionFromMap(cameraMap));
|
|
839
|
+
}
|
|
399
840
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
});
|
|
841
|
+
public void moveToCamera(CameraPosition camera) {
|
|
842
|
+
if (camera == null) return;
|
|
843
|
+
CameraUpdate update = CameraUpdateFactory.newCameraPosition(camera);
|
|
404
844
|
|
|
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);
|
|
845
|
+
if (super.getHeight() <= 0 || super.getWidth() <= 0) {
|
|
846
|
+
// in this case, our map has not been laid out yet, so we save the camera update in a
|
|
847
|
+
// local variable. As soon as layout occurs, we will move the camera to the saved update.
|
|
848
|
+
// Note that if we tried to move to the camera now, it would trigger an exception.
|
|
849
|
+
cameraToSet = update;
|
|
850
|
+
} else {
|
|
851
|
+
map.moveCamera(update);
|
|
852
|
+
cameraToSet = null;
|
|
444
853
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
public void setMapStyle(@Nullable String customMapStyleString) {
|
|
857
|
+
this.customMapStyleString = customMapStyleString;
|
|
858
|
+
if (map != null && customMapStyleString != null) {
|
|
859
|
+
map.setMapStyle(new MapStyleOptions(customMapStyleString));
|
|
450
860
|
}
|
|
451
|
-
|
|
861
|
+
}
|
|
452
862
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (hasPermissions()
|
|
456
|
-
|
|
457
|
-
|
|
863
|
+
public void setShowsUserLocation(boolean showUserLocation) {
|
|
864
|
+
this.showUserLocation = showUserLocation; // hold onto this for lifecycle handling
|
|
865
|
+
if (hasPermissions()) {
|
|
866
|
+
map.setLocationSource(fusedLocationSource);
|
|
867
|
+
//noinspection MissingPermission
|
|
868
|
+
map.setMyLocationEnabled(showUserLocation);
|
|
458
869
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
public void setUserLocationPriority(int priority) {
|
|
873
|
+
fusedLocationSource.setPriority(priority);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
public void setUserLocationUpdateInterval(int interval) {
|
|
877
|
+
fusedLocationSource.setInterval(interval);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
public void setUserLocationFastestInterval(int interval) {
|
|
881
|
+
fusedLocationSource.setFastestInterval(interval);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
public void setShowsMyLocationButton(boolean showMyLocationButton) {
|
|
885
|
+
if (map != null) {
|
|
886
|
+
if (hasPermissions() || !showMyLocationButton) {
|
|
887
|
+
map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
|
|
888
|
+
}
|
|
464
889
|
}
|
|
465
|
-
|
|
890
|
+
}
|
|
466
891
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
892
|
+
public void setToolbarEnabled(boolean toolbarEnabled) {
|
|
893
|
+
if (map != null) {
|
|
894
|
+
if (hasPermissions() || !toolbarEnabled) {
|
|
895
|
+
map.getUiSettings().setMapToolbarEnabled(toolbarEnabled);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
472
899
|
|
|
473
|
-
|
|
474
|
-
|
|
900
|
+
public void setMapType(int mapType) {
|
|
901
|
+
if (map != null) {
|
|
902
|
+
map.setMapType(mapType);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
475
905
|
|
|
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"));
|
|
906
|
+
public void setCacheEnabled(boolean cacheEnabled) {
|
|
907
|
+
this.cacheEnabled = cacheEnabled;
|
|
908
|
+
this.cacheView();
|
|
919
909
|
}
|
|
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);
|
|
910
|
+
|
|
911
|
+
public void setPoiClickEnabled(boolean poiClickEnabled) {
|
|
912
|
+
this.poiClickEnabled = poiClickEnabled;
|
|
913
|
+
if (map != null) {
|
|
914
|
+
map.setOnPoiClickListener(poiClickEnabled ? this : null);
|
|
915
|
+
}
|
|
935
916
|
}
|
|
936
|
-
}
|
|
937
917
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
} else {
|
|
943
|
-
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), duration, null);
|
|
918
|
+
public void setLoadingEnabled(boolean loadingEnabled) {
|
|
919
|
+
if (loadingEnabled && !this.isMapLoaded) {
|
|
920
|
+
this.getMapLoadingLayoutView().setVisibility(View.VISIBLE);
|
|
921
|
+
}
|
|
944
922
|
}
|
|
945
|
-
}
|
|
946
923
|
|
|
947
|
-
|
|
948
|
-
|
|
924
|
+
public void setMoveOnMarkerPress(boolean moveOnPress) {
|
|
925
|
+
this.moveOnMarkerPress = moveOnPress;
|
|
926
|
+
}
|
|
949
927
|
|
|
950
|
-
|
|
928
|
+
public void setMaxZoomLevel(float maxZoomLevel) {
|
|
929
|
+
this.maxZoomLevel = maxZoomLevel;
|
|
930
|
+
if (map != null) {
|
|
931
|
+
map.setMaxZoomPreference(maxZoomLevel);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
951
934
|
|
|
952
|
-
|
|
935
|
+
public void setMinZoomLevel(float minZoomLevel) {
|
|
936
|
+
this.minZoomLevel = minZoomLevel;
|
|
937
|
+
if (map != null) {
|
|
938
|
+
map.setMinZoomPreference(minZoomLevel);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
public void setPitchEnabled(boolean pitchEnabled) {
|
|
943
|
+
this.pitchEnabled = pitchEnabled;
|
|
944
|
+
if (map != null) {
|
|
945
|
+
map.getUiSettings().setTiltGesturesEnabled(pitchEnabled);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
953
948
|
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
}
|
|
960
|
-
// TODO(lmr): may want to include shapes / etc.
|
|
949
|
+
public void setShowsCompass(boolean showsCompass) {
|
|
950
|
+
this.showsCompass = showsCompass;
|
|
951
|
+
if (map != null) {
|
|
952
|
+
map.getUiSettings().setCompassEnabled(showsCompass);
|
|
953
|
+
}
|
|
961
954
|
}
|
|
962
|
-
if (addedPosition) {
|
|
963
|
-
LatLngBounds bounds = builder.build();
|
|
964
|
-
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
|
|
965
955
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
956
|
+
public void setRotateEnabled(boolean rotateEnabled) {
|
|
957
|
+
this.rotateEnabled = rotateEnabled;
|
|
958
|
+
if (map != null) {
|
|
959
|
+
map.getUiSettings().setRotateGesturesEnabled(rotateEnabled);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
970
962
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
963
|
+
public void setZoomEnabled(boolean zoomEnabled) {
|
|
964
|
+
this.zoomEnabled = zoomEnabled;
|
|
965
|
+
if (map != null) {
|
|
966
|
+
map.getUiSettings().setZoomGesturesEnabled(zoomEnabled);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
public void setZoomControlEnabled(boolean zoomControlEnabled) {
|
|
971
|
+
this.zoomControlEnabled = zoomControlEnabled;
|
|
972
|
+
if (map != null) {
|
|
973
|
+
map.getUiSettings().setZoomControlsEnabled(zoomControlEnabled);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
public void setScrollDuringRotateOrZoomEnabled(boolean scrollDuringRotateOrZoomEnabled) {
|
|
978
|
+
this.scrollDuringRotateOrZoomEnabled = scrollDuringRotateOrZoomEnabled;
|
|
979
|
+
if (map != null) {
|
|
980
|
+
map.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(scrollDuringRotateOrZoomEnabled);
|
|
981
|
+
}
|
|
978
982
|
}
|
|
979
|
-
}
|
|
980
983
|
|
|
981
|
-
|
|
982
|
-
|
|
984
|
+
public void setScrollEnabled(boolean scrollEnabled) {
|
|
985
|
+
this.scrollEnabled = scrollEnabled;
|
|
986
|
+
if (map != null) {
|
|
987
|
+
map.getUiSettings().setScrollGesturesEnabled(scrollEnabled);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
public void setShowIndoors(boolean showIndoors) {
|
|
992
|
+
this.showIndoors = showIndoors;
|
|
993
|
+
if (map != null) {
|
|
994
|
+
map.setIndoorEnabled(showIndoors);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
983
997
|
|
|
984
|
-
|
|
998
|
+
public void setShowsIndoorLevelPicker(boolean showsIndoorLevelPicker) {
|
|
999
|
+
this.showsIndoorLevelPicker = showsIndoorLevelPicker;
|
|
1000
|
+
if (map != null) {
|
|
1001
|
+
map.getUiSettings().setIndoorLevelPickerEnabled(showsIndoorLevelPicker);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
985
1004
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1005
|
+
public void setShowBuildings(boolean showBuildings) {
|
|
1006
|
+
this.setShowBuildings = showBuildings;
|
|
1007
|
+
if (map != null) {
|
|
1008
|
+
map.setBuildingsEnabled(showBuildings);
|
|
1009
|
+
}
|
|
989
1010
|
}
|
|
990
1011
|
|
|
991
|
-
boolean addedPosition = false;
|
|
992
1012
|
|
|
993
|
-
|
|
1013
|
+
public void setLoadingBackgroundColor(Integer loadingBackgroundColor) {
|
|
1014
|
+
this.loadingBackgroundColor = loadingBackgroundColor;
|
|
994
1015
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
addedPosition = true;
|
|
1016
|
+
if (this.mapLoadingLayout != null) {
|
|
1017
|
+
if (loadingBackgroundColor == null) {
|
|
1018
|
+
this.mapLoadingLayout.setBackgroundColor(Color.WHITE);
|
|
1019
|
+
} else {
|
|
1020
|
+
this.mapLoadingLayout.setBackgroundColor(this.loadingBackgroundColor);
|
|
1021
|
+
}
|
|
1002
1022
|
}
|
|
1003
|
-
}
|
|
1004
1023
|
}
|
|
1005
1024
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1025
|
+
public void setLoadingIndicatorColor(Integer loadingIndicatorColor) {
|
|
1026
|
+
this.loadingIndicatorColor = loadingIndicatorColor;
|
|
1027
|
+
if (this.mapLoadingProgressBar != null) {
|
|
1028
|
+
Integer color = loadingIndicatorColor;
|
|
1029
|
+
if (color == null) {
|
|
1030
|
+
color = Color.parseColor("#606060");
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
ColorStateList progressTintList = ColorStateList.valueOf(loadingIndicatorColor);
|
|
1034
|
+
ColorStateList secondaryProgressTintList = ColorStateList.valueOf(loadingIndicatorColor);
|
|
1035
|
+
ColorStateList indeterminateTintList = ColorStateList.valueOf(loadingIndicatorColor);
|
|
1009
1036
|
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1037
|
+
this.mapLoadingProgressBar.setProgressTintList(progressTintList);
|
|
1038
|
+
this.mapLoadingProgressBar.setSecondaryProgressTintList(secondaryProgressTintList);
|
|
1039
|
+
this.mapLoadingProgressBar.setIndeterminateTintList(indeterminateTintList);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
public void setHandlePanDrag(boolean handlePanDrag) {
|
|
1044
|
+
this.handlePanDrag = handlePanDrag;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
public void addFeature(View child, int index) {
|
|
1048
|
+
// Our desired API is to pass up annotations/overlays as children to the mapview component.
|
|
1049
|
+
// This is where we intercept them and do the appropriate underlying mapview action.
|
|
1050
|
+
if (child instanceof MapMarker) {
|
|
1051
|
+
MapMarker annotation = (MapMarker) child;
|
|
1052
|
+
annotation.addToMap(markerCollection);
|
|
1053
|
+
features.add(index, annotation);
|
|
1054
|
+
|
|
1055
|
+
// Allow visibility event to be triggered later
|
|
1056
|
+
int visibility = annotation.getVisibility();
|
|
1057
|
+
annotation.setVisibility(INVISIBLE);
|
|
1058
|
+
|
|
1059
|
+
// Remove from a view group if already present, prevent "specified child
|
|
1060
|
+
// already had a parent" error.
|
|
1061
|
+
ViewGroup annotationParent = (ViewGroup) annotation.getParent();
|
|
1062
|
+
if (annotationParent != null) {
|
|
1063
|
+
annotationParent.removeView(annotation);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// Add to the parent group
|
|
1067
|
+
attacherGroup.addView(annotation);
|
|
1068
|
+
|
|
1069
|
+
// Trigger visibility event if necessary.
|
|
1070
|
+
// With some testing, seems like it is not always
|
|
1071
|
+
// triggered just by being added to a parent view.
|
|
1072
|
+
annotation.setVisibility(visibility);
|
|
1073
|
+
|
|
1074
|
+
Marker marker = (Marker) annotation.getFeature();
|
|
1075
|
+
markerMap.put(marker, annotation);
|
|
1076
|
+
} else if (child instanceof MapPolyline) {
|
|
1077
|
+
MapPolyline polylineView = (MapPolyline) child;
|
|
1078
|
+
polylineView.addToMap(polylineCollection);
|
|
1079
|
+
features.add(index, polylineView);
|
|
1080
|
+
Polyline polyline = (Polyline) polylineView.getFeature();
|
|
1081
|
+
polylineMap.put(polyline, polylineView);
|
|
1082
|
+
} else if (child instanceof MapGradientPolyline) {
|
|
1083
|
+
MapGradientPolyline polylineView = (MapGradientPolyline) child;
|
|
1084
|
+
polylineView.addToMap(map);
|
|
1085
|
+
features.add(index, polylineView);
|
|
1086
|
+
TileOverlay tileOverlay = (TileOverlay) polylineView.getFeature();
|
|
1087
|
+
gradientPolylineMap.put(tileOverlay, polylineView);
|
|
1088
|
+
} else if (child instanceof MapPolygon) {
|
|
1089
|
+
MapPolygon polygonView = (MapPolygon) child;
|
|
1090
|
+
polygonView.addToMap(polygonCollection);
|
|
1091
|
+
features.add(index, polygonView);
|
|
1092
|
+
Polygon polygon = (Polygon) polygonView.getFeature();
|
|
1093
|
+
polygonMap.put(polygon, polygonView);
|
|
1094
|
+
} else if (child instanceof MapCircle) {
|
|
1095
|
+
MapCircle circleView = (MapCircle) child;
|
|
1096
|
+
circleView.addToMap(circleCollection);
|
|
1097
|
+
features.add(index, circleView);
|
|
1098
|
+
} else if (child instanceof MapUrlTile) {
|
|
1099
|
+
MapUrlTile urlTileView = (MapUrlTile) child;
|
|
1100
|
+
urlTileView.addToMap(map);
|
|
1101
|
+
features.add(index, urlTileView);
|
|
1102
|
+
} else if (child instanceof MapWMSTile) {
|
|
1103
|
+
MapWMSTile urlTileView = (MapWMSTile) child;
|
|
1104
|
+
urlTileView.addToMap(map);
|
|
1105
|
+
features.add(index, urlTileView);
|
|
1106
|
+
} else if (child instanceof MapLocalTile) {
|
|
1107
|
+
MapLocalTile localTileView = (MapLocalTile) child;
|
|
1108
|
+
localTileView.addToMap(map);
|
|
1109
|
+
features.add(index, localTileView);
|
|
1110
|
+
} else if (child instanceof MapOverlay) {
|
|
1111
|
+
MapOverlay overlayView = (MapOverlay) child;
|
|
1112
|
+
overlayView.addToMap(groundOverlayCollection);
|
|
1113
|
+
features.add(index, overlayView);
|
|
1114
|
+
GroundOverlay overlay = (GroundOverlay) overlayView.getFeature();
|
|
1115
|
+
overlayMap.put(overlay, overlayView);
|
|
1116
|
+
} else if (child instanceof MapHeatmap) {
|
|
1117
|
+
MapHeatmap heatmapView = (MapHeatmap) child;
|
|
1118
|
+
heatmapView.addToMap(map);
|
|
1119
|
+
features.add(index, heatmapView);
|
|
1120
|
+
TileOverlay heatmap = (TileOverlay) heatmapView.getFeature();
|
|
1121
|
+
heatmapMap.put(heatmap, heatmapView);
|
|
1122
|
+
} else if (child instanceof ViewGroup) {
|
|
1123
|
+
ViewGroup children = (ViewGroup) child;
|
|
1124
|
+
for (int i = 0; i < children.getChildCount(); i++) {
|
|
1125
|
+
addFeature(children.getChildAt(i), index);
|
|
1126
|
+
}
|
|
1127
|
+
} else {
|
|
1128
|
+
addView(child, index);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
public int getFeatureCount() {
|
|
1133
|
+
return features.size();
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
public View getFeatureAt(int index) {
|
|
1137
|
+
return features.get(index);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
public void removeFeatureAt(int index) {
|
|
1141
|
+
MapFeature feature = features.remove(index);
|
|
1142
|
+
if (feature instanceof MapMarker) {
|
|
1143
|
+
markerMap.remove(feature.getFeature());
|
|
1144
|
+
feature.removeFromMap(markerCollection);
|
|
1145
|
+
attacherGroup.removeView(feature);
|
|
1146
|
+
} else if (feature instanceof MapHeatmap) {
|
|
1147
|
+
heatmapMap.remove(feature.getFeature());
|
|
1148
|
+
feature.removeFromMap(map);
|
|
1149
|
+
} else if (feature instanceof MapCircle) {
|
|
1150
|
+
feature.removeFromMap(circleCollection);
|
|
1151
|
+
} else if (feature instanceof MapOverlay) {
|
|
1152
|
+
feature.removeFromMap(groundOverlayCollection);
|
|
1153
|
+
} else if (feature instanceof MapPolygon) {
|
|
1154
|
+
feature.removeFromMap(polygonCollection);
|
|
1155
|
+
} else if (feature instanceof MapPolyline) {
|
|
1156
|
+
feature.removeFromMap(polylineCollection);
|
|
1157
|
+
} else {
|
|
1158
|
+
feature.removeFromMap(map);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
public WritableMap makeClickEventData(LatLng point) {
|
|
1163
|
+
WritableMap event = new WritableNativeMap();
|
|
1164
|
+
|
|
1165
|
+
WritableMap coordinate = new WritableNativeMap();
|
|
1166
|
+
coordinate.putDouble("latitude", point.latitude);
|
|
1167
|
+
coordinate.putDouble("longitude", point.longitude);
|
|
1168
|
+
event.putMap("coordinate", coordinate);
|
|
1169
|
+
|
|
1170
|
+
Projection projection = map.getProjection();
|
|
1171
|
+
Point screenPoint = projection.toScreenLocation(point);
|
|
1172
|
+
|
|
1173
|
+
WritableMap position = new WritableNativeMap();
|
|
1174
|
+
position.putDouble("x", screenPoint.x);
|
|
1175
|
+
position.putDouble("y", screenPoint.y);
|
|
1176
|
+
event.putMap("position", position);
|
|
1177
|
+
|
|
1178
|
+
return event;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
public void updateExtraData(Object extraData) {
|
|
1182
|
+
if (setPaddingDeferred && super.getHeight() > 0 && super.getWidth() > 0) {
|
|
1183
|
+
CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
|
|
1184
|
+
|
|
1185
|
+
map.setPadding(edgeLeftPadding + baseLeftMapPadding,
|
|
1186
|
+
edgeTopPadding + baseTopMapPadding,
|
|
1187
|
+
edgeRightPadding + baseRightMapPadding,
|
|
1188
|
+
edgeBottomPadding + baseBottomMapPadding);
|
|
1189
|
+
map.moveCamera(cu);
|
|
1190
|
+
|
|
1191
|
+
// Move the google logo to the default base padding value.
|
|
1192
|
+
map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
|
|
1193
|
+
|
|
1194
|
+
setPaddingDeferred = false;
|
|
1195
|
+
}
|
|
1014
1196
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1197
|
+
// if boundsToMove is not null, we now have the MapView's width/height, so we can apply
|
|
1198
|
+
// a proper camera move
|
|
1199
|
+
if (boundsToMove != null) {
|
|
1200
|
+
HashMap<String, Float> data = (HashMap<String, Float>) extraData;
|
|
1201
|
+
int width = data.get("width") == null ? 0 : data.get("width").intValue();
|
|
1202
|
+
int height = data.get("height") == null ? 0 : data.get("height").intValue();
|
|
1203
|
+
|
|
1204
|
+
//fix for https://github.com/react-native-maps/react-native-maps/issues/245,
|
|
1205
|
+
//it's not guaranteed the passed-in height and width would be greater than 0.
|
|
1206
|
+
if (width <= 0 || height <= 0) {
|
|
1207
|
+
map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsToMove, 0));
|
|
1208
|
+
} else {
|
|
1209
|
+
map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsToMove, width, height, 0));
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
boundsToMove = null;
|
|
1213
|
+
cameraToSet = null;
|
|
1214
|
+
} else if (cameraToSet != null) {
|
|
1215
|
+
map.moveCamera(cameraToSet);
|
|
1216
|
+
cameraToSet = null;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
public void animateToCamera(CameraPosition position, int duration) {
|
|
1220
|
+
if (map == null) return;
|
|
1221
|
+
CameraUpdate update = CameraUpdateFactory.newCameraPosition(position);
|
|
1222
|
+
if (duration <= 0) {
|
|
1223
|
+
map.moveCamera(update);
|
|
1224
|
+
} else {
|
|
1225
|
+
map.animateCamera(update, duration, null);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
public void animateToCamera(ReadableMap camera, int duration) {
|
|
1230
|
+
if (map == null) return;
|
|
1231
|
+
CameraPosition.Builder builder = new CameraPosition.Builder(map.getCameraPosition());
|
|
1232
|
+
if (camera.hasKey("zoom")) {
|
|
1233
|
+
builder.zoom((float) camera.getDouble("zoom"));
|
|
1234
|
+
}
|
|
1235
|
+
if (camera.hasKey("heading")) {
|
|
1236
|
+
builder.bearing((float) camera.getDouble("heading"));
|
|
1237
|
+
}
|
|
1238
|
+
if (camera.hasKey("pitch")) {
|
|
1239
|
+
builder.tilt((float) camera.getDouble("pitch"));
|
|
1240
|
+
}
|
|
1241
|
+
if (camera.hasKey("center")) {
|
|
1242
|
+
ReadableMap center = camera.getMap("center");
|
|
1243
|
+
builder.target(new LatLng(center.getDouble("latitude"), center.getDouble("longitude")));
|
|
1244
|
+
}
|
|
1245
|
+
animateToCamera(builder.build(), duration);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
public void animateToRegion(LatLngBounds bounds, int duration) {
|
|
1249
|
+
if (map == null) return;
|
|
1250
|
+
if (duration <= 0) {
|
|
1251
|
+
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
|
|
1252
|
+
} else {
|
|
1253
|
+
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), duration, null);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
public void fitToElements(ReadableMap edgePadding, boolean animated) {
|
|
1258
|
+
if (map == null) return;
|
|
1259
|
+
|
|
1260
|
+
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
|
1261
|
+
|
|
1262
|
+
boolean addedPosition = false;
|
|
1263
|
+
if (features.size() > 0) {
|
|
1264
|
+
for (MapFeature feature : features) {
|
|
1265
|
+
if (feature instanceof MapMarker) {
|
|
1266
|
+
Marker marker = (Marker) feature.getFeature();
|
|
1267
|
+
builder.include(marker.getPosition());
|
|
1268
|
+
addedPosition = true;
|
|
1269
|
+
}
|
|
1270
|
+
// TODO(lmr): may want to include shapes / etc.
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (addedPosition) {
|
|
1274
|
+
LatLngBounds bounds = builder.build();
|
|
1275
|
+
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
|
|
1276
|
+
|
|
1277
|
+
if (edgePadding != null) {
|
|
1278
|
+
appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
|
|
1279
|
+
edgePadding.getInt("right"), edgePadding.getInt("bottom"));
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
if (animated) {
|
|
1283
|
+
map.animateCamera(cu);
|
|
1284
|
+
} else {
|
|
1285
|
+
map.moveCamera(cu);
|
|
1286
|
+
}
|
|
1287
|
+
// Move the google logo to the default base padding value.
|
|
1288
|
+
map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
public void fitToSuppliedMarkers(ReadableArray markerIDsArray, ReadableMap edgePadding, boolean animated) {
|
|
1293
|
+
if (map == null) return;
|
|
1294
|
+
|
|
1295
|
+
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
|
1296
|
+
|
|
1297
|
+
String[] markerIDs = new String[markerIDsArray.size()];
|
|
1298
|
+
for (int i = 0; i < markerIDsArray.size(); i++) {
|
|
1299
|
+
markerIDs[i] = markerIDsArray.getString(i);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
boolean addedPosition = false;
|
|
1303
|
+
|
|
1304
|
+
List<String> markerIDList = Arrays.asList(markerIDs);
|
|
1305
|
+
|
|
1306
|
+
for (MapFeature feature : features) {
|
|
1307
|
+
if (feature instanceof MapMarker) {
|
|
1308
|
+
String identifier = ((MapMarker) feature).getIdentifier();
|
|
1309
|
+
Marker marker = (Marker) feature.getFeature();
|
|
1310
|
+
if (markerIDList.contains(identifier)) {
|
|
1311
|
+
builder.include(marker.getPosition());
|
|
1312
|
+
addedPosition = true;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
if (addedPosition) {
|
|
1318
|
+
LatLngBounds bounds = builder.build();
|
|
1319
|
+
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
|
|
1320
|
+
|
|
1321
|
+
if (edgePadding != null) {
|
|
1322
|
+
appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
|
|
1323
|
+
edgePadding.getInt("right"), edgePadding.getInt("bottom"));
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
if (animated) {
|
|
1327
|
+
map.animateCamera(cu);
|
|
1328
|
+
} else {
|
|
1329
|
+
map.moveCamera(cu);
|
|
1330
|
+
}
|
|
1331
|
+
// Move the google logo to the default base padding value.
|
|
1332
|
+
map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// padding configured by 'mapPadding' property
|
|
1337
|
+
int baseLeftMapPadding;
|
|
1338
|
+
int baseRightMapPadding;
|
|
1339
|
+
int baseTopMapPadding;
|
|
1340
|
+
int baseBottomMapPadding;
|
|
1341
|
+
// extra padding specified by 'edgePadding' option of fitToElements/fitToSuppliedMarkers/fitToCoordinates
|
|
1342
|
+
int edgeLeftPadding;
|
|
1343
|
+
int edgeRightPadding;
|
|
1344
|
+
int edgeTopPadding;
|
|
1345
|
+
int edgeBottomPadding;
|
|
1346
|
+
|
|
1347
|
+
public void applyBaseMapPadding(int left, int top, int right, int bottom) {
|
|
1348
|
+
if (super.getHeight() <= 0 || super.getWidth() <= 0) {
|
|
1349
|
+
// the map is not laid out yet and calling setPadding() now has no effect
|
|
1350
|
+
baseLeftMapPadding = left;
|
|
1351
|
+
baseRightMapPadding = right;
|
|
1352
|
+
baseTopMapPadding = top;
|
|
1353
|
+
baseBottomMapPadding = bottom;
|
|
1354
|
+
setPaddingDeferred = true;
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// retrieve current camera with current edge paddings configured
|
|
1359
|
+
map.setPadding(edgeLeftPadding + baseLeftMapPadding,
|
|
1360
|
+
edgeTopPadding + baseTopMapPadding,
|
|
1361
|
+
edgeRightPadding + baseRightMapPadding,
|
|
1362
|
+
edgeBottomPadding + baseBottomMapPadding);
|
|
1363
|
+
CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
|
|
1364
|
+
|
|
1365
|
+
baseLeftMapPadding = left;
|
|
1366
|
+
baseRightMapPadding = right;
|
|
1367
|
+
baseTopMapPadding = top;
|
|
1368
|
+
baseBottomMapPadding = bottom;
|
|
1369
|
+
|
|
1370
|
+
// apply base paddings and restore center position of the map
|
|
1371
|
+
map.setPadding(edgeLeftPadding + left,
|
|
1372
|
+
edgeTopPadding + top,
|
|
1373
|
+
edgeRightPadding + right,
|
|
1374
|
+
edgeBottomPadding + bottom);
|
|
1018
1375
|
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
1376
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1377
|
+
// Move the google logo to the default base padding value.
|
|
1378
|
+
map.setPadding(left, top, right, bottom);
|
|
1379
|
+
}
|
|
1126
1380
|
|
|
1127
|
-
|
|
1381
|
+
public void fitToCoordinates(ReadableArray coordinatesArray, ReadableMap edgePadding,
|
|
1382
|
+
boolean animated) {
|
|
1383
|
+
if (map == null) return;
|
|
1128
1384
|
|
|
1129
|
-
|
|
1130
|
-
double lngNE = northEast.getDouble("longitude");
|
|
1131
|
-
builder.include(new LatLng(latNE, lngNE));
|
|
1385
|
+
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
|
1132
1386
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1387
|
+
for (int i = 0; i < coordinatesArray.size(); i++) {
|
|
1388
|
+
ReadableMap latLng = coordinatesArray.getMap(i);
|
|
1389
|
+
double lat = latLng.getDouble("latitude");
|
|
1390
|
+
double lng = latLng.getDouble("longitude");
|
|
1391
|
+
builder.include(new LatLng(lat, lng));
|
|
1392
|
+
}
|
|
1136
1393
|
|
|
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();
|
|
1394
|
+
LatLngBounds bounds = builder.build();
|
|
1395
|
+
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
|
|
1396
|
+
|
|
1397
|
+
if (edgePadding != null) {
|
|
1398
|
+
appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"), edgePadding.getInt("right"), edgePadding.getInt("bottom"));
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
if (animated) {
|
|
1402
|
+
map.animateCamera(cu);
|
|
1360
1403
|
} else {
|
|
1361
|
-
|
|
1404
|
+
map.moveCamera(cu);
|
|
1362
1405
|
}
|
|
1406
|
+
// Move the google logo to the default base padding value.
|
|
1407
|
+
map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
private void appendMapPadding(int iLeft, int iTop, int iRight, int iBottom) {
|
|
1411
|
+
double density = getResources().getDisplayMetrics().density;
|
|
1412
|
+
|
|
1413
|
+
edgeLeftPadding = (int) (iLeft * density);
|
|
1414
|
+
edgeTopPadding = (int) (iTop * density);
|
|
1415
|
+
edgeRightPadding = (int) (iRight * density);
|
|
1416
|
+
edgeBottomPadding = (int) (iBottom * density);
|
|
1417
|
+
|
|
1418
|
+
map.setPadding(edgeLeftPadding + baseLeftMapPadding,
|
|
1419
|
+
edgeTopPadding + baseTopMapPadding,
|
|
1420
|
+
edgeRightPadding + baseRightMapPadding,
|
|
1421
|
+
edgeBottomPadding + baseBottomMapPadding);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
public double[][] getMapBoundaries() {
|
|
1425
|
+
LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
|
|
1426
|
+
LatLng northEast = bounds.northeast;
|
|
1427
|
+
LatLng southWest = bounds.southwest;
|
|
1428
|
+
|
|
1429
|
+
return new double[][]{
|
|
1430
|
+
{northEast.longitude, northEast.latitude},
|
|
1431
|
+
{southWest.longitude, southWest.latitude}
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1363
1434
|
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
String snippet = "";
|
|
1435
|
+
public void setMapBoundaries(ReadableMap northEast, ReadableMap southWest) {
|
|
1436
|
+
if (map == null) return;
|
|
1367
1437
|
|
|
1368
|
-
|
|
1369
|
-
|
|
1438
|
+
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
|
1439
|
+
|
|
1440
|
+
double latNE = northEast.getDouble("latitude");
|
|
1441
|
+
double lngNE = northEast.getDouble("longitude");
|
|
1442
|
+
builder.include(new LatLng(latNE, lngNE));
|
|
1443
|
+
|
|
1444
|
+
double latSW = southWest.getDouble("latitude");
|
|
1445
|
+
double lngSW = southWest.getDouble("longitude");
|
|
1446
|
+
builder.include(new LatLng(latSW, lngSW));
|
|
1447
|
+
|
|
1448
|
+
LatLngBounds bounds = builder.build();
|
|
1449
|
+
|
|
1450
|
+
map.setLatLngBoundsForCameraTarget(bounds);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// InfoWindowAdapter interface
|
|
1454
|
+
|
|
1455
|
+
@Override
|
|
1456
|
+
public View getInfoWindow(Marker marker) {
|
|
1457
|
+
MapMarker markerView = getMarkerMap(marker);
|
|
1458
|
+
return markerView.getCallout();
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
@Override
|
|
1462
|
+
public View getInfoContents(Marker marker) {
|
|
1463
|
+
MapMarker markerView = getMarkerMap(marker);
|
|
1464
|
+
return markerView.getInfoContents();
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
@Override
|
|
1468
|
+
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
1469
|
+
gestureDetector.onTouchEvent(ev);
|
|
1470
|
+
|
|
1471
|
+
int X = (int) ev.getX();
|
|
1472
|
+
int Y = (int) ev.getY();
|
|
1473
|
+
if (map != null) {
|
|
1474
|
+
tapLocation = map.getProjection().fromScreenLocation(new Point(X, Y));
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
int action = MotionEventCompat.getActionMasked(ev);
|
|
1478
|
+
|
|
1479
|
+
switch (action) {
|
|
1480
|
+
case (MotionEvent.ACTION_DOWN):
|
|
1481
|
+
this.getParent().requestDisallowInterceptTouchEvent(
|
|
1482
|
+
map != null && map.getUiSettings().isScrollGesturesEnabled());
|
|
1483
|
+
break;
|
|
1484
|
+
case (MotionEvent.ACTION_UP):
|
|
1485
|
+
// Clear this regardless, since isScrollGesturesEnabled() may have been updated
|
|
1486
|
+
this.getParent().requestDisallowInterceptTouchEvent(false);
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
super.dispatchTouchEvent(ev);
|
|
1490
|
+
return true;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
@Override
|
|
1494
|
+
public void onMarkerDragStart(Marker marker) {
|
|
1495
|
+
WritableMap event = makeClickEventData(marker.getPosition());
|
|
1496
|
+
dispatchEvent(event, OnMarkerDragStartEvent::new);
|
|
1497
|
+
|
|
1498
|
+
MapMarker markerView = getMarkerMap(marker);
|
|
1499
|
+
event = makeClickEventData(marker.getPosition());
|
|
1500
|
+
dispatchEvent(event, OnMarkerDragStartEvent::new, markerView.getId(), context);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
@Override
|
|
1504
|
+
public void onMarkerDrag(Marker marker) {
|
|
1505
|
+
WritableMap event = makeClickEventData(marker.getPosition());
|
|
1506
|
+
dispatchEvent(event, OnMarkerDragEvent::new);
|
|
1507
|
+
|
|
1508
|
+
MapMarker markerView = getMarkerMap(marker);
|
|
1509
|
+
event = makeClickEventData(marker.getPosition());
|
|
1510
|
+
dispatchEvent(event, OnMarkerDragEvent::new, markerView.getId(), context);
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
@Override
|
|
1514
|
+
public void onMarkerDragEnd(Marker marker) {
|
|
1515
|
+
WritableMap event = makeClickEventData(marker.getPosition());
|
|
1516
|
+
dispatchEvent(event, OnMarkerDragEndEvent::new);
|
|
1517
|
+
MapMarker markerView = getMarkerMap(marker);
|
|
1518
|
+
event = makeClickEventData(marker.getPosition());
|
|
1519
|
+
dispatchEvent(event, OnMarkerDragEndEvent::new, markerView.getId(), context);
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
@Override
|
|
1523
|
+
public void onPoiClick(PointOfInterest poi) {
|
|
1524
|
+
WritableMap event = makeClickEventData(poi.latLng);
|
|
1525
|
+
|
|
1526
|
+
event.putString("placeId", poi.placeId);
|
|
1527
|
+
event.putString("name", poi.name);
|
|
1528
|
+
dispatchEvent(event, OnPoiClickEvent::new);
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
private ProgressBar getMapLoadingProgressBar() {
|
|
1532
|
+
if (this.mapLoadingProgressBar == null) {
|
|
1533
|
+
this.mapLoadingProgressBar = new ProgressBar(getContext());
|
|
1534
|
+
this.mapLoadingProgressBar.setIndeterminate(true);
|
|
1535
|
+
}
|
|
1536
|
+
if (this.loadingIndicatorColor != null) {
|
|
1537
|
+
this.setLoadingIndicatorColor(this.loadingIndicatorColor);
|
|
1538
|
+
}
|
|
1539
|
+
return this.mapLoadingProgressBar;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
private RelativeLayout getMapLoadingLayoutView() {
|
|
1543
|
+
if (this.mapLoadingLayout == null) {
|
|
1544
|
+
this.mapLoadingLayout = new RelativeLayout(getContext());
|
|
1545
|
+
this.mapLoadingLayout.setBackgroundColor(Color.LTGRAY);
|
|
1546
|
+
this.addView(this.mapLoadingLayout,
|
|
1547
|
+
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
|
1548
|
+
ViewGroup.LayoutParams.MATCH_PARENT));
|
|
1549
|
+
|
|
1550
|
+
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
|
1551
|
+
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
|
1552
|
+
params.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
1553
|
+
this.mapLoadingLayout.addView(this.getMapLoadingProgressBar(), params);
|
|
1554
|
+
|
|
1555
|
+
this.mapLoadingLayout.setVisibility(View.INVISIBLE);
|
|
1556
|
+
}
|
|
1557
|
+
this.setLoadingBackgroundColor(this.loadingBackgroundColor);
|
|
1558
|
+
return this.mapLoadingLayout;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
private ImageView getCacheImageView() {
|
|
1562
|
+
if (this.cacheImageView == null) {
|
|
1563
|
+
this.cacheImageView = new ImageView(getContext());
|
|
1564
|
+
this.addView(this.cacheImageView,
|
|
1565
|
+
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
|
1566
|
+
ViewGroup.LayoutParams.MATCH_PARENT));
|
|
1567
|
+
this.cacheImageView.setVisibility(View.INVISIBLE);
|
|
1568
|
+
}
|
|
1569
|
+
return this.cacheImageView;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
private void removeCacheImageView() {
|
|
1573
|
+
if (this.cacheImageView != null) {
|
|
1574
|
+
((ViewGroup) this.cacheImageView.getParent()).removeView(this.cacheImageView);
|
|
1575
|
+
this.cacheImageView = null;
|
|
1370
1576
|
}
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
private void removeMapLoadingProgressBar() {
|
|
1580
|
+
if (this.mapLoadingProgressBar != null) {
|
|
1581
|
+
((ViewGroup) this.mapLoadingProgressBar.getParent()).removeView(this.mapLoadingProgressBar);
|
|
1582
|
+
this.mapLoadingProgressBar = null;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1371
1585
|
|
|
1372
|
-
|
|
1373
|
-
|
|
1586
|
+
private void removeMapLoadingLayoutView() {
|
|
1587
|
+
this.removeMapLoadingProgressBar();
|
|
1588
|
+
if (this.mapLoadingLayout != null) {
|
|
1589
|
+
((ViewGroup) this.mapLoadingLayout.getParent()).removeView(this.mapLoadingLayout);
|
|
1590
|
+
this.mapLoadingLayout = null;
|
|
1374
1591
|
}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
private void cacheView() {
|
|
1595
|
+
if (this.cacheEnabled) {
|
|
1596
|
+
final ImageView cacheImageView = this.getCacheImageView();
|
|
1597
|
+
final RelativeLayout mapLoadingLayout = this.getMapLoadingLayoutView();
|
|
1598
|
+
cacheImageView.setVisibility(View.INVISIBLE);
|
|
1599
|
+
mapLoadingLayout.setVisibility(View.VISIBLE);
|
|
1600
|
+
if (this.isMapLoaded) {
|
|
1601
|
+
this.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
|
|
1602
|
+
@Override
|
|
1603
|
+
public void onSnapshotReady(Bitmap bitmap) {
|
|
1604
|
+
cacheImageView.setImageBitmap(bitmap);
|
|
1605
|
+
cacheImageView.setVisibility(View.VISIBLE);
|
|
1606
|
+
mapLoadingLayout.setVisibility(View.INVISIBLE);
|
|
1607
|
+
}
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
} else {
|
|
1611
|
+
this.removeCacheImageView();
|
|
1612
|
+
if (this.isMapLoaded) {
|
|
1613
|
+
this.removeMapLoadingLayoutView();
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
public void onPanDrag(MotionEvent ev) {
|
|
1619
|
+
Point point = new Point((int) ev.getX(), (int) ev.getY());
|
|
1620
|
+
LatLng coords = this.map.getProjection().fromScreenLocation(point);
|
|
1621
|
+
WritableMap event = makeClickEventData(coords);
|
|
1622
|
+
dispatchEvent(event, OnPanDragEvent::new);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
public void onDoublePress(MotionEvent ev) {
|
|
1626
|
+
if (this.map == null) return;
|
|
1627
|
+
Point point = new Point((int) ev.getX(), (int) ev.getY());
|
|
1628
|
+
LatLng coords = this.map.getProjection().fromScreenLocation(point);
|
|
1629
|
+
WritableMap event = makeClickEventData(coords);
|
|
1630
|
+
dispatchEvent(event, OnDoublePressEvent::new);
|
|
1631
|
+
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
public void setKmlSrc(String kmlSrc) {
|
|
1635
|
+
if (isMapReady) {
|
|
1636
|
+
try {
|
|
1637
|
+
InputStream kmlStream = new FileUtil(context).execute(kmlSrc).get();
|
|
1638
|
+
|
|
1639
|
+
if (kmlStream == null) {
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
KmlLayer kmlLayer = new KmlLayer(map, kmlStream, context, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
|
|
1644
|
+
|
|
1645
|
+
kmlLayer.addLayerToMap();
|
|
1646
|
+
|
|
1647
|
+
WritableMap pointers = new WritableNativeMap();
|
|
1648
|
+
WritableArray markers = new WritableNativeArray();
|
|
1649
|
+
|
|
1650
|
+
if (kmlLayer.getContainers() == null) {
|
|
1651
|
+
dispatchEvent(pointers, OnKmlReadyEvent::new);
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
//Retrieve a nested container within the first container
|
|
1656
|
+
KmlContainer container = kmlLayer.getContainers().iterator().next();
|
|
1657
|
+
if (container == null || container.getContainers() == null) {
|
|
1658
|
+
dispatchEvent(pointers, OnKmlReadyEvent::new);
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
if (container.getContainers().iterator().hasNext()) {
|
|
1664
|
+
container = container.getContainers().iterator().next();
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
int index = 0;
|
|
1668
|
+
for (KmlPlacemark placemark : container.getPlacemarks()) {
|
|
1669
|
+
MarkerOptions options = new MarkerOptions();
|
|
1670
|
+
|
|
1671
|
+
if (placemark.getInlineStyle() != null) {
|
|
1672
|
+
options = placemark.getMarkerOptions();
|
|
1673
|
+
} else {
|
|
1674
|
+
options.icon(BitmapDescriptorFactory.defaultMarker());
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
LatLng latLng = ((LatLng) placemark.getGeometry().getGeometryObject());
|
|
1678
|
+
String title = "";
|
|
1679
|
+
String snippet = "";
|
|
1680
|
+
|
|
1681
|
+
if (placemark.hasProperty("name")) {
|
|
1682
|
+
title = placemark.getProperty("name");
|
|
1683
|
+
}
|
|
1375
1684
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1685
|
+
if (placemark.hasProperty("description")) {
|
|
1686
|
+
snippet = placemark.getProperty("description");
|
|
1687
|
+
}
|
|
1379
1688
|
|
|
1689
|
+
options.position(latLng);
|
|
1690
|
+
options.title(title);
|
|
1691
|
+
options.snippet(snippet);
|
|
1692
|
+
// FIXME: get markerManager from somewhere
|
|
1693
|
+
/*
|
|
1380
1694
|
MapMarker marker = new MapMarker(context, options, this.manager.getMarkerManager());
|
|
1381
1695
|
|
|
1382
1696
|
if (placemark.getInlineStyle() != null
|
|
@@ -1393,127 +1707,129 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
|
|
|
1393
1707
|
|
|
1394
1708
|
addFeature(marker, index++);
|
|
1395
1709
|
|
|
1710
|
+
|
|
1396
1711
|
WritableMap loadedMarker = makeClickEventData(latLng);
|
|
1397
1712
|
loadedMarker.putString("id", identifier);
|
|
1398
1713
|
loadedMarker.putString("title", title);
|
|
1399
1714
|
loadedMarker.putString("description", snippet);
|
|
1400
1715
|
|
|
1401
1716
|
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();
|
|
1717
|
+
*/
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
pointers.putArray("markers", markers);
|
|
1721
|
+
dispatchEvent(new WritableNativeMap(), OnKmlReadyEvent::new);
|
|
1722
|
+
|
|
1723
|
+
} catch (XmlPullParserException | IOException | InterruptedException |
|
|
1724
|
+
ExecutionException e) {
|
|
1725
|
+
e.printStackTrace();
|
|
1726
|
+
}
|
|
1727
|
+
} else {
|
|
1728
|
+
this.kmlSrc = kmlSrc;
|
|
1481
1729
|
}
|
|
1482
|
-
}
|
|
1483
1730
|
}
|
|
1484
|
-
}
|
|
1485
1731
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1732
|
+
@Override
|
|
1733
|
+
public void onIndoorBuildingFocused() {
|
|
1734
|
+
IndoorBuilding building = this.map.getFocusedBuilding();
|
|
1735
|
+
if (building != null) {
|
|
1736
|
+
List<IndoorLevel> levels = building.getLevels();
|
|
1737
|
+
int index = 0;
|
|
1738
|
+
WritableArray levelsArray = Arguments.createArray();
|
|
1739
|
+
for (IndoorLevel level : levels) {
|
|
1740
|
+
WritableMap levelMap = Arguments.createMap();
|
|
1741
|
+
levelMap.putInt("index", index);
|
|
1742
|
+
levelMap.putString("name", level.getName());
|
|
1743
|
+
levelMap.putString("shortName", level.getShortName());
|
|
1744
|
+
levelsArray.pushMap(levelMap);
|
|
1745
|
+
index++;
|
|
1746
|
+
}
|
|
1747
|
+
WritableMap event = Arguments.createMap();
|
|
1748
|
+
WritableMap indoorBuilding = Arguments.createMap();
|
|
1749
|
+
indoorBuilding.putArray("levels", levelsArray);
|
|
1750
|
+
indoorBuilding.putInt("activeLevelIndex", building.getActiveLevelIndex());
|
|
1751
|
+
indoorBuilding.putBoolean("underground", building.isUnderground());
|
|
1752
|
+
|
|
1753
|
+
event.putMap("indoorBuilding", indoorBuilding);
|
|
1754
|
+
dispatchEvent(event, OnIndoorBuildingFocusedEvent::new);
|
|
1755
|
+
} else {
|
|
1756
|
+
WritableMap event = Arguments.createMap();
|
|
1757
|
+
WritableArray levelsArray = Arguments.createArray();
|
|
1758
|
+
WritableMap indoorBuilding = Arguments.createMap();
|
|
1759
|
+
indoorBuilding.putArray("levels", levelsArray);
|
|
1760
|
+
indoorBuilding.putInt("activeLevelIndex", 0);
|
|
1761
|
+
indoorBuilding.putBoolean("underground", false);
|
|
1762
|
+
|
|
1763
|
+
event.putMap("indoorBuilding", indoorBuilding);
|
|
1764
|
+
dispatchEvent(event, OnIndoorBuildingFocusedEvent::new);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1488
1767
|
|
|
1489
|
-
|
|
1490
|
-
|
|
1768
|
+
@Override
|
|
1769
|
+
public void onIndoorLevelActivated(IndoorBuilding building) {
|
|
1770
|
+
if (building == null) {
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
int activeLevelIndex = building.getActiveLevelIndex();
|
|
1774
|
+
if (activeLevelIndex < 0 || activeLevelIndex >= building.getLevels().size()) {
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
IndoorLevel level = building.getLevels().get(activeLevelIndex);
|
|
1778
|
+
|
|
1779
|
+
WritableMap event = Arguments.createMap();
|
|
1780
|
+
WritableMap indoorlevel = Arguments.createMap();
|
|
1781
|
+
|
|
1782
|
+
indoorlevel.putInt("activeLevelIndex", activeLevelIndex);
|
|
1783
|
+
indoorlevel.putString("name", level.getName());
|
|
1784
|
+
indoorlevel.putString("shortName", level.getShortName());
|
|
1785
|
+
|
|
1786
|
+
event.putMap("indoorLevel", indoorlevel);
|
|
1787
|
+
dispatchEvent(event, OnIndoorLevelActivatedEvent::new);
|
|
1491
1788
|
}
|
|
1492
1789
|
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1790
|
+
public void setIndoorActiveLevelIndex(int activeLevelIndex) {
|
|
1791
|
+
IndoorBuilding building = this.map.getFocusedBuilding();
|
|
1792
|
+
if (building != null) {
|
|
1793
|
+
if (activeLevelIndex >= 0 && activeLevelIndex < building.getLevels().size()) {
|
|
1794
|
+
IndoorLevel level = building.getLevels().get(activeLevelIndex);
|
|
1795
|
+
if (level != null) {
|
|
1796
|
+
level.activate();
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1499
1800
|
}
|
|
1500
1801
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1802
|
+
private MapMarker getMarkerMap(Marker marker) {
|
|
1803
|
+
MapMarker airMarker = markerMap.get(marker);
|
|
1804
|
+
|
|
1805
|
+
if (airMarker != null) {
|
|
1806
|
+
return airMarker;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
for (Map.Entry<Marker, MapMarker> entryMarker : markerMap.entrySet()) {
|
|
1810
|
+
if (entryMarker.getKey().getPosition().equals(marker.getPosition())
|
|
1811
|
+
&& entryMarker.getKey().getTitle().equals(marker.getTitle())) {
|
|
1812
|
+
airMarker = entryMarker.getValue();
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1503
1816
|
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
super.requestLayout();
|
|
1507
|
-
post(measureAndLayout);
|
|
1508
|
-
}
|
|
1817
|
+
return airMarker;
|
|
1818
|
+
}
|
|
1509
1819
|
|
|
1510
|
-
private final Runnable measureAndLayout = new Runnable() {
|
|
1511
1820
|
@Override
|
|
1512
|
-
public void
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
1821
|
+
public void requestLayout() {
|
|
1822
|
+
super.requestLayout();
|
|
1823
|
+
post(measureAndLayout);
|
|
1516
1824
|
}
|
|
1517
|
-
|
|
1825
|
+
|
|
1826
|
+
private final Runnable measureAndLayout = new Runnable() {
|
|
1827
|
+
@Override
|
|
1828
|
+
public void run() {
|
|
1829
|
+
measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
|
|
1830
|
+
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
|
|
1831
|
+
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1518
1834
|
|
|
1519
1835
|
}
|