1. Add MTImageMapView.h and MTImageMapView.m file in Project

2. Add BridgeHeader File

#import “MTImageMapView.h”

3. Add Custom Class MTImageMapView in UIImageView 

4. Add Image and Coordinate .plist file in Project

coordinate file added to image different coordinate location

4. Outlet of UIImageVIew

@IBOutlet weak var imgView: MTImageMapView!

var arrCoordinates:NSArray = []

5. set Image Layout

override func viewDidLoad() {

        super.viewDidLoad()

        self.setImageLayout()

       imgView.isUserInteractionEnabled = true

    }

func setImageLayout(){

        let strImageName = “img”

        DispatchQueue.main.async {self.imgView.deallocImageMap()}

       setImage(strImageName)

        arrCoordinates = NSArray(contentsOfFile: Bundle.main.path(forResource: “coordinate”, ofType: “plist”)!)!

        DispatchQueue.main.async {

            self.imgView.setMapping(self.arrCoordinates as? [Any], doneBlock: nil)

        }

    }

func setImage(_ strImageName:String){

        imgView.image = UIImage(named: strImageName)

        self.view.layoutIfNeeded()

    }

6. Add Delegate to MTImageMapDelegate

7. Delegate Method To detect User To Which Coordinate to tapped

extension ViewController:MTImageMapDelegate{

    func imageMapView(_ inImageMapView: MTImageMapView!, touchesBeganMapArea inIndexSelected: UInt, areaCentrePoint point: CGPoint)

    {

        print(“Start Location Selected:- \(inIndexSelected)”)

   }

    func imageMapView(_ inImageMapView: MTImageMapView!, touchesEndMapArea inIndexSelected: UInt, areaCentrePoint point: CGPoint) {

        print(“EndLocation Selected:- \(inIndexSelected)”)

    }

}

You may also like

Leave a Reply