Friday, January 25, 2013

Image Paging & MapBox Data Sets

Large image dataset paging has been in WhirlyGlobe for several versions now.  With 2.1, it's gotten a lot more efficient.  In this video I discuss some of the improvements and play around with a couple of neat MapBox data sets.


Interfacing With MapBox


The WhirlyGlobe Component has had remote tile support for a while.  Just provide a base URL and it'll start fetching images in a standard tiling scheme.  In honor of the new MapBox data sets, I decided to make this even simpler.

Some data providers will put a TileJSON file at the top level of their data sets.  MapBox does this, of course, and it provides a little extra bit of information and makes the developer's job simpler.

I added support for parsing TileJSON files to the WhirlyGlobe Component.  With a little help from AFNetworking, we can make the code incredibly easy.


// globeViewC is our WhirlyGlobeViewController
// jsonTileSpec is the full URL for the tile spec
// thisCacheDir is a local directory where we'll cache images
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:jsonTileSpec]];
        
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
  success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
  {
       // Add a quad earth paging layer based on the tile spec we just fetched
       [globeViewC addQuadEarthLayerWithRemoteSource:JSON cache:thisCacheDir];
  }
  failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
  {
       NSLog(@"Failed to reach JSON tile spec at: %@",jsonTileSpec);
  }
];
        
[operation start];

There are blocks involved, so the syntax is a bit horrid, but the result is pretty simple.

  • We send out a request for the top level TileJSON file.  
  • When it comes back we hand it over to the addQuadEarthLayerWithRemoteSource: method on our globe view controller.  
  • WhirlyGlobe does the rest.


WhirlyGlobe 2.1


You can find the new functionality and performance improvements in WhirlyGlobe 2.1.  That version is in beta at the moment, but it's quite stable.

I'm adding a few more minor features, mostly based on requests, and that'll be the release version.  Look for a comprehensive feature video soon.


2 comments:

  1. Something went wrong; YouTube says the video is private.

    ReplyDelete