Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous tiles support #11

Open
jessedc opened this issue Sep 14, 2012 · 2 comments
Open

Asynchronous tiles support #11

jessedc opened this issue Sep 14, 2012 · 2 comments

Comments

@jessedc
Copy link
Owner

jessedc commented Sep 14, 2012

Here's some notes on how to get it working...

https://github.com/route-me/route-me
http://wiki.openstreetmap.org/wiki/OSM_in_MapKit
https://github.com/mladjan/GoogleMapsOverlayiOS

@ghost ghost assigned jessedc Sep 14, 2012
@jessedc jessedc changed the title Add Asynchronous tiles support Asynchronous tiles support Oct 14, 2017
@jessedc jessedc removed their assignment Oct 14, 2017
@codesourse
Copy link

Using NSCondition may solve it
you can download image from internet.

  • (void)download {
    [self.condition lock];
    //TODO: download code
    if (donloadFinish) { // after download send signal
    [self.condition signal];
    [self.condition unlock];
    }
    }
  • (void)doStuffWithDownloadPicture {
    [self.condition lock];
    while (!donloadFinish) {
    [self.condition wait];
    }
    //TODO: get image
    [self.condition unlock];
    }

@Joohansson
Copy link
Contributor

Alamofire seems to be a nice option. It has built in support for URLSession, cache system, placeholder image, purging, image filters, HTTP Basic Auth etc.
https://github.com/Alamofire/AlamofireImage

I started to experiment with this and created a simple asynchronous function to fetch images (not yet using alamofire). Could someone please point me in the right direction why my fetched images does not update in the tile view? It's just black. I guess the tiles needs to refresh somehow after they have been downloaded?

func tiledScrollView(_ scrollView: JCTiledScrollView, imageForRow row: Int, column: Int, scale: Int) -> UIImage? {
        // Ideally we have @3/6/12/24 tiles, but if not we need to change the original image size. See skippingGirlImageSize
        var tileScale = scale
        if (scale % 3 == 0) {
            tileScale = (scale * 10) / 15
        }
    
        //return UIImage(named: "tiles/SkippingGirl_\(tileScale)x_\(row)_\(column).png")
        var image: UIImage? = nil
        if let url = URL(string: "https://tile.openstreetmap.org/\(tileScale+1)/\(row)/\(column).png") {
            getDataFromUrl(url: url) { data, response, error in
                guard let data = data, error == nil else { return }
                DispatchQueue.main.async() {
                    guard let fetched = UIImage(data: data) else {
                        print ("Failed to fetch image: \(url)")
                        return
                    }
                    image = fetched
                }
            }
        }
        return image
    }
    
    func getDataFromUrl(url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
        URLSession.shared.dataTask(with: url) { data, response, error in
            completion(data, response, error)
            }.resume()
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants