The Geography Class example only has a few levels of detail. We can’t zoom in very close and if we could it would take up way too much space on the device. Thus, we need a way to look at tiled image maps sitting on a server.
Let’s add a remote tile source, and take a closer look at the Earth. We’ll use the Stamen Terrain tile set. If you end up wanting to use these tiles in an app that you distribute, check out the requirements. (Full attribution: Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.)
You’ll need to have done the Local Image Layer tutorial. Open your HelloEarth project and get ready.
If you haven’t got one here is a suitable ViewController (for Objective-C or Swift) file to start with. This version handles both a globe and a map and makes a nice starting point.
Remote Tile Source
We’ll set this up to use either the local or remote tiles. Look for the following lines in your source code.
Now replace that with these lines instead. This will let you use either local or remote data.
Don’t forget the call to addLayer below this. We’re just creating a slightly different data source, we still need to add the layer to the globe or map.
There’s only one important change here. Rather than use a MaplyMBTileSource we create a MaplyRemoteTileSource. It does just what it sounds like, loads its tiles from a remote source.
We also set up a cache for the tiles because it’s rude to thrash the server. We set up the MaplyQuadImageTilesLayer as before. It can handle a variety of data sources.
And finally, if you’re running iOS 9 or later, you’ll need to configure the app to be allowed to make HTTP requests. If not, only HTTPS requests are allowed. Just open your Info.plist file, and add the key “App Transport Security Settings”. Inside that, add “Allow Arbitrary Loads” key with value “YES”.
Build and Run
Give it a try. It’s even more fun on a device. You can zoom in to your heart’s content, provided your heart doesn’t desire submeter resolution.
All that with just a few lines of code. WhirlyGlobe-Maply is doing a lot of work behind the scenes. As you move around it pulls in new data, caches it to the local device, displays it, gets rid of the old data and so forth. But setting all this up is easy.
Next up, let’s overlay some data on here. How about some vectors?