You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
92
91
93
-
Note that in current versioncache 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 inthe 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.
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.
161
160
162
161
## How does `MapCache` work behind the scenes
163
162
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.
165
164
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.
167
166
168
167
### Understanding MapCache bootstrap
169
168
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:
171
170
172
171
```swift
173
172
map.useCache(mapCache)
174
173
```
175
174
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 namesof 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`extensionis 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 tilesof the default Apple Maps.
177
176
178
177
This extension also adds a variable in the `MKMapView` to keep the cache config.
179
178
180
-
A layer in the map is called _overlay_ inthe 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).
181
180
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`) :
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` isa 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:
195
194
196
195
1. `funcurl(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.
197
196
198
197
2. `funcloadTile(at path: MKTileOverlayPath, result: @escaping (Data?, Error?) ->Void)`. This method is the one that returns the actual Tile.
199
198
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`
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`:
If you need to create a custom implementation of the cache, you just need to create a classthat 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.
221
222
222
-
Something that may be useful too is the `DiskCache` class.
223
+
Something that may also be useful is the `DiskCache` class.
223
224
224
225
If you need further information you can take a look at
0 commit comments