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

Commit

Permalink
Merge pull request #1055 from mapbox/cocoa-annotations
Browse files Browse the repository at this point in the history
Cocoa annotations API
  • Loading branch information
incanus committed Mar 22, 2015
2 parents 1883315 + 8b21104 commit eded1d9
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 21 deletions.
1 change: 1 addition & 0 deletions gyp/platform-ios.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'../platform/darwin/reachability.m',
'../include/mbgl/ios/MGLMapView.h',
'../platform/ios/MGLMapView.mm',
'../include/mbgl/ios/MGLAnnotation.h',
'../include/mbgl/ios/MGLStyleFunctionValue.h',
'../platform/ios/MGLStyleFunctionValue.m',
'../include/mbgl/ios/MGLTypes.h',
Expand Down
28 changes: 28 additions & 0 deletions include/mbgl/ios/MGLAnnotation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

/** The MGLAnnotation protocol is used to provide annotation-related information to a map view. To use this protocol, you adopt it in any custom objects that store or represent annotation data. Each object then serves as the source of information about a single map annotation and provides critical information, such as the annotation’s location on the map. Annotation objects do not provide the visual representation of the annotation but typically coordinate (in conjunction with the map view’s delegate) the creation of an appropriate objects to handle the display.
*
* An object that adopts this protocol must implement the `coordinate` property. The other methods of this protocol are optional. */
@protocol MGLAnnotation <NSObject>

/** @name Position Attributes */

/** The center point (specified as a map coordinate) of the annotation. (required) (read-only) */
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@optional

/** @name Title Attributes */

/** The string containing the annotation’s title.
*
* Although this property is optional, if you support the selection of annotations in your map view, you are expected to provide this property. This string is displayed in the callout for the associated annotation. */
@property (nonatomic, readonly, copy) NSString *title;

/** The string containing the annotation’s subtitle.
*
* This string is displayed in the callout for the associated annotation. */
@property (nonatomic, readonly, copy) NSString *subtitle;

@end
60 changes: 59 additions & 1 deletion include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import <CoreLocation/CoreLocation.h>

@protocol MGLMapViewDelegate;
@protocol MGLAnnotation;

/** An MGLMapView object provides an embeddable map interface, similar to the one provided by Apple's MapKit. You use this class to display map information and to manipulate the map contents from your application. You can center the map on a given coordinate, specify the size of the area you want to display, and style the features of the map to fit your application's use case.
*
Expand Down Expand Up @@ -184,6 +185,55 @@
* @param styleName The map style name to use. */
- (void)useBundledStyleNamed:(NSString *)styleName;

#pragma mark - Annotating the Map

/** @name Annotating the Map */

/** The complete list of annotations associated with the receiver. (read-only)
*
* The objects in this array must adopt the MGLAnnotation protocol. If no annotations are associated with the map view, the value of this property is `nil`. */
@property (nonatomic, readonly) NSArray *annotations;

/** Adds the specified annotation to the map view.
* @param annotation The annotation object to add to the receiver. This object must conform to the MGLAnnotation protocol. The map view retains the specified object. */
- (void)addAnnotation:(id <MGLAnnotation>)annotation;

/** Adds an array of annotation objects to the map view.
* @param annotations An array of annotation objects. Each object in the array must conform to the MGLAnnotation protocol. The map view retains the individual annotation objects. */
- (void)addAnnotations:(NSArray *)annotations;

/** Removes the specified annotation object from the map view.
*
* Removing an annotation object disassociates it from the map view entirely, preventing it from being displayed on the map. Thus, you would typically call this method only when you want to hide or delete a given annotation.
*
* @param annotation The annotation object to remove. This object must conform to the MGLAnnotation protocol. */
- (void)removeAnnotation:(id <MGLAnnotation>)annotation;

/** Removes an array of annotation objects from the map view.
*
* Removing annotation objects disassociates them from the map view entirely, preventing them from being displayed on the map. Thus, you would typically call this method only when you want to hide or delete the specified annotations.
*
* @param annotations The array of annotations to remove. Objects in the array must conform to the MGLAnnotation protocol. */
- (void)removeAnnotations:(NSArray *)annotations;

/** The annotations that are currently selected.
*
* Assigning a new array to this property selects only the first annotation in the array. */
@property (nonatomic, copy) NSArray *selectedAnnotations;

/** Selects the specified annotation and displays a callout view for it.
*
* If the specified annotation is not onscreen, this method has no effect.
*
* @param annotation The annotation object to select.
* @param animated If `YES`, the callout view is animated into position. */
- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated;

/** Deselects the specified annotation and hides its callout view.
* @param annotation The annotation object to deselect.
* @param animated If `YES`, the callout view is animated offscreen. */
- (void)deselectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated;

#pragma mark - Debugging

/** @name Debugging */
Expand All @@ -201,11 +251,19 @@

@end

// TODO
/** 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

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

/** Returns the style's symbol name to use for the marker for the specified point annotation object.
* @param mapView The map view that requested the annotation symbol name.
* @param annotation The object representing the annotation that is about to be displayed.
* @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;

// Responding to Map Position Changes

// TODO
Expand Down
7 changes: 7 additions & 0 deletions include/mbgl/util/geo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ struct LatLngBounds {
if (point.longitude < sw.longitude) sw.longitude = point.longitude;
if (point.longitude > ne.longitude) ne.longitude = point.longitude;
}

inline bool contains(const LatLng& point) {
return (point.latitude >= sw.latitude &&
point.latitude <= ne.latitude &&
point.longitude >= sw.longitude &&
point.longitude <= ne.longitude);
}
};

}
Expand Down
2 changes: 1 addition & 1 deletion ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ - (void)dealloc
}
}

#pragma mark - Location
#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
Expand Down
10 changes: 2 additions & 8 deletions ios/docs/install_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ -z `which appledoc` ]; then
exit 1
fi

VERSION=$( git tag | sort -r | sed -n '1p' )
VERSION=$( git tag | grep ^[0-9] | sort -r | sed -n '1p' )
echo "Creating new docs for $VERSION..."
echo

Expand All @@ -15,10 +15,4 @@ appledoc \
--project-company Mapbox \
--create-docset \
--company-id com.mapbox \
--ignore app \
--ignore dist \
--ignore pkg \
--ignore test \
--ignore .m \
--ignore .mm \
.
../../include/mbgl/ios
2 changes: 1 addition & 1 deletion ios/docs/remove_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ echo
echo "Removing docs from ~/Library/Developer/Shared/Documentation/DocSets..."
echo

rm -rfv ~/Library/Developer/Shared/Documentation/DocSets/com.mapbox.Mapbox-GL-*
rm -rfv ~/Library/Developer/Shared/Documentation/DocSets/com.mapbox.Mapbox-GL-*
Loading

0 comments on commit eded1d9

Please sign in to comment.