summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Kiley <jmkiley@users.noreply.github.com>2018-08-20 16:30:03 -0700
committerFabian Guerra Soto <fabian.guerra@mapbox.com>2018-08-20 16:30:03 -0700
commit7fc872b797679ae033a32246206efb06c98a0fd5 (patch)
tree4c0e1f32fdc32ec2d1f94fd1f429765c07389f63
parent50059659d100759978c8bebb04ac7beb9e6d618f (diff)
downloadqtlocation-mapboxgl-7fc872b797679ae033a32246206efb06c98a0fd5.tar.gz
Add enabled property to MGLShape (#12352)
* [ios, macos] Add -[MGLMapViewDelegate mapView:canSelectAnnotation:] method. * [ios, macos] Update changelogs. * [ios, macos] Add mapView:canSelect: integration tests. * [ios, macos] Change semantics to shape annotations. * [ios, macos] Update changelogs. * [ios, macos] Update shapeAnnotationIsEnabled documentation, improve code readability.
-rw-r--r--platform/ios/CHANGELOG.md1
-rw-r--r--platform/ios/src/MGLMapView.mm6
-rw-r--r--platform/ios/src/MGLMapViewDelegate.h12
-rw-r--r--platform/ios/test/MGLMapViewDelegateIntegrationTests.swift2
-rw-r--r--platform/macos/CHANGELOG.md1
-rw-r--r--platform/macos/src/MGLMapView.mm6
-rw-r--r--platform/macos/src/MGLMapViewDelegate.h12
-rw-r--r--platform/macos/test/MGLMapViewDelegateIntegrationTests.swift2
8 files changed, 40 insertions, 2 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index d4254554d1..2d52084be7 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -10,6 +10,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed inconsistencies in exception naming. ([#12583](https://github.com/mapbox/mapbox-gl-native/issues/12583))
* Added `MGLShapeOfflineRegion` for defining arbitrarily shaped offline regions [#11447](https://github.com/mapbox/mapbox-gl-native/pull/11447)
* Added a one-time warning about possible attribute loss when initializing an `MGLShapeSource` with an `MGLShapeCollection` [#12625](https://github.com/mapbox/mapbox-gl-native/pull/12625)
+* Added an `-[MGLMapViewDelegate mapView:shapeAnnotationIsEnabled:]` method to specify whether an annotation is selectable. ([#12352](https://github.com/mapbox/mapbox-gl-native/pull/12352))
## 4.3.0 - August 15, 2018
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 2a231838a4..8ca41b328c 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -4183,7 +4183,11 @@ public:
{
if ([annotation isKindOfClass:[MGLMultiPoint class]])
{
- return false;
+ if ([self.delegate respondsToSelector:@selector(mapView:shapeAnnotationIsEnabled:)]) {
+ return !!(![self.delegate mapView:self shapeAnnotationIsEnabled:(MGLMultiPoint *)annotation]);
+ } else {
+ return false;
+ }
}
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
diff --git a/platform/ios/src/MGLMapViewDelegate.h b/platform/ios/src/MGLMapViewDelegate.h
index 201e3db84b..4bd1a95c9b 100644
--- a/platform/ios/src/MGLMapViewDelegate.h
+++ b/platform/ios/src/MGLMapViewDelegate.h
@@ -433,6 +433,18 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark Selecting Annotations
/**
+ Returns a Boolean value indicating whether the shape annotation can be selected.
+
+ If the return value is `YES`, the user can select the annotation by tapping
+ on it. If the delegate does not implement this method, the default value is `YES`.
+
+ @param mapView The map view that has selected the annotation.
+ @param annotation The object representing the shape annotation.
+ @return A Boolean value indicating whether the annotation can be selected.
+ */
+- (BOOL)mapView:(MGLMapView *)mapView shapeAnnotationIsEnabled:(MGLShape *)annotation;
+
+/**
Tells the delegate that one of its annotations was selected.
You can use this method to track changes in the selection state of annotations.
diff --git a/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift b/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
index 4d11b000b9..48673b1d14 100644
--- a/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
+++ b/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
@@ -58,6 +58,8 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) {}
func mapViewDidFinishRenderingFrame(_ mapView: MGLMapView, fullyRendered: Bool) {}
+
+ func mapView(_ mapView: MGLMapView, shapeAnnotationIsEnabled annotation: MGLShape) -> Bool { return false }
func mapView(_ mapView: MGLMapView, didAdd annotationViews: [MGLAnnotationView]) {}
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index 1e6a54d8e9..c0c751d370 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -6,6 +6,7 @@
* The `-[MGLMapView annotationAtPoint:]` method can now return annotations near tile boundaries at high zoom levels. ([#12570](https://github.com/mapbox/mapbox-gl-native/pull/12570))
* Fixed inconsistencies in exception naming. ([#12583](https://github.com/mapbox/mapbox-gl-native/issues/12583))
* Added `MGLShapeOfflineRegion` for defining arbitrarily shaped offline regions [#11447](https://github.com/mapbox/mapbox-gl-native/pull/11447)
+* Added an `-[MGLMapViewDelegate mapView:shapeAnnotationIsEnabled:]` method to specify whether an annotation is selectable. ([#12352](https://github.com/mapbox/mapbox-gl-native/pull/12352))
# 0.10.0 - August 15, 2018
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 154b716377..3c1fe18499 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -2108,7 +2108,11 @@ public:
if ([annotation isKindOfClass:[MGLMultiPoint class]])
{
- return false;
+ if ([self.delegate respondsToSelector:@selector(mapView:shapeAnnotationIsEnabled:)]) {
+ return !!(![self.delegate mapView:self shapeAnnotationIsEnabled:(MGLMultiPoint *)annotation]);
+ } else {
+ return false;
+ }
}
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
diff --git a/platform/macos/src/MGLMapViewDelegate.h b/platform/macos/src/MGLMapViewDelegate.h
index dae5b40286..2a8b28c1b4 100644
--- a/platform/macos/src/MGLMapViewDelegate.h
+++ b/platform/macos/src/MGLMapViewDelegate.h
@@ -244,6 +244,18 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark Selecting Annotations
/**
+ Returns a Boolean value indicating whether the shape annotation can be selected.
+
+ If the return value is `YES`, the user can select the annotation by clicking
+ on it. If the delegate does not implement this method, the default value is `YES`.
+
+ @param mapView The map view that has selected the annotation.
+ @param annotation The object representing the shape annotation.
+ @return A Boolean value indicating whether the annotation can be selected.
+ */
+- (BOOL)mapView:(MGLMapView *)mapView shapeAnnotationIsEnabled:(MGLShape *)annotation;
+
+/**
Tells the delegate that one of its annotations has been selected.
You can use this method to track changes to the selection state of annotations.
diff --git a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift
index 3f82e7c61a..00635d97eb 100644
--- a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift
+++ b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift
@@ -26,6 +26,8 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate {
func mapViewDidFinishRenderingMap(_ mapView: MGLMapView, fullyRendered: Bool) {}
func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {}
+
+ func mapView(_ mapView: MGLMapView, shapeAnnotationIsEnabled annotation: MGLShape) -> Bool { return false }
func mapView(_ mapView: MGLMapView, didDeselect annotation: MGLAnnotation) {}