Skip to content

Commit 13283ea

Browse files
authored
Merge pull request #40 from dhritzkiv/patch-1
Update README.md
2 parents a47f263 + 3991720 commit 13283ea

1 file changed

Lines changed: 32 additions & 31 deletions

File tree

README.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,20 @@ What is coming:
2727

2828

2929
## Installation
30-
MapCache is available through [CocoaPods](https://cocoapods.org). To install
31-
it, simply add the following line to your `Podfile`:
30+
MapCache is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your `Podfile`:
3231

3332
```ruby
3433
pod 'MapCache'
3534
```
3635

3736
## How to use MapCache?
38-
In the view controller where you have the `MKMapView` import `MapCache`
37+
In the view controller where you have a `MKMapView`, import `MapCache`:
3938

4039
```swift
4140
import MapCache
4241
```
4342

44-
Then within the ViewController add
43+
Then, within the ViewController add:
4544

4645
```swift
4746
// ViewController.swift
@@ -51,11 +50,11 @@ class ViewController: UIViewController {
5150
override func viewDidLoad() {
5251
super.viewDidLoad()
5352

54-
...
53+
//...
5554

5655
map.delegate = self
5756

58-
...
57+
//...
5958

6059
// First setup the config of our cache.
6160
// The only thing we must provide is the url template of the tile server.
@@ -70,11 +69,11 @@ class ViewController: UIViewController {
7069
// cache
7170
map.useCache(mapCache)
7271

73-
...
72+
//...
7473
}
7574
```
7675

77-
Finally, tell the map delegate to use `mapCacheRenderer`
76+
Finally, tell the map delegate to use `mapCacheRenderer`:
7877

7978
```swift
8079
//ViewController.swift
@@ -88,14 +87,14 @@ extension ViewController : MKMapViewDelegate {
8887
}
8988

9089
```
91-
After setting up map cache browsed areas of the map will be kept on disk. If user browses again that area it will use the local version.
90+
After setting up the map cache, browsed areas of the map will be kept on disk. If the user browses again, that area it will use the local version.
9291

93-
Note that in current version cache has not expiration date so if you need to get an updated version of the tiles you must call `clear()` which will wipe out the whole cache.
92+
Note that in the current version, the cache does not support expiration dates, so if you need to get an updated version of the tiles you must call `clear()` which will wipe out the whole cache.
9493

9594
```swift
9695
mapCache.clear() {
97-
// do something after clear
98-
print("cache cleared!")
96+
// do something after clear
97+
print("cache cleared!")
9998
}
10099
```
101100

@@ -107,10 +106,10 @@ mapCache.calculateDiskSize()
107106

108107
You can take a look at the [**Example/ folder**](https://github.com/merlos/MapCache/tree/master/Example/MapCache) to see a complete implementation.
109108

110-
A [Reference documentation](http://www.merlos.org/MapCache) is also available.
109+
[Reference documentation](http://www.merlos.org/MapCache) is also available.
111110

112111
## MapCache configuration
113-
Config map cache is pretty straight forward, typically you will need to set only `urlTemplate` and probably the `subdomains`.
112+
Configurating the map cache is pretty straight forward. Typically, you will only need to set `urlTemplate` and, optionally, the `subdomains`.
114113

115114
These are the options:
116115

@@ -157,29 +156,29 @@ config.capacity = 200 * 1024 * 1024 // 200 Megabytes
157156

158157
```
159158

160-
If you need to use MapCache in different controllers, to avoid issues just be sure to use the same values in the config.
159+
If you need to use MapCache in different controllers, be sure to use the same values in the config to avoid issues.
161160

162161
## How does `MapCache` work behind the scenes
163162

164-
If you need to build on something top of MapCache read this. If not, you can ignore
163+
If you need to build something on top of MapCache, read the following.
165164

166-
MapCache is a hack of [MapKit](https://developer.apple.com/documentation/mapkit), the map framework of Apple.
165+
MapCache is a hack of [MapKit](https://developer.apple.com/documentation/mapkit), the map framework from Apple, used on their iOS, macOS, tvOS, and watchOS platforms.
167166

168167
### Understanding MapCache bootstrap
169168

170-
As explained in _How to use MapCache?_ section, in order to bootstrap MapCache we have to call this method
169+
As explained in _How to use MapCache?_ section, in order to bootstrap MapCache, we have to call this method:
171170

172171
```swift
173172
map.useCache(mapCache)
174173
```
175174

176-
Where map is an instance of `MKMapView`, the main class used to display a map in iOS. What MapCache does through the extension (`MKMapView+MapCache`) is to add a new method `useCache` that tells `MKMapView` to display in the map a new tile layer on top of the default layers. Because of this while the tiles are loaded you may see the names of the default Apple Maps.
175+
Where map is an instance of `MKMapView`, the main class used to display a map with MapKit. What MapCache does through the `MKMapView+MapCache` extension is to add a new method `useCache` that tells `MKMapView` to display a new tile layer on top of the default layers. Because of this, while the tiles are loaded you may see the tiles of the default Apple Maps.
177176

178177
This extension also adds a variable in the `MKMapView` to keep the cache config.
179178

180-
A layer in the map is called _overlay_ in the MapKit terminology. MapCache uses [tile based overlay](https://en.wikipedia.org/wiki/Tiled_web_map). implemented in the class `CachedTileOverlay` which is a subclass of [MKTileOverlay](https://developer.apple.com/documentation/mapkit/mktileoverlay).
179+
A layer in the map is called _overlay_ in MapKit terminology. MapCache uses [tile based overlay](https://en.wikipedia.org/wiki/Tiled_web_map) implemented in the class `CachedTileOverlay`, which is a subclass of [MKTileOverlay](https://developer.apple.com/documentation/mapkit/mktileoverlay).
181180

182-
Overlays, have associated _renderers_ that are the actual classes that draw the content of an overlay in the screen. For example, there are rendererers for points, lines, polygons, and tiles. When `MapView` needs to display an overlay it calls the delegate with the overlay it is going to render and you need to provide the renderer to use. In order to do that, We added a method `mapCacheRenderer` that just returns the default [MKTileOverlayRenderer](https://developer.apple.com/documentation/mapkit/mktileoverlay) when the class of the overlay passed as argument is of the type `CachedTileOverlay`. That is why we need to add this code on the application in the delegate of the map view (`MKMapViewDelegate`) :
181+
Overlays have associated _renderers_ that are the actual classes that draw the content of an overlay on the screen. For example, there are rendererers for points, lines, polygons, and tiles. When `MapView` needs to display an overlay, it calls the delegate with the overlay it is going to render and you need to provide the renderer to use. In order to do that, We added a `mapCacheRenderer` method that returns the default [MKTileOverlayRenderer](https://developer.apple.com/documentation/mapkit/mktileoverlay) when the class of the overlay passed as the argument is of the type `CachedTileOverlay`. That is why we need to add this code on the application in the delegate of the map view (`MKMapViewDelegate`) :
183182

184183
```swift
185184
extension ViewController : MKMapViewDelegate {
@@ -191,35 +190,37 @@ extension ViewController : MKMapViewDelegate {
191190

192191
### `CachedTileOverlay` and `MapCacheProtocol`
193192

194-
As mentioned earlier, `CachedTileOverlay` is tile based layer that is implemented as a subclass of [MKTileOverlay](https://developer.apple.com/documentation/mapkit/mktileoverlay). Basically, the only thing that it does is to override two methods of the parent class:
193+
As mentioned earlier, `CachedTileOverlay` is a tile based layer that is implemented as a subclass of [MKTileOverlay](https://developer.apple.com/documentation/mapkit/mktileoverlay). Basically, the only thing that it does is to override two methods of the parent class:
195194

196195
1. `func url(forTilePath path: MKTileOverlayPath) -> URL`. The goal of this method is to return the URL of the tile. We need to overwrite it to be able to use the tile server of our preference.
197196

198197
2. `func loadTile(at path: MKTileOverlayPath, result: @escaping (Data?, Error?) -> Void)`. This method is the one that returns the actual Tile.
199198

200-
If you take a look to the [implementation of `CachedTileOverlay`](https://github.com/merlos/MapCache/blob/master/MapCache/Classes/CachedTileOverlay.swift) you will notice that it only forwards the request a method with the same signature of a variable called `mapCache` which is an instance of a class that implements `MapCacheProtocol`
199+
If you take a look at the [implementation of `CachedTileOverlay`](https://github.com/merlos/MapCache/blob/master/MapCache/Classes/CachedTileOverlay.swift), you will notice that it only forwards the request to the method with the same signature of a variable called `mapCache` which is an instance of a class that implements `MapCacheProtocol`
201200

202-
```
203-
override public func url(forTilePath path: MKTileOverlayPath) -> URL {`
204-
return mapCache.url(forTilePath: path)
205-
}
201+
```swift
202+
override public func url(forTilePath path: MKTileOverlayPath) -> URL {
203+
return mapCache.url(forTilePath: path)
204+
}
206205
```
207206

208-
The [`MapCacheProtocol definition`](https://github.com/merlos/MapCache/blob/master/MapCache/Classes/MapCacheProtocol.swift) is pretty simple, it just requires to have a config variable instance of a `MapCacheConfig` and an implementation of the two methods that are called from `CachedTileOverlay`
207+
The [`MapCacheProtocol definition`](https://github.com/merlos/MapCache/blob/master/MapCache/Classes/MapCacheProtocol.swift) is pretty simple, as it just requires to have a config variable instance of a `MapCacheConfig` and an implementation of the two methods that are called from `CachedTileOverlay`:
209208

210-
```
209+
```swift
211210
public protocol MapCacheProtocol {
212211

213212
var config: MapCacheConfig { get set }
214213

215214
func url(forTilePath path: MKTileOverlayPath) -> URL
216215

217216
func loadTile(at path: MKTileOverlayPath, result: @escaping (Data?, Error?) -> Void)
217+
218+
}
218219
```
219220

220-
If you need to create a custom implementation of the cache, you just need to create a class that implements this protocol and initialize the cache using `map.useCache(myCustomCacheImplementationInstance)`. The implementation provided by the library is on the class named as `MapCache`.
221+
If you need to create a custom implementation of the cache, you need to create a class that implements this protocol and initialize the cache using `map.useCache(myCustomCacheImplementationInstance)`. The implementation provided by the library is on the `MapCache` class.
221222

222-
Something that may be useful too is the `DiskCache` class.
223+
Something that may also be useful is the `DiskCache` class.
223224

224225
If you need further information you can take a look at
225226

0 commit comments

Comments
 (0)