Adding Interactivity

The MPIMapViewDelegate protocol 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() is a callback function that is executed when a polygon is touched. This function will pass in an 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.

func onPolygonClicked(polygon: MPIPolygon) {
mapView?.cameraManager.focusOn(targets: MPIOptions.CameraTargets(polygons: [polygon]))
mapView?.setPolygonColor(polygon: polygon, color: "blue")


onNothingClicked() is a callback function that is execute when the user touches outside the interactive polygons. A common use case of this function is to reset the changes made by tapping polygons.

func onNothingClicked() {
Was this page helpful?

Next Topic