react-native-maps 1.21.0-alpha.66 → 1.21.0-alpha.67
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.
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
package com.rnmaps.fabric;
|
|
2
2
|
|
|
3
|
+
import static com.rnmaps.maps.MapModule.SNAPSHOT_FORMAT_JPG;
|
|
4
|
+
import static com.rnmaps.maps.MapModule.SNAPSHOT_FORMAT_PNG;
|
|
5
|
+
import static com.rnmaps.maps.MapModule.SNAPSHOT_RESULT_BASE64;
|
|
6
|
+
import static com.rnmaps.maps.MapModule.SNAPSHOT_RESULT_FILE;
|
|
7
|
+
import static com.rnmaps.maps.MapModule.closeQuietly;
|
|
8
|
+
|
|
9
|
+
import android.graphics.Bitmap;
|
|
10
|
+
import android.net.Uri;
|
|
11
|
+
import android.util.Base64;
|
|
12
|
+
import android.util.DisplayMetrics;
|
|
13
|
+
|
|
14
|
+
import androidx.annotation.Nullable;
|
|
15
|
+
|
|
3
16
|
import com.facebook.fbreact.specs.NativeAirMapsModuleSpec;
|
|
4
17
|
import com.facebook.react.bridge.Arguments;
|
|
5
18
|
import com.facebook.react.bridge.Promise;
|
|
@@ -8,9 +21,18 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
8
21
|
import com.facebook.react.bridge.UIManager;
|
|
9
22
|
import com.facebook.react.bridge.WritableMap;
|
|
10
23
|
import com.facebook.react.uimanager.UIManagerHelper;
|
|
24
|
+
import com.google.android.gms.maps.GoogleMap;
|
|
11
25
|
import com.google.android.gms.maps.model.CameraPosition;
|
|
26
|
+
import com.rnmaps.maps.MapUIBlock;
|
|
12
27
|
import com.rnmaps.maps.MapView;
|
|
13
28
|
|
|
29
|
+
import org.json.JSONException;
|
|
30
|
+
import org.json.JSONObject;
|
|
31
|
+
|
|
32
|
+
import java.io.ByteArrayOutputStream;
|
|
33
|
+
import java.io.File;
|
|
34
|
+
import java.io.FileOutputStream;
|
|
35
|
+
|
|
14
36
|
public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
|
|
15
37
|
public NativeAirMapsModule(ReactApplicationContext reactContext) {
|
|
16
38
|
super(reactContext);
|
|
@@ -23,23 +45,23 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
|
|
|
23
45
|
|
|
24
46
|
@Override
|
|
25
47
|
public void getCamera(double tag, Promise promise) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
UIManager uiManager = UIManagerHelper.getUIManagerForReactTag(getReactApplicationContext(), (int) tag);
|
|
49
|
+
getReactApplicationContext().runOnUiQueueThread(new Runnable() {
|
|
50
|
+
@Override
|
|
51
|
+
public void run() {
|
|
52
|
+
MapView view = (MapView) uiManager.resolveView((int) tag);
|
|
53
|
+
CameraPosition position = view.map.getCameraPosition();
|
|
54
|
+
WritableMap map = Arguments.createMap();
|
|
55
|
+
WritableMap center = Arguments.createMap();
|
|
56
|
+
center.putDouble("latitude", position.target.latitude);
|
|
57
|
+
center.putDouble("longitude", position.target.longitude);
|
|
58
|
+
map.putMap("center", center);
|
|
59
|
+
map.putDouble("heading", position.bearing);
|
|
60
|
+
map.putDouble("pitch", position.tilt);
|
|
61
|
+
map.putDouble("zoom", position.zoom);
|
|
62
|
+
promise.resolve(map);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
@Override
|
|
@@ -54,7 +76,74 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
|
|
|
54
76
|
|
|
55
77
|
@Override
|
|
56
78
|
public void takeSnapshot(double tag, String config, Promise promise) {
|
|
57
|
-
|
|
79
|
+
WritableMap options = null;
|
|
80
|
+
try {
|
|
81
|
+
if (config != null) {
|
|
82
|
+
JSONObject jsonObject = new JSONObject(config);
|
|
83
|
+
options = JSONUtil.convertJsonToWritable(jsonObject);
|
|
84
|
+
WritableMap finalOptions = options;
|
|
85
|
+
|
|
86
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
87
|
+
final String format = finalOptions.hasKey("format") ? finalOptions.getString("format") : "png";
|
|
88
|
+
final Bitmap.CompressFormat compressFormat =
|
|
89
|
+
format.equals(SNAPSHOT_FORMAT_PNG) ? Bitmap.CompressFormat.PNG :
|
|
90
|
+
format.equals(SNAPSHOT_FORMAT_JPG) ? Bitmap.CompressFormat.JPEG : null;
|
|
91
|
+
final double quality = finalOptions.hasKey("quality") ? finalOptions.getDouble("quality") : 1.0;
|
|
92
|
+
final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
|
93
|
+
final Integer width =
|
|
94
|
+
finalOptions.hasKey("width") ? (int) (displayMetrics.density * finalOptions.getDouble("width")) : 0;
|
|
95
|
+
final Integer height =
|
|
96
|
+
finalOptions.hasKey("height") ? (int) (displayMetrics.density * finalOptions.getDouble("height")) : 0;
|
|
97
|
+
final String result = finalOptions.hasKey("result") ? finalOptions.getString("result") : "file";
|
|
98
|
+
|
|
99
|
+
UIManager uiManager = UIManagerHelper.getUIManagerForReactTag(getReactApplicationContext(), (int) tag);
|
|
100
|
+
getReactApplicationContext().runOnUiQueueThread(new Runnable() {
|
|
101
|
+
@Override
|
|
102
|
+
public void run() {
|
|
103
|
+
MapView view = (MapView) uiManager.resolveView((int) tag);
|
|
104
|
+
view.map.snapshot(snapshot -> {
|
|
105
|
+
|
|
106
|
+
// Convert image to requested width/height if necessary
|
|
107
|
+
if (snapshot == null) {
|
|
108
|
+
promise.reject("Failed to generate bitmap, snapshot = null");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if ((width != 0) && (height != 0) &&
|
|
112
|
+
(width != snapshot.getWidth() || height != snapshot.getHeight())) {
|
|
113
|
+
snapshot = Bitmap.createScaledBitmap(snapshot, width, height, true);
|
|
114
|
+
}
|
|
115
|
+
// Save the snapshot to disk
|
|
116
|
+
if (result.equals(SNAPSHOT_RESULT_FILE)) {
|
|
117
|
+
File tempFile;
|
|
118
|
+
FileOutputStream outputStream;
|
|
119
|
+
try {
|
|
120
|
+
tempFile =
|
|
121
|
+
File.createTempFile("AirMapSnapshot", "." + format, context.getCacheDir());
|
|
122
|
+
outputStream = new FileOutputStream(tempFile);
|
|
123
|
+
} catch (Exception e) {
|
|
124
|
+
promise.reject(e);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
|
|
128
|
+
closeQuietly(outputStream);
|
|
129
|
+
String uri = Uri.fromFile(tempFile).toString();
|
|
130
|
+
promise.resolve(uri);
|
|
131
|
+
} else if (result.equals(SNAPSHOT_RESULT_BASE64)) {
|
|
132
|
+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
133
|
+
snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
|
|
134
|
+
closeQuietly(outputStream);
|
|
135
|
+
byte[] bytes = outputStream.toByteArray();
|
|
136
|
+
String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
137
|
+
promise.resolve(data);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
} catch (JSONException e) {
|
|
144
|
+
promise.reject("Failed to parse config ", config);
|
|
145
|
+
|
|
146
|
+
}
|
|
58
147
|
}
|
|
59
148
|
|
|
60
149
|
@Override
|
|
@@ -35,249 +35,249 @@ import java.util.Map;
|
|
|
35
35
|
@ReactModule(name = MapModule.NAME)
|
|
36
36
|
public class MapModule extends ReactContextBaseJavaModule {
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Override
|
|
49
|
-
public String getName() {
|
|
50
|
-
return NAME;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Override
|
|
54
|
-
public Map<String, Object> getConstants() {
|
|
55
|
-
final Map<String, Object> constants = new HashMap<>();
|
|
56
|
-
constants.put("legalNotice", "This license information is displayed in Settings > Google > Open Source on any device running Google Play services.");
|
|
57
|
-
return constants;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public Activity getActivity() {
|
|
61
|
-
return getCurrentActivity();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public static void closeQuietly(Closeable closeable) {
|
|
65
|
-
if (closeable == null) return;
|
|
66
|
-
try {
|
|
67
|
-
closeable.close();
|
|
68
|
-
} catch (IOException ignored) {
|
|
38
|
+
public static final String NAME = "AirMapModule";
|
|
39
|
+
public static final String SNAPSHOT_RESULT_FILE = "file";
|
|
40
|
+
public static final String SNAPSHOT_RESULT_BASE64 = "base64";
|
|
41
|
+
public static final String SNAPSHOT_FORMAT_PNG = "png";
|
|
42
|
+
public static final String SNAPSHOT_FORMAT_JPG = "jpg";
|
|
43
|
+
|
|
44
|
+
public MapModule(ReactApplicationContext reactContext) {
|
|
45
|
+
super(reactContext);
|
|
69
46
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@ReactMethod
|
|
73
|
-
public void takeSnapshot(final int tag, final ReadableMap options, final Promise promise) {
|
|
74
|
-
|
|
75
|
-
// Parse and verity options
|
|
76
|
-
final ReactApplicationContext context = getReactApplicationContext();
|
|
77
|
-
final String format = options.hasKey("format") ? options.getString("format") : "png";
|
|
78
|
-
final Bitmap.CompressFormat compressFormat =
|
|
79
|
-
format.equals(SNAPSHOT_FORMAT_PNG) ? Bitmap.CompressFormat.PNG :
|
|
80
|
-
format.equals(SNAPSHOT_FORMAT_JPG) ? Bitmap.CompressFormat.JPEG : null;
|
|
81
|
-
final double quality = options.hasKey("quality") ? options.getDouble("quality") : 1.0;
|
|
82
|
-
final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
|
83
|
-
final Integer width =
|
|
84
|
-
options.hasKey("width") ? (int) (displayMetrics.density * options.getDouble("width")) : 0;
|
|
85
|
-
final Integer height =
|
|
86
|
-
options.hasKey("height") ? (int) (displayMetrics.density * options.getDouble("height")) : 0;
|
|
87
|
-
final String result = options.hasKey("result") ? options.getString("result") : "file";
|
|
88
|
-
|
|
89
|
-
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
|
|
90
|
-
view.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
|
|
91
|
-
public void onSnapshotReady(@Nullable Bitmap snapshot) {
|
|
92
|
-
|
|
93
|
-
// Convert image to requested width/height if necessary
|
|
94
|
-
if (snapshot == null) {
|
|
95
|
-
promise.reject("Failed to generate bitmap, snapshot = null");
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if ((width != 0) && (height != 0) &&
|
|
99
|
-
(width != snapshot.getWidth() || height != snapshot.getHeight())) {
|
|
100
|
-
snapshot = Bitmap.createScaledBitmap(snapshot, width, height, true);
|
|
101
|
-
}
|
|
102
47
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
tempFile =
|
|
109
|
-
File.createTempFile("AirMapSnapshot", "." + format, context.getCacheDir());
|
|
110
|
-
outputStream = new FileOutputStream(tempFile);
|
|
111
|
-
} catch (Exception e) {
|
|
112
|
-
promise.reject(e);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
|
|
116
|
-
closeQuietly(outputStream);
|
|
117
|
-
String uri = Uri.fromFile(tempFile).toString();
|
|
118
|
-
promise.resolve(uri);
|
|
119
|
-
} else if (result.equals(SNAPSHOT_RESULT_BASE64)) {
|
|
120
|
-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
121
|
-
snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
|
|
122
|
-
closeQuietly(outputStream);
|
|
123
|
-
byte[] bytes = outputStream.toByteArray();
|
|
124
|
-
String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
125
|
-
promise.resolve(data);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
48
|
+
@Override
|
|
49
|
+
public String getName() {
|
|
50
|
+
return NAME;
|
|
51
|
+
}
|
|
129
52
|
|
|
130
|
-
|
|
131
|
-
|
|
53
|
+
@Override
|
|
54
|
+
public Map<String, Object> getConstants() {
|
|
55
|
+
final Map<String, Object> constants = new HashMap<>();
|
|
56
|
+
constants.put("legalNotice", "This license information is displayed in Settings > Google > Open Source on any device running Google Play services.");
|
|
57
|
+
return constants;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public Activity getActivity() {
|
|
61
|
+
return getCurrentActivity();
|
|
62
|
+
}
|
|
132
63
|
|
|
133
|
-
|
|
64
|
+
public static void closeQuietly(Closeable closeable) {
|
|
65
|
+
if (closeable == null) return;
|
|
66
|
+
try {
|
|
67
|
+
closeable.close();
|
|
68
|
+
} catch (IOException ignored) {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
134
71
|
|
|
135
|
-
|
|
136
|
-
|
|
72
|
+
@ReactMethod
|
|
73
|
+
public void takeSnapshot(final int tag, final ReadableMap options, final Promise promise) {
|
|
74
|
+
|
|
75
|
+
// Parse and verity options
|
|
76
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
77
|
+
final String format = options.hasKey("format") ? options.getString("format") : "png";
|
|
78
|
+
final Bitmap.CompressFormat compressFormat =
|
|
79
|
+
format.equals(SNAPSHOT_FORMAT_PNG) ? Bitmap.CompressFormat.PNG :
|
|
80
|
+
format.equals(SNAPSHOT_FORMAT_JPG) ? Bitmap.CompressFormat.JPEG : null;
|
|
81
|
+
final double quality = options.hasKey("quality") ? options.getDouble("quality") : 1.0;
|
|
82
|
+
final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
|
83
|
+
final Integer width =
|
|
84
|
+
options.hasKey("width") ? (int) (displayMetrics.density * options.getDouble("width")) : 0;
|
|
85
|
+
final Integer height =
|
|
86
|
+
options.hasKey("height") ? (int) (displayMetrics.density * options.getDouble("height")) : 0;
|
|
87
|
+
final String result = options.hasKey("result") ? options.getString("result") : "file";
|
|
88
|
+
|
|
89
|
+
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
|
|
90
|
+
view.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
|
|
91
|
+
public void onSnapshotReady(@Nullable Bitmap snapshot) {
|
|
92
|
+
|
|
93
|
+
// Convert image to requested width/height if necessary
|
|
94
|
+
if (snapshot == null) {
|
|
95
|
+
promise.reject("Failed to generate bitmap, snapshot = null");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if ((width != 0) && (height != 0) &&
|
|
99
|
+
(width != snapshot.getWidth() || height != snapshot.getHeight())) {
|
|
100
|
+
snapshot = Bitmap.createScaledBitmap(snapshot, width, height, true);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Save the snapshot to disk
|
|
104
|
+
if (result.equals(SNAPSHOT_RESULT_FILE)) {
|
|
105
|
+
File tempFile;
|
|
106
|
+
FileOutputStream outputStream;
|
|
107
|
+
try {
|
|
108
|
+
tempFile =
|
|
109
|
+
File.createTempFile("AirMapSnapshot", "." + format, context.getCacheDir());
|
|
110
|
+
outputStream = new FileOutputStream(tempFile);
|
|
111
|
+
} catch (Exception e) {
|
|
112
|
+
promise.reject(e);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
|
|
116
|
+
closeQuietly(outputStream);
|
|
117
|
+
String uri = Uri.fromFile(tempFile).toString();
|
|
118
|
+
promise.resolve(uri);
|
|
119
|
+
} else if (result.equals(SNAPSHOT_RESULT_BASE64)) {
|
|
120
|
+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
121
|
+
snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
|
|
122
|
+
closeQuietly(outputStream);
|
|
123
|
+
byte[] bytes = outputStream.toByteArray();
|
|
124
|
+
String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
125
|
+
promise.resolve(data);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
137
129
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
final ReactApplicationContext context = getReactApplicationContext();
|
|
130
|
+
return null;
|
|
131
|
+
});
|
|
141
132
|
|
|
142
|
-
|
|
143
|
-
CameraPosition position = view.map.getCameraPosition();
|
|
133
|
+
// Add UI-block so we can get a valid reference to the map-view
|
|
144
134
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
centerJson.putDouble("longitude", position.target.longitude);
|
|
135
|
+
uiBlock.addToUIManager();
|
|
136
|
+
}
|
|
148
137
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
cameraJson.putDouble("zoom", (double)position.zoom);
|
|
153
|
-
cameraJson.putDouble("pitch", (double)position.tilt);
|
|
138
|
+
@ReactMethod
|
|
139
|
+
public void getCamera(final int tag, final Promise promise) {
|
|
140
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
154
141
|
|
|
155
|
-
promise
|
|
142
|
+
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
|
|
143
|
+
CameraPosition position = view.map.getCameraPosition();
|
|
156
144
|
|
|
157
|
-
|
|
158
|
-
|
|
145
|
+
WritableMap centerJson = new WritableNativeMap();
|
|
146
|
+
centerJson.putDouble("latitude", position.target.latitude);
|
|
147
|
+
centerJson.putDouble("longitude", position.target.longitude);
|
|
159
148
|
|
|
160
|
-
|
|
161
|
-
|
|
149
|
+
WritableMap cameraJson = new WritableNativeMap();
|
|
150
|
+
cameraJson.putMap("center", centerJson);
|
|
151
|
+
cameraJson.putDouble("heading", (double) position.bearing);
|
|
152
|
+
cameraJson.putDouble("zoom", (double) position.zoom);
|
|
153
|
+
cameraJson.putDouble("pitch", (double) position.tilt);
|
|
162
154
|
|
|
163
|
-
|
|
164
|
-
public void getAddressFromCoordinates(final int tag, final ReadableMap coordinate, final Promise promise) {
|
|
165
|
-
final ReactApplicationContext context = getReactApplicationContext();
|
|
155
|
+
promise.resolve(cameraJson);
|
|
166
156
|
|
|
167
|
-
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, mapView -> {
|
|
168
|
-
if (coordinate == null ||
|
|
169
|
-
!coordinate.hasKey("latitude") ||
|
|
170
|
-
!coordinate.hasKey("longitude")) {
|
|
171
|
-
promise.reject("Invalid coordinate format");
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
Geocoder geocoder = new Geocoder(context);
|
|
175
|
-
try {
|
|
176
|
-
List<Address> list =
|
|
177
|
-
geocoder.getFromLocation(coordinate.getDouble("latitude"),coordinate.getDouble("longitude"),1);
|
|
178
|
-
if (list.isEmpty()) {
|
|
179
|
-
promise.reject("Can not get address location");
|
|
180
157
|
return null;
|
|
181
|
-
|
|
182
|
-
Address address = list.get(0);
|
|
183
|
-
|
|
184
|
-
WritableMap addressJson = new WritableNativeMap();
|
|
185
|
-
addressJson.putString("name", address.getFeatureName());
|
|
186
|
-
addressJson.putString("locality", address.getLocality());
|
|
187
|
-
addressJson.putString("thoroughfare", address.getThoroughfare());
|
|
188
|
-
addressJson.putString("subThoroughfare", address.getSubThoroughfare());
|
|
189
|
-
addressJson.putString("subLocality", address.getSubLocality());
|
|
190
|
-
addressJson.putString("administrativeArea", address.getAdminArea());
|
|
191
|
-
addressJson.putString("subAdministrativeArea", address.getSubAdminArea());
|
|
192
|
-
addressJson.putString("postalCode", address.getPostalCode());
|
|
193
|
-
addressJson.putString("countryCode", address.getCountryCode());
|
|
194
|
-
addressJson.putString("country", address.getCountryName());
|
|
195
|
-
|
|
196
|
-
promise.resolve(addressJson);
|
|
197
|
-
} catch (IOException e) {
|
|
198
|
-
promise.reject("Can not get address location");
|
|
199
|
-
}
|
|
158
|
+
});
|
|
200
159
|
|
|
201
|
-
|
|
202
|
-
}
|
|
160
|
+
uiBlock.addToUIManager();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@ReactMethod
|
|
164
|
+
public void getAddressFromCoordinates(final int tag, final ReadableMap coordinate, final Promise promise) {
|
|
165
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
166
|
+
|
|
167
|
+
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, mapView -> {
|
|
168
|
+
if (coordinate == null ||
|
|
169
|
+
!coordinate.hasKey("latitude") ||
|
|
170
|
+
!coordinate.hasKey("longitude")) {
|
|
171
|
+
promise.reject("Invalid coordinate format");
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
Geocoder geocoder = new Geocoder(context);
|
|
175
|
+
try {
|
|
176
|
+
List<Address> list =
|
|
177
|
+
geocoder.getFromLocation(coordinate.getDouble("latitude"), coordinate.getDouble("longitude"), 1);
|
|
178
|
+
if (list.isEmpty()) {
|
|
179
|
+
promise.reject("Can not get address location");
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
Address address = list.get(0);
|
|
183
|
+
|
|
184
|
+
WritableMap addressJson = new WritableNativeMap();
|
|
185
|
+
addressJson.putString("name", address.getFeatureName());
|
|
186
|
+
addressJson.putString("locality", address.getLocality());
|
|
187
|
+
addressJson.putString("thoroughfare", address.getThoroughfare());
|
|
188
|
+
addressJson.putString("subThoroughfare", address.getSubThoroughfare());
|
|
189
|
+
addressJson.putString("subLocality", address.getSubLocality());
|
|
190
|
+
addressJson.putString("administrativeArea", address.getAdminArea());
|
|
191
|
+
addressJson.putString("subAdministrativeArea", address.getSubAdminArea());
|
|
192
|
+
addressJson.putString("postalCode", address.getPostalCode());
|
|
193
|
+
addressJson.putString("countryCode", address.getCountryCode());
|
|
194
|
+
addressJson.putString("country", address.getCountryName());
|
|
195
|
+
|
|
196
|
+
promise.resolve(addressJson);
|
|
197
|
+
} catch (IOException e) {
|
|
198
|
+
promise.reject("Can not get address location");
|
|
199
|
+
}
|
|
203
200
|
|
|
204
|
-
|
|
205
|
-
|
|
201
|
+
return null;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
uiBlock.addToUIManager();
|
|
205
|
+
}
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
@ReactMethod
|
|
208
|
+
public void pointForCoordinate(final int tag, ReadableMap coordinate, final Promise promise) {
|
|
209
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
210
|
+
final double density = (double) context.getResources().getDisplayMetrics().density;
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
final LatLng coord = new LatLng(
|
|
213
|
+
coordinate.hasKey("latitude") ? coordinate.getDouble("latitude") : 0.0,
|
|
214
|
+
coordinate.hasKey("longitude") ? coordinate.getDouble("longitude") : 0.0
|
|
215
|
+
);
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
|
|
218
|
+
Point pt = view.map.getProjection().toScreenLocation(coord);
|
|
219
219
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
WritableMap ptJson = new WritableNativeMap();
|
|
221
|
+
ptJson.putDouble("x", (double) pt.x / density);
|
|
222
|
+
ptJson.putDouble("y", (double) pt.y / density);
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
promise.resolve(ptJson);
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
return null;
|
|
227
|
+
});
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
uiBlock.addToUIManager();
|
|
230
|
+
}
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
@ReactMethod
|
|
233
|
+
public void coordinateForPoint(final int tag, ReadableMap point, final Promise promise) {
|
|
234
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
235
|
+
final double density = (double) context.getResources().getDisplayMetrics().density;
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
237
|
+
final Point pt = new Point(
|
|
238
|
+
point.hasKey("x") ? (int) (point.getDouble("x") * density) : 0,
|
|
239
|
+
point.hasKey("y") ? (int) (point.getDouble("y") * density) : 0
|
|
240
|
+
);
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
|
|
243
|
+
LatLng coord = view.map.getProjection().fromScreenLocation(pt);
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
WritableMap coordJson = new WritableNativeMap();
|
|
246
|
+
coordJson.putDouble("latitude", coord.latitude);
|
|
247
|
+
coordJson.putDouble("longitude", coord.longitude);
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
promise.resolve(coordJson);
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
return null;
|
|
252
|
+
});
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
uiBlock.addToUIManager();
|
|
255
|
+
}
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
@ReactMethod
|
|
258
|
+
public void getMapBoundaries(final int tag, final Promise promise) {
|
|
259
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
|
|
262
|
+
double[][] boundaries = view.getMapBoundaries();
|
|
263
263
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
WritableMap coordinates = new WritableNativeMap();
|
|
265
|
+
WritableMap northEastHash = new WritableNativeMap();
|
|
266
|
+
WritableMap southWestHash = new WritableNativeMap();
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
northEastHash.putDouble("longitude", boundaries[0][0]);
|
|
269
|
+
northEastHash.putDouble("latitude", boundaries[0][1]);
|
|
270
|
+
southWestHash.putDouble("longitude", boundaries[1][0]);
|
|
271
|
+
southWestHash.putDouble("latitude", boundaries[1][1]);
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
coordinates.putMap("northEast", northEastHash);
|
|
274
|
+
coordinates.putMap("southWest", southWestHash);
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
promise.resolve(coordinates);
|
|
277
277
|
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
return null;
|
|
279
|
+
});
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
uiBlock.addToUIManager();
|
|
282
|
+
}
|
|
283
283
|
}
|
package/lib/MapView.js
CHANGED
|
@@ -206,15 +206,9 @@ class MapView extends React.Component {
|
|
|
206
206
|
if (config.result !== 'file' && config.result !== 'base64') {
|
|
207
207
|
throw new Error('Invalid result specified');
|
|
208
208
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
else if (react_native_1.Platform.OS === 'ios') {
|
|
214
|
-
if (this.fabricMap.current) {
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
return this.fabricMap.current.takeSnapshot(config);
|
|
217
|
-
}
|
|
209
|
+
if (this.fabricMap.current) {
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
return this.fabricMap.current.takeSnapshot(config);
|
|
218
212
|
}
|
|
219
213
|
return Promise.reject('takeSnapshot not supported on this platform');
|
|
220
214
|
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Leland Richardson <leland.m.richardson@gmail.com>",
|
|
7
7
|
"homepage": "https://github.com/react-native-maps/react-native-maps#readme",
|
|
8
|
-
"version": "1.21.0-alpha.
|
|
8
|
+
"version": "1.21.0-alpha.67",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"lint": "eslint . --max-warnings 0",
|