Skip to content

Instantly share code, notes, and snippets.

@CartBlanche
Created July 6, 2011 23:24
Show Gist options
  • Save CartBlanche/1068585 to your computer and use it in GitHub Desktop.
Save CartBlanche/1068585 to your computer and use it in GitHub Desktop.
MyViewDelegate
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.MapKit;
using MonoTouch.Dialog;
namespace Sample
{
class MyViewDelegate : MKMapViewDelegate
{
DialogViewController _dvc;
UIWebView _webView;
public MyViewDelegate(DialogViewController aDialogViewController)
{
_dvc = aDialogViewController;
}
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MyMapAnnotation)
{
var csAnnotation = (MyMapAnnotation)annotation;
var identifier = "pin";
MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(identifier);
if (pinView == null)
{
pinView = new MKPinAnnotationView(csAnnotation, identifier);
}
pinView.Image = csAnnotation.PinImage;
var moreButton = UIButton.FromType(UIButtonType.DetailDisclosure);
pinView.RightCalloutAccessoryView = moreButton;
annotationView = pinView;
//annotationView.transform = CGAffineTransform.MakeScale(2.0, 2.0);
annotationView.Enabled = true;
annotationView.CanShowCallout = true;
}
return annotationView;
}
public override void CalloutAccessoryControlTapped (MKMapView mapView, MKAnnotationView view, UIControl control)
{
if (view.Annotation is MyMapAnnotation)
{
var csAnnotation = view.Annotation as MyMapAnnotation;
if (_webView == null )
{
_webView = new UIWebView();
}
_webView.Frame = new RectangleF (0, 0, _dvc.View.Frame.Width, _dvc.View.Frame.Height);
NSUrl nsurl = new NSUrl ("http://www.savagesoftwaresolutions.com/case.asp?CID=" + csAnnotation.CID);
NSUrlRequest req = new NSUrlRequest (nsurl);
_webView.LoadRequest(req);
_webView.ScalesPageToFit = true;
_dvc.View.AddSubview(_webView);
}
}
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view )
{
if (view.Annotation is MyMapAnnotation)
{
var csAnnotation = (MyMapAnnotation)view.Annotation;
var data = NSData.FromUrl(new NSUrl("http://www.savagesoftwaresolutions.com/FILES/image/"+ csAnnotation.Image));
var imageview = new UIImageView(UIImage.LoadFromData(data));
imageview.Frame = new RectangleF(2, 2, 50, 50);
view.LeftCalloutAccessoryView = imageview;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment