react-native-maps 1.21.0-alpha.57 → 1.21.0-alpha.59

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.
@@ -0,0 +1,86 @@
1
+ package com.rnmaps.fabric;
2
+
3
+ import com.facebook.react.bridge.Arguments;
4
+ import com.facebook.react.bridge.WritableArray;
5
+ import com.facebook.react.bridge.WritableMap;
6
+
7
+ import org.json.JSONArray;
8
+ import org.json.JSONException;
9
+ import org.json.JSONObject;
10
+
11
+ import java.util.Iterator;
12
+
13
+ public class JSONUtil {
14
+ public static WritableMap convertJsonToWritable(JSONObject jsonObject) throws JSONException {
15
+ WritableMap map = Arguments.createMap();
16
+ Iterator<String> iterator = jsonObject.keys();
17
+
18
+ while (iterator.hasNext()) {
19
+ String key = iterator.next();
20
+ Object value = jsonObject.get(key);
21
+
22
+ if (value == JSONObject.NULL) {
23
+ map.putNull(key);
24
+ }
25
+ // Check primitive types first
26
+ else if (value instanceof Integer) {
27
+ map.putInt(key, jsonObject.getInt(key));
28
+ }
29
+ else if (value instanceof Long) {
30
+ map.putDouble(key, ((Long) value).doubleValue());
31
+ }
32
+ else if (value instanceof Double) {
33
+ map.putDouble(key, jsonObject.getDouble(key));
34
+ }
35
+ else if (value instanceof Boolean) {
36
+ map.putBoolean(key, jsonObject.getBoolean(key));
37
+ }
38
+ else if (value instanceof String) {
39
+ map.putString(key, jsonObject.getString(key));
40
+ }
41
+ // Check complex types
42
+ else if (value instanceof JSONObject) {
43
+ map.putMap(key, convertJsonToWritable(jsonObject.getJSONObject(key)));
44
+ }
45
+ else if (value instanceof JSONArray) {
46
+ map.putArray(key, convertJsonArrayToWritable(jsonObject.getJSONArray(key)));
47
+ }
48
+ }
49
+
50
+ return map;
51
+ }
52
+ public static WritableArray convertJsonArrayToWritable(JSONArray jsonArray) throws JSONException {
53
+ WritableArray array = Arguments.createArray();
54
+
55
+ for (int i = 0; i < jsonArray.length(); i++) {
56
+ Object value = jsonArray.get(i);
57
+
58
+ if (value == JSONObject.NULL) {
59
+ array.pushNull();
60
+ }
61
+ else if (value instanceof Integer) {
62
+ array.pushInt((Integer) value);
63
+ }
64
+ else if (value instanceof Long) {
65
+ array.pushDouble(((Long) value).doubleValue());
66
+ }
67
+ else if (value instanceof Double) {
68
+ array.pushDouble((Double) value);
69
+ }
70
+ else if (value instanceof Boolean) {
71
+ array.pushBoolean((Boolean) value);
72
+ }
73
+ else if (value instanceof String) {
74
+ array.pushString((String) value);
75
+ }
76
+ else if (value instanceof JSONObject) {
77
+ array.pushMap(convertJsonToWritable((JSONObject) value));
78
+ }
79
+ else if (value instanceof JSONArray) {
80
+ array.pushArray(convertJsonArrayToWritable((JSONArray) value));
81
+ }
82
+ }
83
+
84
+ return array;
85
+ }
86
+ }
@@ -9,8 +9,15 @@ import android.view.View;
9
9
  import androidx.annotation.NonNull;
10
10
  import androidx.annotation.Nullable;
11
11
 
12
+ import org.json.JSONArray;
13
+ import org.json.JSONException;
14
+ import org.json.JSONObject;
15
+
16
+ import com.facebook.react.bridge.Arguments;
12
17
  import com.facebook.react.bridge.ReactApplicationContext;
13
18
  import com.facebook.react.bridge.ReadableMap;
19
+ import com.facebook.react.bridge.WritableArray;
20
+ import com.facebook.react.bridge.WritableMap;
14
21
  import com.facebook.react.module.annotations.ReactModule;
15
22
  import com.facebook.react.uimanager.LayoutShadowNode;
16
23
  import com.facebook.react.uimanager.ReactStylesDiffMap;
@@ -25,6 +32,8 @@ import com.google.android.gms.maps.GoogleMap;
25
32
  import com.google.android.gms.maps.GoogleMapOptions;
26
33
  import com.google.android.gms.maps.MapsInitializer;
27
34
  import com.google.android.gms.maps.model.CameraPosition;
35
+ import com.google.android.gms.maps.model.LatLng;
36
+ import com.google.android.gms.maps.model.LatLngBounds;
28
37
  import com.rnmaps.maps.MapView;
29
38
  import com.rnmaps.maps.SizeReportingShadowNode;
30
39
 
@@ -467,32 +476,97 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
467
476
 
468
477
  @Override
469
478
  public void animateToRegion(MapView view, String regionJSON, int duration) {
479
+ try {
480
+ JSONObject region = new JSONObject(regionJSON);
481
+ double lng = region.getDouble("longitude");
482
+ double lat = region.getDouble("latitude");
483
+ double lngDelta = region.getDouble("longitudeDelta");
484
+ double latDelta = region.getDouble("latitudeDelta");
485
+ LatLngBounds bounds = new LatLngBounds(
486
+ new LatLng(lat - latDelta / 2, lng - lngDelta / 2), // southwest
487
+ new LatLng(lat + latDelta / 2, lng + lngDelta / 2) // northeast
488
+ );
489
+ view.animateToRegion(bounds, duration);
490
+ } catch (JSONException e) {
491
+ throw new RuntimeException(e);
492
+ }
470
493
 
471
494
  }
472
495
 
473
496
  @Override
474
497
  public void setCamera(MapView view, String cameraJSON) {
475
-
498
+ try {
499
+ JSONObject camera = new JSONObject(cameraJSON);
500
+ CameraPosition position = view.cameraPositionFromJSON(camera);
501
+ view.moveToCamera(position);
502
+ } catch (JSONException e) {
503
+ Log.e("MapViewManager", "parse camera exception " + e);
504
+ }
476
505
  }
477
506
 
478
507
  @Override
479
508
  public void animateCamera(MapView view, String cameraJSON, int duration) {
480
-
509
+ try {
510
+ JSONObject camera = new JSONObject(cameraJSON);
511
+ CameraPosition position = view.cameraPositionFromJSON(camera);
512
+ view.animateToCamera(position, duration);
513
+ } catch (JSONException e) {
514
+ Log.e("MapViewManager", "parse camera exception " + e);
515
+ }
481
516
  }
482
517
 
483
518
  @Override
484
519
  public void fitToElements(MapView view, String edgePaddingJSON, boolean animated) {
520
+ try {
521
+ WritableMap map = null;
522
+ if (edgePaddingJSON != null) {
523
+ JSONObject jsonObject = new JSONObject(edgePaddingJSON);
524
+ map = JSONUtil.convertJsonToWritable(jsonObject);
525
+ }
526
+ view.fitToElements(map, animated);
527
+ } catch (JSONException e){
528
+ Log.e("MapViewManager", "parse edgePaddingJSON exception " + e);
529
+ }
485
530
 
486
531
  }
487
532
 
488
533
  @Override
489
534
  public void fitToSuppliedMarkers(MapView view, String markersJSON, String edgePaddingJSON, boolean animated) {
535
+ try {
536
+ WritableArray markers = null;
537
+ if (markersJSON != null) {
538
+ JSONArray array = new JSONArray(markersJSON);
539
+ markers = JSONUtil.convertJsonArrayToWritable(array);
540
+ }
541
+ WritableMap edgePadding = null;
542
+ if (edgePaddingJSON != null) {
543
+ JSONObject jsonObject = new JSONObject(edgePaddingJSON);
544
+ edgePadding = JSONUtil.convertJsonToWritable(jsonObject);
545
+ }
546
+ view.fitToSuppliedMarkers(markers, edgePadding, animated);
547
+ } catch (JSONException e) {
548
+ throw new RuntimeException(e);
549
+ }
490
550
 
491
551
  }
492
552
 
493
553
  @Override
494
554
  public void fitToCoordinates(MapView view, String coordinatesJSON, String edgePaddingJSON, boolean animated) {
495
-
555
+ try {
556
+ WritableArray coordinates = null;
557
+ if (coordinatesJSON != null) {
558
+ JSONArray array = new JSONArray(coordinatesJSON);
559
+ coordinates = JSONUtil.convertJsonArrayToWritable(array);
560
+ }
561
+ WritableMap edgePadding = null;
562
+ if (edgePaddingJSON != null) {
563
+ JSONObject jsonObject = new JSONObject(edgePaddingJSON);
564
+ edgePadding = JSONUtil.convertJsonToWritable(jsonObject);
565
+ }
566
+ view.fitToCoordinates(coordinates, edgePadding, animated);
567
+ } catch (JSONException e) {
568
+ throw new RuntimeException(e);
569
+ }
496
570
  }
497
571
 
498
572
  @Override