Skip to content
Developers Docs

Mapsted Maps - Mobile Docs

Migration guide to 6.1.0

Migration Guide to 6.1.0+

This guide is provided to assist with the migration from Mapsted SDK v6.0.3 to v6.1.0+

iOS

We have restructured map events, click listeners and entity and overlay click listeners in the mobile sdk, as outlined below.

Map, Entity, Overlay Click Listeners

Overview

In SDK version 6.1.0, we have improved the listener callbacks for map, entity, and overlay interactions to simplify and unify handling. This update provides more streamlined management of events such as clicks and map movements.

Key Changes
  • New Listener Types: Introduced MapClickListener and MapEventListener interfaces to replace previous multiple listeners - MNMapVectorElementListenerDelegate, MNMapVectorTileEventListenerDelegate and MNMapListenerDelegate.
  • Simplified Callbacks: The callback methods have been refactored to provide better context and reduce code redundancy.
Migration Steps
1. Adding Listener Delegates

In previous versions, we used to set up listeners with the following calls:

    mapViewController.addMapTileEventListenerDelegate(delegate: self)
    mapViewController.addMapVectorElementListenerDelegate(delegate: self)
    mapViewController.addMapListenerDelegate(delegate: self)

In SDK v6.1.0+, this has been simplified to:

    mapViewController.addMapEventListenerDelegate(delegate: self)
    mapViewController.addMapClickListernerDelegate(delegate: self)

Here mapViewController is an object of MNMapViewController

2. Remove Listener Delegates

In previous versions, we used to remove listeners with the following calls:

    mapViewController.removeMapTileEventListenerDelegate(delegate: self)
    mapViewController.removeMapVectorElementListenerDelegate(delegate: self)
    mapViewController.removeMapListenerDelegate(delegate: self)

In SDK v6.1.0+, this has been simplified to:

    mapViewController.removeMapEventListenerDelegate(delegate: self)
    mapViewController.removeMapClickListenerDelegate(delegate: self)

Here mapViewController is an object of MNMapViewController

3. Implementing Listener Callbacks

In previous versions, we used to handle map events across multiple delegate interfaces:

extension YourViewController: MNMapVectorElementListenerDelegate {
    func onPolygonTapped(polygon: MNMapPolygon, tapType: MapstedMap.MapstedMapApi.TapType, tapPos: MNMercator) { 

    }

    func onEntityTapped(entity: MNMapEntity, tapType: MapstedMap.MapstedMapApi.TapType, tapPos: MNMercator) {

    }

    func onBalloonClicked(searchEntity: MNSearchEntity) {

    }

    func onMarkerTapped(markerName: String, markerType: String) { 

    }
}

extension YourViewController: MNMapVectorTileEventListenerDelegate {
    public func onTileBalloonClicked(searchEntity: MNSearchEntity) {
        self.onBalloonClicked(searchEntity: searchEntity)
    }

    public func onTileMarkerTapped(markerName: String, markerType: String) {
        self.onMarkerTapped(markerName: markerName, markerType: markerType)
    }

    public func onTileEntityTapped(entity: MNMapEntity, tapType: MapstedMapApi.TapType, tapPos: MNMercator) {
        self.onEntityTapped(entity: entity, tapType: tapType, tapPos: tapPos)
    }

    public func onTilePolygonTapped(polygon: MNMapPolygon, tapType: MapstedMapApi.TapType, tapPos: MNMercator) {
        self.onPolygonTapped(polygon: polygon, tapType: tapType, tapPos: tapPos)
    }
}

extension YourViewController: MNMapListenerDelegate {
    func onMapMoved() {

    }

    func onMapStable() {

    }

    func onMapIdle() {

    }

    func func onMapInteraction() {

    }

    func outsideBuildingTapped(tapPos: MNMercator, tapType: MapstedMap.MapstedMapApi.TapType) {

    }
}

With SDK v6.1.0+, implement events with MapEventListener and MapClickListener, consolidating map, entity and overlay click events into more streamlined methods.

extension YourViewController: MapEventListener {
    func onMapEvent(event: MapstedMap.MapEvent) {
        if event == .MAP_IDLE {
            //Handle map idle
        } 
        else if event == .MAP_MOVED {
            //Handle map moved
        } 
        else if event == .MAP_STABLE {
            //Handle map stable
        } 
        else if event == .MAP_INTERACTION {
            //Handle map interaction
        }
    }
}

extension YourViewController: MapClickListener {
    func onMapClicked(event: MapstedMap.MapClickEvent) {
        if event.getClickType() == .SINGLE {
            if let clickedEntity = event.getClickEntity() {
                //Process tapped entity
            } 
            else if let mapOverlay = event.getClickOverlay(), !mapOverlay.toolTipName.isEmpty {
                //Process tapped overlay
            }
        } 
        else {
            //Handle other click types (e.g.,long-press, outside map area,tap on walk way)
        }
    }
}