Bug 15053 - MKMapView.GetViewForOverlay doesn't seem to be called at all...
Summary: MKMapView.GetViewForOverlay doesn't seem to be called at all...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.9.5.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-09-27 19:23 UTC by Larry O'Brien
Modified: 2013-09-27 19:49 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Larry O'Brien 2013-09-27 19:23:58 UTC
It seems to me that MKMapView.GetViewForOverlay is not getting called at all, even if there is no OverlayRenderer assigned:

			mapView = new MKMapView(View.Bounds);	
			mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;		

			var coords = new CLLocationCoordinate2D(29.976111, 31.132778); // pyramids of giza, egypt
			var span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude));
			// set the coords and zoom on the map
			mapView.MapType = MKMapType.Satellite;
			mapView.Region = new MKCoordinateRegion(coords, span);

//			mapView.OverlayRenderer = (m, o) => {
//				if(circleRenderer == null)
//				{
//					circleRenderer = new MKCircleRenderer(o as MKCircle);
//					circleRenderer.FillColor = UIColor.Purple;
//					circleRenderer.Alpha = 0.5f;
//				}
//				return circleRenderer;
//			};

			mapView.GetViewForOverlay = (m, o) => {
				Console.WriteLine("Never called");
				if(circleView == null)
					circleView = new MKCircleView(o as MKCircle);
					circleView.BackgroundColor = UIColor.Green;
					circleView.Alpha = 0.5f;
				return circleView;

			circleOverlay = MKCircle.Circle (coords, 200);
			mapView.AddOverlay (circleOverlay);
Comment 1 Sebastien Pouliot 2013-09-27 19:49:40 UTC
If you're using events then an internal delegate is created. That internal delegate (must) implements everything, including the new method.

So OverlayRenderer is effectively called (from ObjC) *because it's defined in the internal delegate* but not routed to managed code (since no event was added).

Often (this happened before) when the newer method alternative is implemented (i.e. it respond) then the old one is never called by iOS. i.e. Apple code looks like:

if (respondToSelector (@new)) {
   new X, Y
} else {
   old X, Y

OTOH that would only happen on iOS7. Earlier iOS would still reach the GetViewForOverlay (because it lacks the previous condition).

You either:

* need to support both cases (for old and new iOS versions);

* use a MKMapViewDelegate (not the events)