react-native-maps 1.21.0-alpha.88 → 1.21.0-alpha.89

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.
@@ -7,6 +7,7 @@ import static com.rnmaps.maps.MapModule.SNAPSHOT_RESULT_FILE;
7
7
  import static com.rnmaps.maps.MapModule.closeQuietly;
8
8
 
9
9
  import android.graphics.Bitmap;
10
+ import android.graphics.Point;
10
11
  import android.location.Address;
11
12
  import android.location.Geocoder;
12
13
  import android.net.Uri;
@@ -26,6 +27,7 @@ import com.facebook.react.bridge.WritableNativeMap;
26
27
  import com.facebook.react.uimanager.UIManagerHelper;
27
28
  import com.google.android.gms.maps.GoogleMap;
28
29
  import com.google.android.gms.maps.model.CameraPosition;
30
+ import com.google.android.gms.maps.model.LatLng;
29
31
  import com.rnmaps.maps.MapUIBlock;
30
32
  import com.rnmaps.maps.MapView;
31
33
 
@@ -232,11 +234,51 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
232
234
 
233
235
  @Override
234
236
  public void getPointForCoordinate(double tag, ReadableMap coordinate, Promise promise) {
237
+ final ReactApplicationContext context = getReactApplicationContext();
238
+ final double density = (double) context.getResources().getDisplayMetrics().density;
239
+
240
+ final LatLng coord = new LatLng(
241
+ coordinate.hasKey("latitude") ? coordinate.getDouble("latitude") : 0.0,
242
+ coordinate.hasKey("longitude") ? coordinate.getDouble("longitude") : 0.0
243
+ );
244
+
245
+ MapUIBlock uiBlock = new MapUIBlock((int) tag, promise, context, view -> {
246
+ Point pt = view.map.getProjection().toScreenLocation(coord);
247
+
248
+ WritableMap ptJson = new WritableNativeMap();
249
+ ptJson.putDouble("x", (double) pt.x / density);
250
+ ptJson.putDouble("y", (double) pt.y / density);
251
+
252
+ promise.resolve(ptJson);
253
+
254
+ return null;
255
+ });
235
256
 
257
+ uiBlock.addToUIManager();
236
258
  }
237
259
 
238
260
  @Override
239
261
  public void getCoordinateForPoint(double tag, ReadableMap point, Promise promise) {
262
+ final ReactApplicationContext context = getReactApplicationContext();
263
+ final double density = (double) context.getResources().getDisplayMetrics().density;
264
+
265
+ final Point pt = new Point(
266
+ point.hasKey("x") ? (int) (point.getDouble("x") * density) : 0,
267
+ point.hasKey("y") ? (int) (point.getDouble("y") * density) : 0
268
+ );
269
+
270
+ MapUIBlock uiBlock = new MapUIBlock((int)tag, promise, context, view -> {
271
+ LatLng coord = view.map.getProjection().fromScreenLocation(pt);
272
+
273
+ WritableMap coordJson = new WritableNativeMap();
274
+ coordJson.putDouble("latitude", coord.latitude);
275
+ coordJson.putDouble("longitude", coord.longitude);
276
+
277
+ promise.resolve(coordJson);
278
+
279
+ return null;
280
+ });
240
281
 
282
+ uiBlock.addToUIManager();
241
283
  }
242
284
  }
package/lib/MapView.js CHANGED
@@ -233,13 +233,8 @@ class MapView extends React.Component {
233
233
  * @return Promise Promise with the point ({ x: Number, y: Number })
234
234
  */
235
235
  pointForCoordinate(coordinate) {
236
- if (react_native_1.Platform.OS === 'android') {
237
- return react_native_1.NativeModules.AirMapModule.pointForCoordinate(this._getHandle(), coordinate);
238
- }
239
- else if (react_native_1.Platform.OS === 'ios') {
240
- if (this.fabricMap.current) {
241
- return this.fabricMap.current.getPointForCoordinate(coordinate);
242
- }
236
+ if (this.fabricMap.current) {
237
+ return this.fabricMap.current.getPointForCoordinate(coordinate);
243
238
  }
244
239
  return Promise.reject('pointForCoordinate not supported on this platform');
245
240
  }
@@ -253,13 +248,8 @@ class MapView extends React.Component {
253
248
  * @return Promise Promise with the coordinate ({ latitude: Number, longitude: Number })
254
249
  */
255
250
  coordinateForPoint(point) {
256
- if (react_native_1.Platform.OS === 'android') {
257
- return react_native_1.NativeModules.AirMapModule.coordinateForPoint(this._getHandle(), point);
258
- }
259
- else if (react_native_1.Platform.OS === 'ios') {
260
- if (this.fabricMap.current) {
261
- return this.fabricMap.current.getCoordinateForPoint(point);
262
- }
251
+ if (this.fabricMap.current) {
252
+ return this.fabricMap.current.getCoordinateForPoint(point);
263
253
  }
264
254
  return Promise.reject('coordinateForPoint not supported on this platform');
265
255
  }
@@ -54,7 +54,7 @@ const createFabricMap = (ViewComponent, Commands) => {
54
54
  return NativeAirMapsModule_1.default.getPointForCoordinate((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
55
55
  }
56
56
  else {
57
- throw new Error('getPointForCoordinate is only supported on iOS with Fabric.');
57
+ throw new Error('getPointForCoordinate is not supported on this platform.');
58
58
  }
59
59
  },
60
60
  async getAddressFromCoordinates(coordinate) {
@@ -62,7 +62,7 @@ const createFabricMap = (ViewComponent, Commands) => {
62
62
  return NativeAirMapsModule_1.default.getAddressFromCoordinates((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
63
63
  }
64
64
  else {
65
- throw new Error('getAddressFromCoordinates is only supported on iOS with Fabric.');
65
+ throw new Error('getAddressFromCoordinates is not supported on this platform');
66
66
  }
67
67
  },
68
68
  async takeSnapshot(config) {
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.88",
8
+ "version": "1.21.0-alpha.89",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",