Select to view content in your preferred language

mapView.PointerMoved functionality (similar to .NET api)?

923
5
Jump to solution
09-26-2019 05:17 AM
WesBailes
Occasional Contributor

I use the pointermoved functionality in a .NET app and was wondering if something similar is available for Android? I have an android device that has a smart stylus and would like to handle the movements (pointer over) above the map if at all possible.  I haven't done extensive research as of yet, but curious as to if anyone had some info.  thanks!

0 Kudos
1 Solution

Accepted Solutions
WesBailes
Occasional Contributor

Actually figured it out.  setOnHoverListener() did the trick:

mapView.setOnHoverListener(object:View.OnHoverListener {
    override fun onHover(v:View, event:MotionEvent):Boolean {

        val screenPoint = android.graphics.Point(
            Math.round(event!!.x),
            Math.round(event!!.y)
        )

        val mapPoint = mapView.screenToLocation(screenPoint)
        when (event.getAction()) {
            MotionEvent.ACTION_HOVER_ENTER -> hover_text.text ="entered the map at (x: ${mapPoint.x}, y: ${mapPoint.y})"
            MotionEvent.ACTION_HOVER_MOVE ->  hover_text.text = "currently hovering on (x: ${mapPoint.x}, y: ${mapPoint.y})"
            MotionEvent.ACTION_HOVER_EXIT ->  hover_text.text ="no longer hovering, left the map at (x: ${mapPoint.x}, y: ${mapPoint.y}))"
        }
        return false
    }
})

View solution in original post

0 Kudos
5 Replies
MarkBaird
Esri Regular Contributor

Yes, but before I answer the question can you confirm which SDK you are using.  Are you using Android as with Android Studio, or writing a Xamarin cross platform app with Visual Studio?

0 Kudos
WesBailes
Occasional Contributor

Mark, thanks for the reply!  Yes using ArcGIS Runtime for Android (100.6) with Android Studio 3.5.  

0 Kudos
MarkBaird
Esri Regular Contributor

So the PointerMoved method you've seen is probably a specific method for working with WPF controls.

As a start I'd take a look at this sample to see some basics of interacting with MapViews in Android controls:

Feature Layer Selection | ArcGIS for Developers 

It shows you how you can implement a touch listener.

WesBailes
Occasional Contributor

Thanks!  I may check into the setCapturePointerListener method to see what it does.

0 Kudos
WesBailes
Occasional Contributor

Actually figured it out.  setOnHoverListener() did the trick:

mapView.setOnHoverListener(object:View.OnHoverListener {
    override fun onHover(v:View, event:MotionEvent):Boolean {

        val screenPoint = android.graphics.Point(
            Math.round(event!!.x),
            Math.round(event!!.y)
        )

        val mapPoint = mapView.screenToLocation(screenPoint)
        when (event.getAction()) {
            MotionEvent.ACTION_HOVER_ENTER -> hover_text.text ="entered the map at (x: ${mapPoint.x}, y: ${mapPoint.y})"
            MotionEvent.ACTION_HOVER_MOVE ->  hover_text.text = "currently hovering on (x: ${mapPoint.x}, y: ${mapPoint.y})"
            MotionEvent.ACTION_HOVER_EXIT ->  hover_text.text ="no longer hovering, left the map at (x: ${mapPoint.x}, y: ${mapPoint.y}))"
        }
        return false
    }
})
0 Kudos