Simon
Simon

Reputation: 67

Tiled Vector Based Map iOS

I am attempting to create a custom vector based map using tiles, much like iOS 6 Maps. I have seen many great solutions for raster-based maps, but so far nothing based on Vector Based Maps.

I have the entire map in drawing code, but unfortunately it is too big to use in one file. I also have the svg. preferably, i would like a solution that does not involve recreating the entire map in another format, yet also, i would prefer if the solution was easy on the iPhone, ie did not crash/perform slowly on it.

Does anyone have any ideas?

Thanks for your kind assistance,

Upvotes: 3

Views: 851

Answers (1)

Tommy
Tommy

Reputation: 100652

I think your best bet is to output the SVG as a [vector] PDF. That should be something you can achieve automatically using whatever software you used to create the SVG. The advantage of PDF is that it's a vector format that iOS natively understands and can render in a small number of calls.

What you then probably want to do is create a subclass of UIView that can render the PDF. You'll need to drop down to the relevant Core Graphics C stuff but it's not all that difficult to achieve. Pulling a tutorial off the internet at random gives me this one.

If you give that UIView a layerClass of CATiledLayer then size it for the whole of your map and place it inside a scroll view you should get the exact same tiling behaviour as Maps, Safari, etc. You won't have to implement anything special — if you trap your view's drawRect: you should see it being called just for small sections.

Don't worry about any older tutorials on CATiledLayer that start raising threading concerns — per QA1637 you're permitted just to implement drawRect: in the normal UIKit way and have the threading just work since iOS 4. Assuming you intend to support the iPhone 5 screen resolution you can't submit for older than 4.3 anyway and even if you aren't then I really don't recommend you expend the effort.

Upvotes: 2

Related Questions