neilang / NAMapKit

Allows you to use custom maps in iphone applications and attempts to mimics some of the behaviour of the MapKit framework
MIT License
263 stars 52 forks source link

Add a demo with a custom pin annotation #54

Open dblock opened 8 years ago

dblock commented 8 years ago

From https://github.com/neilang/NAMapKit/issues/52, add a demo project that uses a completely custom pin annotation image.

saravananNV commented 8 years ago

@dblock are you going to develop this customization as new feature.have you started to work on this

thanks

dblock commented 8 years ago

No, I have not started to work on this. Customization is already a feature, https://github.com/neilang/NAMapKit/blob/master/README.md#custom-annotations. You're not getting much help here because you're asking for fairly basic things, and I totally understand that you're just starting programming in Objective-C, but people contributing to this project don't really have time to teach you the basics. I suggest finding a friend or colleague who's a bit more experienced and pairing with them on this.

saravananNV commented 8 years ago

i have override the naannotation class as below

class CustomClassView: NAAnnotation {

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

override func createViewOnMapView(mapView: NAMapView) -> UIView {
    var view: UIButton = UIButton()
    view.setBackgroundImage(UIImage(named: "pin_green"), forState: .Normal)
    return view
}

}

and my main function as

class View1: UIViewController{

var bgImage: UIImageView?
var mapView : NAPinAnnotationMapView = NAPinAnnotationMapView()
var melbourne : NAPinAnnotation = NAPinAnnotation()
var melbourne_view : NAPinAnnotationView = NAPinAnnotationView()
var call_outView : NAPinAnnotationCallOutView = NAPinAnnotationCallOutView()
var annotation : CustomClassView = CustomClassView()
var dot: NADotAnnotation = NADotAnnotation()
@IBOutlet var floorMapImage: UIImageView!
/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

override func viewDidLoad() {
   mapView = NAPinAnnotationMapView(frame: self.view.bounds)
   // mapView = NAPinAnnotationMapView(frame: CGRectMake(0 , 0, 600,200))
    mapView.backgroundColor = UIColor.whiteColor()
    mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
    mapView.minimumZoomScale = 0.5
    mapView.maximumZoomScale = 0.5
    mapView.displayMap(UIImage(named: "floor_map"))
    melbourne = NAPinAnnotation.annotationWithPoint(CGPointMake(547.0, 460.0)) as! NAPinAnnotation
    melbourne.title = "Sample"
    melbourne.subtitle = "I have a subtitle"
    annotation.createViewOnMapView(mapView)
    mapView.addAnnotation(melbourne, animated: false)
    self.view!.addSubview(mapView)
    let button   = UIButton(type: UIButtonType.System) as UIButton
    button.frame = CGRectMake(100, 300, 100, 50)
    button.setTitle("Test Button", forState: UIControlState.Normal)
    button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
    mapView.addSubview(button)

// dot = NADotAnnotation.annotationWithPoint(CGPointMake(547.0,460.0)) as! NADotAnnotation // mapView.addAnnotation(dot, animated: true) } }

but pin customization image was not working...