Skip to content

ScaleBar crash when used with AutoPanMode.NAVIGATION #201

@chakflying

Description

@chakflying

So I'm using Jetpack Compose + AndroidViewBinding, but those technicalities shouldn't make much difference. Here is how I setup the scaleBar:

   AndroidViewBinding(
        factory = { layoutInflater: LayoutInflater, viewGroup: ViewGroup, b: Boolean ->
            val viewBinding = MapLayoutBinding.inflate(layoutInflater, viewGroup, b)

            ...

            // Init Scale Bar
            val scaleBar = Scalebar(viewBinding.mapView.context)
            with(scaleBar) {
                alignment = Scalebar.Alignment.LEFT
                style = Style.LINE
                textSize = 28
                addToMapView(viewBinding.mapView)
            }

            ...

            return@AndroidViewBinding viewBinding

Then when the view is loaded, I setup locationDisplay to center on current location:

    val locationDisplay = mapView.locationDisplay
    with(locationDisplay) {
        isShowAccuracy = true
        startAsync()
        addDataSourceStatusChangedListener {
            if (it.isStarted) {
                 locationDisplay.autoPanMode = LocationDisplay.AutoPanMode.NAVIGATION
            }
        }
    }

If I either remove the scaleBar or comment out the line locationDisplay.autoPanMode, it works fine. But having both will cause crash when the view is loaded:

java.util.NoSuchElementException: Array contains no element matching the predicate.
        at com.esri.arcgisruntime.toolkit.extension.ScalebarRendererExtensionsKt.selectMultiplierData(ScalebarRendererExtensions.kt:155)
        at com.esri.arcgisruntime.toolkit.extension.ScalebarRendererExtensionsKt.calculateBestLength(ScalebarRendererExtensions.kt:63)
        at com.esri.arcgisruntime.toolkit.scalebar.Scalebar.onDraw(Scalebar.kt:462)
        at android.view.View.draw(View.java:22350)
        at android.view.View.updateDisplayListIfDirty(View.java:21226)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.View.draw(View.java:22081)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4516)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)
        at android.view.View.draw(View.java:22353)
        at androidx.compose.ui.platform.AndroidViewsHandler.drawView(AndroidViewsHandler.android.kt:72)
        at androidx.compose.ui.platform.AndroidComposeView.drawAndroidView(AndroidComposeView.android.kt:481)
        at androidx.compose.ui.viewinterop.AndroidViewHolder$layoutNode$1$coreModifier$1.invoke(AndroidViewHolder.android.kt:235)
        at androidx.compose.ui.viewinterop.AndroidViewHolder$layoutNode$1$coreModifier$1.invoke(AndroidViewHolder.android.kt:232)
        at androidx.compose.ui.draw.DrawBackgroundModifier.draw(DrawModifier.kt:101)
        at androidx.compose.ui.node.ModifiedDrawNode.performDraw(ModifiedDrawNode.kt:102)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:244)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performDraw(DelegatingLayoutNodeWrapper.kt:68)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:244)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performDraw(DelegatingLayoutNodeWrapper.kt:68)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:244)
        at androidx.compose.ui.node.LayoutNodeDrawScope.drawContent(LayoutNodeDrawScope.kt:42)
        at com.google.accompanist.placeholder.PlaceholderKt$placeholder$4$1$1.invoke(Placeholder.kt:168)
        at com.google.accompanist.placeholder.PlaceholderKt$placeholder$4$1$1.invoke(Placeholder.kt:160)
        at androidx.compose.ui.draw.DrawWithContentModifier.draw(DrawModifier.kt:263)
        ...

I'm not sure how this can happen. Does the autoPanMode cause the map to be in a state where the scale is invalid?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions