Coder Social home page Coder Social logo

mtigas / ios-maplayerdemo Goto Github PK

View Code? Open in Web Editor NEW
197.0 16.0 25.0 423 KB

Demo of using MKOverlayView in iOS 4.0+ to render custom tile server overlays. (Last updated in 2012, you probably want to look elsewhere for modern code examples.)

License: BSD 2-Clause "Simplified" License

Objective-C 100.00%

ios-maplayerdemo's Introduction

iOS Custom Map Layer Example

A barebones demo app that demonstrates the use of some new MapKit functionality in iOS 4.0.:

The MKOverlay protocol and MKOverlayView class and how to use these to render custom tile layers a la Google Maps API. (i.e. Google Maps-compatible tile layers from Mapnik/Tilecache, gheat, etc.) Examples include tilesets from OpenStreetMap and MapBox.

(Caveat: the OpenStreetMap renders opaquely over the default Google layer, it does not replace it.)

Comments and feedback are welcome.

  

What?

I refactored django-gheat as a side project and I’ve been working on iOS development a bit lately and was seeking a slick way to plug the django-gheat demo tileserver into the iPhone. The Google Maps API just doesn’t have enough performance in the browser to make for a decent user experience.

Some conversation threads recommended combining a UIScrollView with CATiledLayer, but this seemed unwieldy to couple with the existing MapKit framework.

Lo and behold, iOS 4.0 added custom overlay functionality to MapKit, though I have not seen any mention or example of it’s use to date.

Notes

The code is generally commented thoroughly. I am not an expert in cartography, so my knowledge of map projections and some of the calculations within the code are to be taken with a grain of salt.

CustomOverlayView compensates for [[UIScreen mainScreen] scale], or the iPhone 4’s pixel doubling. The view applies the screen scale factor, creating a situation as if the screen were twice as large. Because MapKit loads pixel-doubled tiles but maintains the same viewport, CustomOverlayView renders tiles of the next (or scale-appropriate) zoom level to maintain a one-to-one mapping with MapKit’s own tiles.

The [MKOverlayView -canDrawMapRect…] and [MKOverlayView -drawMapRect…] methods rely on asynchronously downloading tiles as requested (by -canDrawMapRect) into cache, and then using that cache in the -drawMapRect method after the success callback notifies MapKit to try the tile again.

ios-maplayerdemo's People

Contributors

mtigas avatar

Stargazers

Jimmy avatar Sam Zhang avatar Blossom avatar ssbomb avatar Jason Zhou 周正昌 avatar Ken Tominaga avatar Angus H. avatar  avatar Stuart Lynn avatar Oleksii Schastlyvyi avatar Kien Lhi avatar Yan Li avatar Rafael Mena avatar clearbrian avatar Ciprian (Chip) Rarau avatar Sebastian-H. Picklum avatar Mehul Akoliya avatar  avatar Lukas Kukacka avatar Egor Ivkin avatar Richard Kirk avatar Timur Kuchkarov avatar Luis Enrique Espinoza Severino avatar Thomas Krajacic avatar  avatar Stanislav Pankevich avatar Bernhard Loibl avatar kimziv avatar James Van Dyne avatar Alexander Simson avatar Derek Trauger avatar Nilesh  avatar Matt Hudson avatar Almer Lucke avatar Lanbo Zhang avatar igal nassima avatar Přemysl Ptáček avatar Hao avatar  avatar Ken Lu avatar  avatar  avatar youtoutou avatar Dan Kang avatar u avatar LYB avatar Dmitriy Shibarshin avatar  avatar  avatar  avatar  avatar hemingwayEGS avatar Arjun Mahanti avatar Sedat Kilinc avatar Tariq Seifuddin avatar Jindřich Doležy avatar Petr Zvoníček avatar AndyJin avatar Manuel Deutsch avatar Hans-Jürgen Krüger avatar Fabien avatar  avatar Jiaxu avatar Christos Tachtatzis avatar  avatar Rob Wisner avatar Mike Krus avatar Brad Leege avatar Jooyoung-Lee avatar Davis avatar Vinay Chavan avatar Brian Davidson avatar Carlos Vitor Barros avatar Ralph Shao avatar Marcio Horoiwa avatar Vitaly Peretiatko avatar Jack Gao avatar Eric Wolfe avatar Juan Carlos Alonso avatar ppm avatar Linh M. Tran avatar  avatar Mohammad Hanif avatar Jon Bourke avatar Francesco Bartoli avatar Adao Junior avatar Matthew Ryan avatar  avatar Fabio Ribeiro avatar Sanjit Saluja avatar  avatar Chris Dunphy avatar Jean-Baptiste Gomez avatar  avatar sigman avatar  avatar  avatar  avatar Lionel avatar Sebas Barrios avatar

Watchers

 avatar  avatar Marcus Rohrmoser avatar Jim Wang avatar  avatar  avatar magixmin avatar Christian Gilbert avatar mayulu avatar John avatar Kevin Muldoon avatar James Cloos avatar duythanhphan avatar Johnny Xu avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.