Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[WIP] Annotation callout views #1074

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e992448
More descriptive variable name
1ec5 Mar 23, 2015
b027b0b
Annotation callout views
1ec5 Mar 23, 2015
579b25d
Update calloutview submodule in Makefile
1ec5 Mar 24, 2015
6a84f9c
Don’t animate dismissal when other animations are present
1ec5 Mar 24, 2015
fa67a65
rename callout submodule & move to vendor folder
incanus Mar 24, 2015
fd5eca6
properties are already strong by default
incanus Mar 24, 2015
e42321a
move QuartzCore linking
incanus Mar 24, 2015
64e60b2
Merge branch 'master' into 894-callout
incanus Mar 24, 2015
b17beda
codify threading assumptions
incanus Mar 24, 2015
6a6c2a1
stub out delegate callbacks
incanus Mar 24, 2015
36e7cee
implement delegate callbacks
incanus Mar 24, 2015
836e425
clean whitespace
incanus Mar 24, 2015
c71e468
remove unused properties
incanus Mar 24, 2015
65949db
fixes #1080: tighten up notifications & annotation deselection
incanus Mar 24, 2015
f97f42c
remove unnecessary
incanus Mar 24, 2015
b28853f
ensure all selection goes through callout trigger
incanus Mar 24, 2015
6a46c48
deselect selected annotation on removal
incanus Mar 24, 2015
6ac2c4d
determine offset for callouts on a per-annotation symbol basis
incanus Mar 24, 2015
8b675da
remove log line
incanus Mar 24, 2015
3b29337
cut down on over-aggressive deselection
incanus Mar 24, 2015
fc2e7fd
stub out callout control callback
incanus Mar 24, 2015
265aa9f
Update to nfarina/calloutview@da691eceee57cdecce0235d2946552e105d8b7c6
1ec5 Mar 24, 2015
5850422
stub out callout-related delegate methods
incanus Mar 24, 2015
952fe12
Merge branch '894-callout' of github.com:mapbox/mapbox-gl-native into…
incanus Mar 24, 2015
f282d6f
callout-related delegate handling
incanus Mar 24, 2015
af5b007
docs improvements
incanus Mar 25, 2015
3346f8d
don't show callout if not title
incanus Mar 25, 2015
f4f279f
Merge remote-tracking branch 'origin/master' into 894-callout
incanus Mar 25, 2015
1f3d813
show callouts by default
incanus Mar 25, 2015
0dbed13
reduce span of touch regions
incanus Mar 25, 2015
7efb15e
need two gestures since two views
incanus Mar 25, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
[submodule "test/ios/KIF"]
path = test/ios/KIF
url = https://github.com/mapbox/KIF.git

[submodule "platform/ios/vendor/SMCalloutView"]
path = platform/ios/vendor/SMCalloutView
url = https://github.com/nfarina/calloutview.git
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ config/%.gypi: configure
styles/styles:
git submodule update --init styles

SMCalloutView:
git submodule update --init platform/ios/vendor/SMCalloutView

#### Library builds ############################################################

.PRECIOUS: Makefile/mbgl
Makefile/mbgl: config/$(HOST).gypi styles/styles
Makefile/mbgl: config/$(HOST).gypi styles/styles SMCalloutView
deps/run_gyp mbgl.gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f make

mbgl: Makefile/mbgl
Expand All @@ -41,13 +44,13 @@ install: Makefile/mbgl
LINK=`pwd`/gyp/link.py $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) install

.PRECIOUS: Xcode/mbgl
Xcode/mbgl: config/$(HOST).gypi styles/styles
Xcode/mbgl: config/$(HOST).gypi styles/styles SMCalloutView
deps/run_gyp mbgl.gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f xcode

##### Test builds ##############################################################

.PRECIOUS: Makefile/test
Makefile/test: test/test.gyp config/$(HOST).gypi styles/styles
Makefile/test: test/test.gyp config/$(HOST).gypi styles/styles SMCalloutView
deps/run_gyp test/test.gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f make

test: Makefile/test
Expand All @@ -58,7 +61,7 @@ test-%: test


.PRECIOUS: Xcode/test
Xcode/test: test/test.gyp config/osx.gypi styles/styles
Xcode/test: test/test.gyp config/osx.gypi styles/styles SMCalloutView
deps/run_gyp test/test.gyp $(CONFIG_osx) $(LIBS_osx) --generator-output=./build/osx -f xcode

.PHONY: lproj lbuild run-xlinux
Expand Down Expand Up @@ -108,7 +111,7 @@ xproj: xosx-proj
#### iOS application builds ####################################################

.PRECIOUS: Xcode/ios
Xcode/ios: ios/app/mapboxgl-app.gyp config/ios.gypi styles/styles
Xcode/ios: ios/app/mapboxgl-app.gyp config/ios.gypi styles/styles SMCalloutView
deps/run_gyp ios/app/mapboxgl-app.gyp $(CONFIG_ios) $(LIBS_ios) --generator-output=./build/ios -f xcode

.PHONY: ios-proj ios run-ios
Expand Down
3 changes: 3 additions & 0 deletions gyp/platform-ios.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
'../platform/ios/NSDictionary+MGLAdditions.m',
'../include/mbgl/ios/UIColor+MGLAdditions.h',
'../platform/ios/UIColor+MGLAdditions.m',
'../platform/ios/vendor/SMCalloutView/SMCalloutView.h',
'../platform/ios/vendor/SMCalloutView/SMCalloutView.m',
],

'variables': {
Expand All @@ -52,6 +54,7 @@
'-framework GLKit',
'-framework MobileCoreServices',
'-framework OpenGLES',
'-framework QuartzCore',
'-framework SystemConfiguration',
'-framework UIKit',
],
Expand Down
79 changes: 79 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,15 @@

@end

#pragma mark - MGLMapViewDelegate

/** The MGLMapViewDelegate protocol defines a set of optional methods that you can use to receive map-related update messages. Because many map operations require the MGLMapView class to load data asynchronously, the map view calls these methods to notify your application when specific operations complete. The map view also uses these methods to request annotation marker symbology and to manage interactions with those markers. */
@protocol MGLMapViewDelegate <NSObject>

@optional

#pragma mark - Managing the Display of Annotations

/** @name Managing the Display of Annotations */

/** Returns the style's symbol name to use for the marker for the specified point annotation object.
Expand All @@ -264,14 +268,54 @@
* @return The marker symbol to display for the specified annotation or `nil` if you want to display the default symbol. */
- (NSString *)mapView:(MGLMapView *)mapView symbolNameForAnnotation:(id <MGLAnnotation>)annotation;

/** Returns a Boolean value indicating whether the annotation is able to display extra information in a callout bubble.
*
* If the value returned is `YES`, a standard callout bubble is shown when the user taps a selected annotation. The callout uses the title and subtitle text from the associated annotation object. If there is no title text, though, the annotation will not show a callout. The callout also displays any custom callout views returned by the delegate for the left and right callout accessory views.
*
* If the value returned is `NO`, the value of the title and subtitle strings are ignored.
*
* @param mapView The map view that requested the annotation callout ability.
* @param annotation The object representing the annotation.
* @return A Boolean indicating whether the annotation should show a callout. */
- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation;

/** Return the view to display on the left side of the standard callout bubble.
*
* The default value is treated as if `nil`. The left callout view is typically used to display information about the annotation or to link to custom information provided by your application.
*
* If the view you specify is also a descendant of the `UIControl` class, you can use the map view’s delegate to receive notifications when your control is tapped. If it does not descend from `UIControl`, your view is responsible for handling any touch events within its bounds.
*
* @param mapView The map view presenting the annotation callout.
* @param annotation The object representing the annotation with the callout.
* @return The accessory view to display. */
- (UIView *)mapView:(MGLMapView *)mapView leftCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation;

/** Return the view to display on the right side of the standard callout bubble.
*
* The default value is treated is if `nil`. The right callout view is typically used to link to more detailed information about the annotation. A common view to specify for this property is `UIButton` object whose type is set to `UIButtonTypeDetailDisclosure`.
*
* If the view you specify is also a descendant of the `UIControl` class, you can use the map view’s delegate to receive notifications when your control is tapped. If it does not descend from `UIControl`, your view is responsible for handling any touch events within its bounds.
*
* @param mapView The map view presenting the annotation callout.
* @param annotation The object representing the annotation with the callout.
* @return The accessory view to display. */
- (UIView *)mapView:(MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation;

#pragma mark - Responding to Map Position Changes

// Responding to Map Position Changes

// TODO
- (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated;

// TODO
- (void)mapViewRegionIsChanging:(MGLMapView *)mapView;

// TODO
- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated;

#pragma mark - Loading the Map Data

// Loading the Map Data

// TODO
Expand All @@ -289,4 +333,39 @@
// TODO
- (void)mapViewDidFinishRenderingMap:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered;

#pragma mark - Managing Annotations

/** @name Managing Annotations */

/* Tells the delegate that the user tapped one of the annotation's accessory buttons.
*
* Accessory views contain custom content and are positioned on either side of the annotation title text. If a view you specify is a descendant of the `UIControl` class, the map view calls this method as a convenience whenever the user taps your view. You can use this method to respond to taps and perform any actions associated with that control. For example, if your control displayed additional information about the annotation, you could use this method to present a modal panel with that information.
*
* If your custom accessory views are not descendants of the `UIControl` class, the map view does not call this method.
*
* @param mapView The map view containing the specified annotation.
* @param annotation The annotation whose button was tapped.
* @param control The control that was tapped. */
- (void)mapView:(MGLMapView *)mapView annotation:(id <MGLAnnotation>)annotation calloutAccessoryControlTapped:(UIControl *)control;

#pragma mark - Selecting Annotations

/** @name Selecting Annotations */

/* Tells the delegate that one of its annotations was selected.
*
* You can use this method to track changes in the selection state of annotations.
*
* @param mapView The map view containing the annotation.
* @param annotation The annotation that was selected. */
- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id <MGLAnnotation>)annotation;

/* Tells the delegate that one of its annotations was deselected.
*
* You can use this method to track changes in the selection state of annotations.
*
* @param mapView The map view containing the annotation.
* @param annotation The annotation that was deselected. */
- (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id <MGLAnnotation>)annotation;

@end
1 change: 1 addition & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class Map : private util::noncopyable {

// Annotations
void setDefaultPointAnnotationSymbol(const std::string&);
double getTopOffsetPixelsForAnnotationSymbol(const std::string&);
uint32_t addPointAnnotation(const LatLng&, const std::string& symbol);
std::vector<uint32_t> addPointAnnotations(const std::vector<LatLng>&,
const std::vector<std::string>& symbols);
Expand Down
17 changes: 9 additions & 8 deletions include/mbgl/map/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class Map;
enum MapChange : uint8_t {
MapChangeRegionWillChange = 0,
MapChangeRegionWillChangeAnimated = 1,
MapChangeRegionDidChange = 2,
MapChangeRegionDidChangeAnimated = 3,
MapChangeWillStartLoadingMap = 4,
MapChangeDidFinishLoadingMap = 5,
MapChangeDidFailLoadingMap = 6,
MapChangeWillStartRenderingMap = 7,
MapChangeDidFinishRenderingMap = 8,
MapChangeDidFinishRenderingMapFullyRendered = 9
MapChangeRegionIsChanging = 2,
MapChangeRegionDidChange = 3,
MapChangeRegionDidChangeAnimated = 4,
MapChangeWillStartLoadingMap = 5,
MapChangeDidFinishLoadingMap = 6,
MapChangeDidFailLoadingMap = 7,
MapChangeWillStartRenderingMap = 8,
MapChangeDidFinishRenderingMap = 9,
MapChangeDidFinishRenderingMapFullyRendered = 10
};

class View {
Expand Down
11 changes: 10 additions & 1 deletion ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

static NSString *const kStyleVersion = @"v7";

@interface MBXViewController () <UIActionSheetDelegate, CLLocationManagerDelegate>
@interface MBXViewController () <UIActionSheetDelegate, CLLocationManagerDelegate, MGLMapViewDelegate>

@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) CLLocationManager *locationManager;
Expand Down Expand Up @@ -70,6 +70,8 @@ - (void)viewDidLoad

self.mapView.viewControllerForLayoutGuides = self;

self.mapView.delegate = self;

self.view.tintColor = kTintColor;
self.navigationController.navigationBar.tintColor = kTintColor;
self.mapView.tintColor = kTintColor;
Expand Down Expand Up @@ -338,6 +340,13 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray
[self.locationManager stopUpdatingLocation];
}

#pragma mark - MGLMapViewDelegate

- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation
{
return YES;
}

#pragma clang diagnostic pop

@end
Loading