Search code examples
iosios5mkmapviewmapkit

Black and white overlay for an MKMapView


I have an MKMapView and am adding an overlay (MKOverlay) to it.

I would like the overlay to make the map view underneath to appear black & white (i.e. monochrome). Is there any way of doing this?

(I guess I could make the overlay translucent black/gray, but that's not the exact effect I would like.)


System details: developing an iOS 5 app in Xcode 4.2.


Solution

  • The most proper route, which sadly isn't yet available on iOS would be:

    Your MKOverlay is at some point being used to create an MKOverlayView, which will have a CALayer as it descends from UIView. You can attach CIFilters as compositingFilters to CALayers, which dictate how the view is composited with the background. You could attach a filter of type CIColorMonochrome to that.

    Because that option isn't available, you're going to have to leap through some major hurdles to do the work for yourself. You'll probably need to implement your own custom MKOverlayView that in its drawView uses the techniques given in Apple's QA1703 to get the pixel contents of the map view in the relevant area (be careful not to end up in an infinite recursive loop though), transform those into black and white and present them as your view.

    Is that something it's worth investigating further or would you be happier to substitute the effect than to really delve into this stuff?