@@ -71,6 +71,7 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter,
71
71
private boolean handlePanDrag = false ;
72
72
private boolean moveOnMarkerPress = true ;
73
73
private boolean cacheEnabled = false ;
74
+ private boolean initialRegionSet = false ;
74
75
75
76
private static final String [] PERMISSIONS = new String []{
76
77
"android.permission.ACCESS_FINE_LOCATION" , "android.permission.ACCESS_COARSE_LOCATION" };
@@ -305,7 +306,9 @@ public void onHostResume() {
305
306
map .setMyLocationEnabled (showUserLocation );
306
307
}
307
308
synchronized (AirMapView .this ) {
308
- AirMapView .this .onResume ();
309
+ if (!destroyed ) {
310
+ AirMapView .this .onResume ();
311
+ }
309
312
paused = false ;
310
313
}
311
314
}
@@ -359,6 +362,13 @@ public synchronized void doDestroy() {
359
362
onDestroy ();
360
363
}
361
364
365
+ public void setInitialRegion (ReadableMap initialRegion ) {
366
+ if (!initialRegionSet && initialRegion != null ) {
367
+ setRegion (initialRegion );
368
+ initialRegionSet = true ;
369
+ }
370
+ }
371
+
362
372
public void setRegion (ReadableMap region ) {
363
373
if (region == null ) return ;
364
374
@@ -713,13 +723,13 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
713
723
// Timer Implementation
714
724
715
725
public void startMonitoringRegion () {
716
- if (isMonitoringRegion ) return ;
726
+ if (map == null || isMonitoringRegion ) return ;
717
727
timerHandler .postDelayed (timerRunnable , 100 );
718
728
isMonitoringRegion = true ;
719
729
}
720
730
721
731
public void stopMonitoringRegion () {
722
- if (!isMonitoringRegion ) return ;
732
+ if (map == null || !isMonitoringRegion ) return ;
723
733
timerHandler .removeCallbacks (timerRunnable );
724
734
isMonitoringRegion = false ;
725
735
}
@@ -732,16 +742,18 @@ public void stopMonitoringRegion() {
732
742
@ Override
733
743
public void run () {
734
744
735
- Projection projection = map .getProjection ();
736
- VisibleRegion region = (projection != null ) ? projection .getVisibleRegion () : null ;
737
- LatLngBounds bounds = (region != null ) ? region .latLngBounds : null ;
738
-
739
- if ((bounds != null ) &&
740
- (lastBoundsEmitted == null ||
741
- LatLngBoundsUtils .BoundsAreDifferent (bounds , lastBoundsEmitted ))) {
742
- LatLng center = map .getCameraPosition ().target ;
743
- lastBoundsEmitted = bounds ;
744
- eventDispatcher .dispatchEvent (new RegionChangeEvent (getId (), bounds , center , true ));
745
+ if (map != null ) {
746
+ Projection projection = map .getProjection ();
747
+ VisibleRegion region = (projection != null ) ? projection .getVisibleRegion () : null ;
748
+ LatLngBounds bounds = (region != null ) ? region .latLngBounds : null ;
749
+
750
+ if ((bounds != null ) &&
751
+ (lastBoundsEmitted == null ||
752
+ LatLngBoundsUtils .BoundsAreDifferent (bounds , lastBoundsEmitted ))) {
753
+ LatLng center = map .getCameraPosition ().target ;
754
+ lastBoundsEmitted = bounds ;
755
+ eventDispatcher .dispatchEvent (new RegionChangeEvent (getId (), bounds , center , true ));
756
+ }
745
757
}
746
758
747
759
timerHandler .postDelayed (this , 100 );
0 commit comments