diff options
Diffstat (limited to 'platform/ios/src')
-rw-r--r-- | platform/ios/src/MGLMapView+Impl.h | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView+Impl.mm | 5 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 8 | ||||
-rw-r--r-- | platform/ios/src/MGLMapViewDelegate.h | 14 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView_Private.h | 1 |
5 files changed, 29 insertions, 0 deletions
diff --git a/platform/ios/src/MGLMapView+Impl.h b/platform/ios/src/MGLMapView+Impl.h index 3a7488b443..0a62b7da82 100644 --- a/platform/ios/src/MGLMapView+Impl.h +++ b/platform/ios/src/MGLMapView+Impl.h @@ -69,6 +69,7 @@ public: void onSourceChanged(mbgl::style::Source& source) override; void onDidBecomeIdle() override; void onStyleImageMissing(const std::string& imageIdentifier) override; + bool onCanRemoveUnusedStyleImage(const std::string& imageIdentifier) override; protected: /// Cocoa map view that this adapter bridges to. diff --git a/platform/ios/src/MGLMapView+Impl.mm b/platform/ios/src/MGLMapView+Impl.mm index 73e692defe..1bccfa662f 100644 --- a/platform/ios/src/MGLMapView+Impl.mm +++ b/platform/ios/src/MGLMapView+Impl.mm @@ -100,3 +100,8 @@ void MGLMapViewImpl::onStyleImageMissing(const std::string& imageIdentifier) { NSString *imageName = [NSString stringWithUTF8String:imageIdentifier.c_str()]; [mapView didFailToLoadImage:imageName]; } + +bool MGLMapViewImpl::onCanRemoveUnusedStyleImage(const std::string &imageIdentifier) { + NSString *imageName = [NSString stringWithUTF8String:imageIdentifier.c_str()]; + return [mapView shouldRemoveStyleImage:imageName]; +} diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index ea4a482ccc..c0b7380607 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -6234,6 +6234,14 @@ public: } } +- (BOOL)shouldRemoveStyleImage:(NSString *)imageName { + if ([self.delegate respondsToSelector:@selector(mapView:shouldRemoveStyleImage:)]) { + return [self.delegate mapView:self shouldRemoveStyleImage:imageName]; + } + + return YES; +} + - (void)updateUserLocationAnnotationView { [self updateUserLocationAnnotationViewAnimatedWithDuration:0]; diff --git a/platform/ios/src/MGLMapViewDelegate.h b/platform/ios/src/MGLMapViewDelegate.h index f5249d1797..3ddb7b007f 100644 --- a/platform/ios/src/MGLMapViewDelegate.h +++ b/platform/ios/src/MGLMapViewDelegate.h @@ -277,6 +277,20 @@ NS_ASSUME_NONNULL_BEGIN - (nullable UIImage *)mapView:(MGLMapView *)mapView didFailToLoadImage:(NSString *)imageName; +/** + Asks the delegate whether the map view should evict cached images. + + This method is called in two scenarios: when the cumulative size of unused images + exceeds the cache size or when the last tile that includes the image is removed from + memory. + + @param mapView The map view that is evicting the image. + @param imageName The image name that is going to be removed. + @return A Boolean value indicating whether the map view should evict + the cached image. + */ +- (BOOL)mapView:(MGLMapView *)mapView shouldRemoveStyleImage:(NSString *)imageName; + #pragma mark Tracking User Location /** diff --git a/platform/ios/src/MGLMapView_Private.h b/platform/ios/src/MGLMapView_Private.h index 08c1ff410d..5aa4902a91 100644 --- a/platform/ios/src/MGLMapView_Private.h +++ b/platform/ios/src/MGLMapView_Private.h @@ -41,6 +41,7 @@ FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const _Nonnull MGLUnderlyingMapUna - (void)mapViewDidFinishLoadingStyle; - (void)sourceDidChange:(nonnull MGLSource *)source; - (void)didFailToLoadImage:(nonnull NSString *)imageName; +- (BOOL)shouldRemoveStyleImage:(nonnull NSString *)imageName; /** Triggers another render pass even when it is not necessary. */ - (void)setNeedsRerender; |