summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-05-31 17:56:10 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-07-01 15:47:28 -0700
commitc71e67b98e7e6ec22740f79e9e691f3839178a48 (patch)
treee6667b113e1b0aa6ae315e9b5f3384727ab19ed4
parentca4e3650c061b2722dc40abed7eadbf984c9b28d (diff)
downloadqtlocation-mapboxgl-c71e67b98e7e6ec22740f79e9e691f3839178a48.tar.gz
[ios] Add shoulRremoveStyleImage to MGLMapViewDelegate.
-rw-r--r--platform/ios/src/MGLMapView+Impl.h1
-rw-r--r--platform/ios/src/MGLMapView+Impl.mm5
-rw-r--r--platform/ios/src/MGLMapView.mm8
-rw-r--r--platform/ios/src/MGLMapViewDelegate.h11
-rw-r--r--platform/ios/src/MGLMapView_Private.h1
-rw-r--r--platform/ios/test/MGLMapViewDelegateIntegrationTests.swift2
-rw-r--r--platform/macos/src/MGLMapView+Impl.h1
-rw-r--r--platform/macos/src/MGLMapView+Impl.mm5
-rw-r--r--platform/macos/src/MGLMapView.mm8
-rw-r--r--platform/macos/src/MGLMapViewDelegate.h11
-rw-r--r--platform/macos/src/MGLMapView_Private.h1
-rw-r--r--platform/macos/test/MGLMapViewDelegateIntegrationTests.swift1
12 files changed, 55 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..f41476a34b 100644
--- a/platform/ios/src/MGLMapViewDelegate.h
+++ b/platform/ios/src/MGLMapViewDelegate.h
@@ -277,6 +277,17 @@ 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
+ goes over the cache size or when the image's requesting tile is destroyed.
+
+ @param mapView The map view that is evicting the image.
+ @param imageName The image name that is going to be removed.
+ */
+- (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;
diff --git a/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift b/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
index 1330281faa..172538c65b 100644
--- a/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
+++ b/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
@@ -98,4 +98,6 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate {
func mapViewUserLocationAnchorPoint(_ mapView: MGLMapView) -> CGPoint { return CGPoint(x: 100, y: 100) }
func mapView(_ mapView: MGLMapView, didFailToLoadImage imageName: String) -> UIImage? { return nil }
+
+ func mapView(_ mapView: MGLMapView, shouldRemoveStyleImage imageName: String) -> Bool { return false }
}
diff --git a/platform/macos/src/MGLMapView+Impl.h b/platform/macos/src/MGLMapView+Impl.h
index 19583c17e5..2d523716d4 100644
--- a/platform/macos/src/MGLMapView+Impl.h
+++ b/platform/macos/src/MGLMapView+Impl.h
@@ -36,6 +36,7 @@ public:
void onDidFinishLoadingStyle() override;
void onSourceChanged(mbgl::style::Source& source) override;
void onDidBecomeIdle() override;
+ bool onCanRemoveUnusedStyleImage(const std::string& imageIdentifier) override;
protected:
/// Cocoa map view that this adapter bridges to.
diff --git a/platform/macos/src/MGLMapView+Impl.mm b/platform/macos/src/MGLMapView+Impl.mm
index 7be5545671..2354f67a6d 100644
--- a/platform/macos/src/MGLMapView+Impl.mm
+++ b/platform/macos/src/MGLMapView+Impl.mm
@@ -94,3 +94,8 @@ void MGLMapViewImpl::onSourceChanged(mbgl::style::Source& source) {
MGLSource * nativeSource = [mapView.style sourceWithIdentifier:identifier];
[mapView sourceDidChange:nativeSource];
}
+
+bool MGLMapViewImpl::onCanRemoveUnusedStyleImage(const std::string &imageIdentifier) {
+ NSString *imageName = [NSString stringWithUTF8String:imageIdentifier.c_str()];
+ return [mapView shouldRemoveStyleImage:imageName];
+}
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 75bdaac080..3c9647571e 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -978,6 +978,14 @@ public:
self.needsDisplay = YES;
}
+- (BOOL)shouldRemoveStyleImage:(NSString *)imageName {
+ if ([self.delegate respondsToSelector:@selector(mapView:shouldRemoveStyleImage:)]) {
+ return [self.delegate mapView:self shouldRemoveStyleImage:imageName];
+ }
+
+ return YES;
+}
+
#pragma mark Printing
- (void)print:(__unused id)sender {
diff --git a/platform/macos/src/MGLMapViewDelegate.h b/platform/macos/src/MGLMapViewDelegate.h
index 1de4b47eb7..6fb54e3a53 100644
--- a/platform/macos/src/MGLMapViewDelegate.h
+++ b/platform/macos/src/MGLMapViewDelegate.h
@@ -333,6 +333,17 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable NSViewController *)mapView:(MGLMapView *)mapView calloutViewControllerForAnnotation:(id <MGLAnnotation>)annotation;
+/**
+ 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
+ goes over the cache size or when the image's requesting tile is destroyed.
+
+ @param mapView The map view that is evicting the image.
+ @param imageName The image name that is going to be removed.
+ */
+- (BOOL)mapView:(MGLMapView *)mapView shouldRemoveStyleImage:(NSString *)imageName;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/macos/src/MGLMapView_Private.h b/platform/macos/src/MGLMapView_Private.h
index afd7cf2422..3d9b36c30a 100644
--- a/platform/macos/src/MGLMapView_Private.h
+++ b/platform/macos/src/MGLMapView_Private.h
@@ -45,6 +45,7 @@ namespace mbgl {
- (void)mapViewDidBecomeIdle;
- (void)mapViewDidFinishLoadingStyle;
- (void)sourceDidChange:(nonnull MGLSource *)source;
+- (BOOL)shouldRemoveStyleImage:(nonnull NSString *)imageName;
/// Asynchronously render a frame of the map.
- (void)setNeedsRerender;
diff --git a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift
index 6c37017be6..90a777e379 100644
--- a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift
+++ b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift
@@ -59,4 +59,5 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, calloutViewControllerFor annotation: MGLAnnotation) -> NSViewController? { return nil }
+ func mapView(_ mapView: MGLMapView, shouldRemoveStyleImage imageName: String) -> Bool { return false }
}