Skip to content

Map Events

This document aims to guide you through the use of MapEventsListener and MapEventsHandler. The first one allows you to listen to the Map Events of the Pointr Map, and the latter allows you to modify the behavior of the Map Widget upon Map Events.

MapEventsListener

This is an interface that once implemented and added to the Pointr Map Widget, allows you to subscribe and listen to the Map Events like POI tap, map tap, etc.

Note

When you add a MapEventsListener, the default Map behavior of Pointr stays as is. The callbacks are triggered as a result of these operations.

An example to the usage can be found as below:

    mapWidgetFragment.addListener(object: MapEventsListener {
        override fun mapDidEndLoading(mapFragment: PTRMapFragment) {
            mapWidgetFragment.mapFragment!!.maximumZoomLevel = 18.7
        }
    })
    class ViewController: UIViewController, PTRMapEventsListener {

       func presentMapWidget() {
         let mapWidget = PTRMapWidgetViewController(configuration: configuration)
         mapWidget.mapViewController.addListener(self)
         ​​mapWidget.modalPresentationStyle = .fullScreen
         present(mapWidget, animated: true, completion: nil)
       }

       func map(_ map: PTRMapViewController, didZoom zoomValue: Double) {
           // Map zoomed
        }
    }

The available callbacks of MapEventsListener can be found on the Reference:

MapEventsHandler

This is an open class which handles the Map Events of the Pointr Map Widget. It has a default implementation that the Pointr Map Widget uses which provides the default behavior upon map events. If you set your own MapEventsHandler to Pointr Map Widget, you get to override the default behavior. Only the methods implemented in the custom MapEventsHandler will be overridden. It is not mandatory to override every operation.

Warning

Overriding an event, and not calling super will completely remove the default Pointr behavior upon that event. So, you should be careful when overriding these methods to not cause unwanted behavior.

For example, if you override the mapDidReceiveTapOnPoi, and do not call super.mapDidReceiveTapOnPoi, Pointr bottom sheet will not be displayed upon tapping on a poi.

If you override mapDidEndLoading callback, and do not call super.mapDidEndLoading, this will prevent the map from appearing on the map widget.

mapWidgetFragment.mapEventsHandler = object: MapEventsHandler(mapWidgetFragment) {
    override fun mapDidReceiveTapOnPoi(mapFragment: PTRMapFragment, poi: Poi) {
        // Show custom Poi Selection bottom sheet
    }

    override fun mapDidEndLoading(mapFragment: PTRMapFragment) {
        super.mapDidEndLoading(mapFragment) // super call is required when overriding this
        // Do operations after map load
    }
}
class ViewController: UIViewController {

final class MyMapEventsHandler: PTRMapEventsHandler {
    override func mapDidEndLoading(_ map: PTRMapViewController) {
        super.mapDidEndLoading(map)
        // your code
    }
}

func presentMapWidget() {
       let mapWidget = PTRMapWidgetViewController(configuration: configuration)
       let myMapEventsHandler = MyMapEventsHandler(mapWidget: mapWidget)
       mapWidget.mapEventsHandler = myMapEventsHandler
       mapWidget.modalPresentationStyle = .fullScreen
       present(mapWidget, animated: true, completion: nil)
    }
}

The available methods of the MapEventsHandler can be found on the reference:


Last update: June 4, 2024
Back to top