summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBrad Leege <bleege@gmail.com>2015-03-23 10:52:27 -0500
committerBrad Leege <bleege@gmail.com>2015-03-23 10:52:27 -0500
commit044d1fc3c258ca435880d1adbcdbc34fc67c2d24 (patch)
treeb9ff72fa70779857959d864b8ac8e390e4431c9f /include
parent33f4dfffd2d9ef20d803e495c47b1248b51bd12c (diff)
parent9d30d4042c3311d02568adbb38dd13fb82faf75d (diff)
downloadqtlocation-mapboxgl-044d1fc3c258ca435880d1adbcdbc34fc67c2d24.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into 1033-metrics
Conflicts: gyp/platform-ios.gypi platform/ios/MGLMapView.mm styles
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/ios/MGLAnnotation.h28
-rw-r--r--include/mbgl/ios/MGLMapView.h60
-rw-r--r--include/mbgl/ios/MapboxGL.h7
-rw-r--r--include/mbgl/map/map.hpp48
-rw-r--r--include/mbgl/util/geo.hpp7
5 files changed, 131 insertions, 19 deletions
diff --git a/include/mbgl/ios/MGLAnnotation.h b/include/mbgl/ios/MGLAnnotation.h
new file mode 100644
index 0000000000..e4907d9b94
--- /dev/null
+++ b/include/mbgl/ios/MGLAnnotation.h
@@ -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
diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h
index 481e878edc..3a6e622e12 100644
--- a/include/mbgl/ios/MGLMapView.h
+++ b/include/mbgl/ios/MGLMapView.h
@@ -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.
*
@@ -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 */
@@ -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
diff --git a/include/mbgl/ios/MapboxGL.h b/include/mbgl/ios/MapboxGL.h
new file mode 100644
index 0000000000..237d493f31
--- /dev/null
+++ b/include/mbgl/ios/MapboxGL.h
@@ -0,0 +1,7 @@
+#import "MGLAnnotation.h"
+#import "MGLMapView.h"
+#import "MGLStyleFunctionValue.h"
+#import "MGLTypes.h"
+#import "NSArray+MGLAdditions.h"
+#import "NSDictionary+MGLAdditions.h"
+#import "UIColor+MGLAdditions.h"
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 86c89f769d..e5eabdac4d 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -37,7 +37,9 @@ class GlyphAtlas;
class SpriteAtlas;
class LineAtlas;
class Environment;
+class EnvironmentScope;
class AnnotationManager;
+class MapData;
class Map : private util::noncopyable {
friend class View;
@@ -74,7 +76,15 @@ public:
void render();
// Notifies the Map thread that the state has changed and an update might be necessary.
- void triggerUpdate();
+ using UpdateType = uint32_t;
+ enum class Update : UpdateType {
+ Nothing = 0,
+ StyleInfo = 1 << 0,
+ Debug = 1 << 1,
+ DefaultTransitionDuration = 1 << 2,
+ Classes = 1 << 3,
+ };
+ void triggerUpdate(Update = Update::Nothing);
// Triggers a render. Can be called from any thread.
void triggerRender();
@@ -91,8 +101,8 @@ public:
void setDefaultTransitionDuration(std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
std::chrono::steady_clock::duration getDefaultTransitionDuration();
- void setStyleURL(const std::string &url);
- void setStyleJSON(std::string newStyleJSON, const std::string &base = "");
+ void setStyleURL(const std::string& url);
+ void setStyleJSON(const std::string& json, const std::string& base = "");
std::string getStyleJSON() const;
// Transition
@@ -130,7 +140,7 @@ public:
// API
void setAccessToken(const std::string &token);
- const std::string &getAccessToken() const;
+ std::string getAccessToken() const;
// Projection
inline void getWorldBoundsMeters(ProjectedMeters &sw, ProjectedMeters &ne) const { Projection::getWorldBoundsMeters(sw, ne); }
@@ -156,7 +166,7 @@ public:
bool getDebug() const;
inline const TransformState &getState() const { return state; }
- inline std::chrono::steady_clock::time_point getTime() const { return animationTime; }
+ std::chrono::steady_clock::time_point getTime() const;
inline AnnotationManager& getAnnotationManager() const { return *annotationManager; }
private:
@@ -177,6 +187,13 @@ private:
void updateSources();
void updateSources(const util::ptr<StyleLayerGroup> &group);
+ // Triggered by triggerUpdate();
+ void update();
+
+ // Loads the style set in the data object. Called by Update::StyleInfo
+ void reloadStyle();
+ void loadStyleJSON(const std::string& json, const std::string& base);
+
// Prepares a map render by updating the tiles we need for the current view, as well as updating
// the stylesheet.
void prepare();
@@ -192,6 +209,7 @@ private:
Mode mode = Mode::None;
const std::unique_ptr<Environment> env;
+ std::unique_ptr<EnvironmentScope> scope;
View &view;
private:
@@ -223,26 +241,20 @@ private:
FileSource& fileSource;
util::ptr<Style> style;
- const std::unique_ptr<GlyphAtlas> glyphAtlas;
+ std::unique_ptr<GlyphAtlas> glyphAtlas;
util::ptr<GlyphStore> glyphStore;
- const std::unique_ptr<SpriteAtlas> spriteAtlas;
+ std::unique_ptr<SpriteAtlas> spriteAtlas;
util::ptr<Sprite> sprite;
- const std::unique_ptr<LineAtlas> lineAtlas;
+ std::unique_ptr<LineAtlas> lineAtlas;
util::ptr<TexturePool> texturePool;
- const std::unique_ptr<Painter> painter;
+ std::unique_ptr<Painter> painter;
util::ptr<AnnotationManager> annotationManager;
- std::string styleURL;
- std::string styleJSON = "";
- std::vector<std::string> classes;
- std::string accessToken;
-
- std::chrono::steady_clock::duration defaultTransitionDuration;
-
- bool debug = false;
- std::chrono::steady_clock::time_point animationTime = std::chrono::steady_clock::time_point::min();
+ const std::unique_ptr<MapData> data;
std::set<util::ptr<StyleSource>> activeSources;
+
+ std::atomic<UpdateType> updated;
};
}
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index b99a6e6614..6ece6d4de9 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -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);
+ }
};
}