Skip to content

Commit dbec6ec

Browse files
fix null pointer in ArcgsMapView
1 parent b94d68c commit dbec6ec

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

arcgis_map_sdk_android/android/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ group 'dev.fluttercommunity.arcgis_map_sdk_android'
22
version '1.0-SNAPSHOT'
33

44
buildscript {
5-
ext.kotlin_version = '1.6.10'
5+
ext.kotlin_version = '1.9.0'
66
repositories {
77
google()
88
mavenCentral()
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:7.1.3'
12+
classpath 'com.android.tools.build:gradle:8.3.2'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
1515
}
@@ -29,8 +29,7 @@ apply plugin: 'com.android.library'
2929
apply plugin: 'kotlin-android'
3030

3131
android {
32-
compileSdkVersion 31
33-
32+
compileSdkVersion 34
3433

3534
// Conditional for compatibility with AGP <4.2.
3635
if (project.android.hasProperty("namespace")) {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Thu Oct 24 09:10:14 CEST 2024
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/ArcgisMapView.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,24 @@ internal class ArcgisMapView(
101101
mapView.graphicsOverlays.add(defaultGraphicsOverlay)
102102

103103
mapView.addMapScaleChangedListener {
104-
val zoomLevel = getZoomLevel(mapView)
104+
if(mapView.mapScale.isNaN()) return@addMapScaleChangedListener
105105

106+
val zoomLevel = getZoomLevel(mapView)
106107
zoomStreamHandler.addZoom(zoomLevel)
107108
}
109+
108110
mapView.addViewpointChangedListener {
109-
val center = mapView.visibleArea.extent.center
110-
val wgs84Center =
111-
GeometryEngine.project(center, SpatialReferences.getWgs84()) as Point
112-
centerPositionStreamHandler.add(
113-
LatLng(
114-
longitude = wgs84Center.x,
115-
latitude = wgs84Center.y
116-
)
117-
)
111+
// The viewpoint listener is executed async which means that the map
112+
// can be altered when this is called. If we reload the map or dispose the map
113+
// we don't have a visibleArea or an extent which would throw null pointer in this case.
114+
val center = mapView.visibleArea?.extent?.center ?: return@addViewpointChangedListener
115+
val wgs84Center = GeometryEngine.project(center, SpatialReferences.getWgs84()) as? Point
116+
117+
val latLng = wgs84Center?.let {
118+
LatLng(longitude = it.x,latitude = it.y)
119+
} ?: return@addViewpointChangedListener
120+
121+
centerPositionStreamHandler.add(latLng)
118122
}
119123

120124
val viewPoint = Viewpoint(

0 commit comments

Comments
 (0)