Adding Interactivity

The MPIMapViewListener interface enables the onPolygonClicked() and onNothingClicked() functions which react to user touch. We can leverage these callback functions to add interactivity and functionality to our map.

onPolygonClicked

onPolygonClicked() is a callback function that is executed when a polygon is touched. This function will pass in an MPINavigable.MPIPolygon parameter which allows you to access different properties of the touched polygon. A common use of this function is to focus the camera on and highlight the polygon.

override fun onPolygonClicked(polygon: MPINavigatable.MPIPolygon) {
mapView?.cameraManager?.focusOn(MPIOptions.CameraTargets(polygons = listOf(polygon)))
mapView?.setPolygonColor(polygon, "blue")
}

onNothingClicked

onNothingClicked() is a callback function that is execute when the user touches outside the interactive polygons.

override fun onNothingClicked() {
mapView?.clearAllPolygonColors() {
it?.message?.let { message ->
Log.e("clearAllPolygonColors", message)
}
}
}
Was this page helpful?

Next Topic

Labels