summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-05-31 17:34:11 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-01 17:37:01 -0700
commit0fba70d5a8465499b0dce900e5aa74f7189e4594 (patch)
tree7902b9bd29d25de0de6d116fc3245b1b269477f4 /platform
parentcfd6757ecc9bd4d9b1f4c5266d19da48c529f58b (diff)
downloadqtlocation-mapboxgl-0fba70d5a8465499b0dce900e5aa74f7189e4594.tar.gz
[all] Rationalize annotation API
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/android/src/jni.cpp79
-rw-r--r--platform/darwin/src/MGLGeometry_Private.h5
-rw-r--r--platform/darwin/src/MGLMultiPoint_Private.h4
-rw-r--r--platform/darwin/src/MGLPolygon.mm14
-rw-r--r--platform/darwin/src/MGLPolyline.mm14
-rw-r--r--platform/default/glfw_view.cpp40
-rw-r--r--platform/ios/src/MGLMapView.mm75
-rw-r--r--platform/osx/src/MGLMapView.mm80
-rw-r--r--platform/qt/include/qmapbox.hpp2
-rw-r--r--platform/qt/include/qmapboxgl.hpp4
-rw-r--r--platform/qt/src/qmapboxgl.cpp63
11 files changed, 117 insertions, 263 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 4c3f77e9da..ed2563cf7b 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -13,8 +13,7 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/camera.hpp>
-#include <mbgl/annotation/point_annotation.hpp>
-#include <mbgl/annotation/shape_annotation.hpp>
+#include <mbgl/annotation/annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
@@ -681,8 +680,10 @@ void nativeUpdateMarker(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr,
jdouble latitude = jni::GetField<jdouble>(*env, position, *latLngLatitudeId);
jdouble longitude = jni::GetField<jdouble>(*env, position, *latLngLongitudeId);
- // Because Java only has int, not unsigned int, we need to bump the annotation id up to a long.
- nativeMapView->getMap().updatePointAnnotation(markerId, mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), iconId));
+ nativeMapView->getMap().updateAnnotation(markerId, mbgl::SymbolAnnotation {
+ mbgl::Point<double>(longitude, latitude),
+ iconId
+ });
}
jni::jarray<jlong>* nativeAddMarkers(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jarray<jni::jobject>* jarray) {
@@ -693,30 +694,30 @@ jni::jarray<jlong>* nativeAddMarkers(JNIEnv *env, jni::jobject* obj, jlong nativ
NullCheck(*env, jarray);
std::size_t len = jni::GetArrayLength(*env, *jarray);
- std::vector<mbgl::PointAnnotation> markers;
- markers.reserve(len);
+ std::vector<mbgl::AnnotationID> ids;
+ ids.reserve(len);
for (std::size_t i = 0; i < len; i++) {
jni::jobject* marker = jni::GetObjectArrayElement(*env, *jarray, i);
jni::jobject* position = jni::GetField<jni::jobject*>(*env, marker, *markerPositionId);
jni::jobject* icon = jni::GetField<jni::jobject*>(*env, marker, *markerIconId);
- jni::DeleteLocalRef(*env, marker);
-
jni::jstring* jid = reinterpret_cast<jni::jstring*>(jni::GetField<jni::jobject*>(*env, icon, *iconIdId));
- jni::DeleteLocalRef(*env, icon);
-
- std::string id = std_string_from_jstring(env, jid);
- jni::DeleteLocalRef(*env, jid);
jdouble latitude = jni::GetField<jdouble>(*env, position, *latLngLatitudeId);
jdouble longitude = jni::GetField<jdouble>(*env, position, *latLngLongitudeId);
- jni::DeleteLocalRef(*env, position);
- markers.emplace_back(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), id));
+ ids.push_back(nativeMapView->getMap().addAnnotation(mbgl::SymbolAnnotation {
+ mbgl::Point<double>(longitude, latitude),
+ std_string_from_jstring(env, jid)
+ }));
+
+ jni::DeleteLocalRef(*env, position);
+ jni::DeleteLocalRef(*env, jid);
+ jni::DeleteLocalRef(*env, icon);
+ jni::DeleteLocalRef(*env, marker);
}
- std::vector<uint32_t> pointAnnotationIDs = nativeMapView->getMap().addPointAnnotations(markers);
- return std_vector_uint_to_jobject(env, pointAnnotationIDs);
+ return std_vector_uint_to_jobject(env, ids);
}
static mbgl::Color toColor(jint color) {
@@ -762,24 +763,23 @@ jni::jarray<jlong>* nativeAddPolylines(JNIEnv *env, jni::jobject* obj, jlong nat
NullCheck(*env, jarray);
std::size_t len = jni::GetArrayLength(*env, *jarray);
- std::vector<mbgl::ShapeAnnotation> shapes;
- shapes.reserve(len);
+ std::vector<mbgl::AnnotationID> ids;
+ ids.reserve(len);
for (std::size_t i = 0; i < len; i++) {
jni::jobject* polyline = jni::GetObjectArrayElement(*env, *jarray, i);
-
- mbgl::LineAnnotationProperties lineProperties;
- lineProperties.opacity = jni::GetField<jfloat>(*env, polyline, *polylineAlphaId);
- lineProperties.color = toColor(jni::GetField<jint>(*env, polyline, *polylineColorId));
- lineProperties.width = jni::GetField<jfloat>(*env, polyline, *polylineWidthId);
-
jni::jobject* points = jni::GetField<jni::jobject*>(*env, polyline, *polylinePointsId);
- shapes.emplace_back(toGeometry<mbgl::LineString<double>>(env, points), lineProperties);
+
+ mbgl::LineAnnotation annotation { toGeometry<mbgl::LineString<double>>(env, points) };
+ annotation.opacity = jni::GetField<jfloat>(*env, polyline, *polylineAlphaId);
+ annotation.color = toColor(jni::GetField<jint>(*env, polyline, *polylineColorId));
+ annotation.width = jni::GetField<jfloat>(*env, polyline, *polylineWidthId);
+ ids.push_back(nativeMapView->getMap().addAnnotation(annotation));
jni::DeleteLocalRef(*env, polyline);
}
- return std_vector_uint_to_jobject(env, nativeMapView->getMap().addShapeAnnotations(shapes));
+ return std_vector_uint_to_jobject(env, ids);
}
jni::jarray<jlong>* nativeAddPolygons(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jarray<jni::jobject>* jarray) {
@@ -790,24 +790,23 @@ jni::jarray<jlong>* nativeAddPolygons(JNIEnv *env, jni::jobject* obj, jlong nati
NullCheck(*env, jarray);
std::size_t len = jni::GetArrayLength(*env, *jarray);
- std::vector<mbgl::ShapeAnnotation> shapes;
- shapes.reserve(len);
+ std::vector<mbgl::AnnotationID> ids;
+ ids.reserve(len);
for (std::size_t i = 0; i < len; i++) {
jni::jobject* polygon = jni::GetObjectArrayElement(*env, *jarray, i);
-
- mbgl::FillAnnotationProperties fillProperties;
- fillProperties.opacity = jni::GetField<jfloat>(*env, polygon, *polygonAlphaId);
- fillProperties.outlineColor = toColor(jni::GetField<jint>(*env, polygon, *polygonStrokeColorId));
- fillProperties.color = toColor(jni::GetField<jint>(*env, polygon, *polygonFillColorId));
-
jni::jobject* points = jni::GetField<jni::jobject*>(*env, polygon, *polygonPointsId);
- shapes.emplace_back(mbgl::Polygon<double> { toGeometry<mbgl::LinearRing<double>>(env, points) }, fillProperties);
+
+ mbgl::FillAnnotation annotation { mbgl::Polygon<double> { toGeometry<mbgl::LinearRing<double>>(env, points) } };
+ annotation.opacity = jni::GetField<jfloat>(*env, polygon, *polygonAlphaId);
+ annotation.outlineColor = toColor(jni::GetField<jint>(*env, polygon, *polygonStrokeColorId));
+ annotation.color = toColor(jni::GetField<jint>(*env, polygon, *polygonFillColorId));
+ ids.push_back(nativeMapView->getMap().addAnnotation(annotation));
jni::DeleteLocalRef(*env, polygon);
}
- return std_vector_uint_to_jobject(env, nativeMapView->getMap().addShapeAnnotations(shapes));
+ return std_vector_uint_to_jobject(env, ids);
}
void nativeRemoveAnnotations(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jarray<jlong>* jarray) {
@@ -817,20 +816,14 @@ void nativeRemoveAnnotations(JNIEnv *env, jni::jobject* obj, jlong nativeMapView
NullCheck(*env, jarray);
std::size_t len = jni::GetArrayLength(*env, *jarray);
-
- std::vector<uint32_t> ids;
- ids.reserve(len);
-
auto elements = jni::GetArrayElements(*env, *jarray);
jlong* jids = std::get<0>(elements).get();
for (std::size_t i = 0; i < len; i++) {
if(jids[i] == -1L)
continue;
- ids.push_back(static_cast<uint32_t>(jids[i]));
+ nativeMapView->getMap().removeAnnotation(jids[i]);
}
-
- nativeMapView->getMap().removeAnnotations(ids);
}
jni::jarray<jlong>* nativeGetAnnotationsInBounds(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jobject* latLngBounds_) {
diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h
index 0538cd94ea..fc57460128 100644
--- a/platform/darwin/src/MGLGeometry_Private.h
+++ b/platform/darwin/src/MGLGeometry_Private.h
@@ -6,6 +6,7 @@
#endif
#import <mbgl/util/geo.hpp>
+#import <mbgl/util/geometry.hpp>
/// Returns the smallest rectangle that contains both the given rectangle and
/// the given point.
@@ -15,6 +16,10 @@ NS_INLINE mbgl::LatLng MGLLatLngFromLocationCoordinate2D(CLLocationCoordinate2D
return mbgl::LatLng(coordinate.latitude, coordinate.longitude);
}
+NS_INLINE mbgl::Point<double> MGLPointFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
+ return mbgl::Point<double>(coordinate.longitude, coordinate.latitude);
+}
+
NS_INLINE CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng) {
return CLLocationCoordinate2DMake(latLng.latitude, latLng.longitude);
}
diff --git a/platform/darwin/src/MGLMultiPoint_Private.h b/platform/darwin/src/MGLMultiPoint_Private.h
index f7a7bd4ffd..aa52a02fcb 100644
--- a/platform/darwin/src/MGLMultiPoint_Private.h
+++ b/platform/darwin/src/MGLMultiPoint_Private.h
@@ -3,7 +3,7 @@
#import "MGLGeometry.h"
#import "MGLTypes.h"
-#import <mbgl/annotation/shape_annotation.hpp>
+#import <mbgl/annotation/annotation.hpp>
#import <vector>
#import <CoreGraphics/CoreGraphics.h>
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)intersectsOverlayBounds:(MGLCoordinateBounds)overlayBounds;
/** Constructs a shape annotation object, asking the delegate for style values. */
-- (mbgl::ShapeAnnotation)shapeAnnotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate;
+- (mbgl::Annotation)annotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate;
@end
diff --git a/platform/darwin/src/MGLPolygon.mm b/platform/darwin/src/MGLPolygon.mm
index 47be070246..c009d9e3d6 100644
--- a/platform/darwin/src/MGLPolygon.mm
+++ b/platform/darwin/src/MGLPolygon.mm
@@ -36,19 +36,19 @@
return result;
}
-- (mbgl::ShapeAnnotation)shapeAnnotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate {
- mbgl::FillAnnotationProperties fillProperties;
- fillProperties.opacity = [delegate alphaForShapeAnnotation:self];
- fillProperties.outlineColor = [delegate strokeColorForShapeAnnotation:self];
- fillProperties.color = [delegate fillColorForPolygonAnnotation:self];
-
+- (mbgl::Annotation)annotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate {
mbgl::Polygon<double> geometry;
geometry.push_back(self.ring);
for (MGLPolygon *polygon in self.interiorPolygons) {
geometry.push_back(polygon.ring);
}
- return mbgl::ShapeAnnotation(geometry, fillProperties);
+ mbgl::FillAnnotation annotation { geometry };
+ annotation.opacity = [delegate alphaForShapeAnnotation:self];
+ annotation.outlineColor = [delegate strokeColorForShapeAnnotation:self];
+ annotation.color = [delegate fillColorForPolygonAnnotation:self];
+
+ return annotation;
}
@end
diff --git a/platform/darwin/src/MGLPolyline.mm b/platform/darwin/src/MGLPolyline.mm
index ebba5c862e..15ea5a0952 100644
--- a/platform/darwin/src/MGLPolyline.mm
+++ b/platform/darwin/src/MGLPolyline.mm
@@ -13,12 +13,7 @@
return [[self alloc] initWithCoordinates:coords count:count];
}
-- (mbgl::ShapeAnnotation)shapeAnnotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate {
- mbgl::LineAnnotationProperties lineProperties;
- lineProperties.opacity = [delegate alphaForShapeAnnotation:self];
- lineProperties.color = [delegate strokeColorForShapeAnnotation:self];
- lineProperties.width = [delegate lineWidthForPolylineAnnotation:self];
-
+- (mbgl::Annotation)annotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate {
NSUInteger count = self.pointCount;
CLLocationCoordinate2D *coordinates = self.coordinates;
@@ -28,7 +23,12 @@
geometry.push_back(mbgl::Point<double>(coordinates[i].longitude, coordinates[i].latitude));
}
- return mbgl::ShapeAnnotation(geometry, lineProperties);
+ mbgl::LineAnnotation annotation { geometry };
+ annotation.opacity = [delegate alphaForShapeAnnotation:self];
+ annotation.color = [delegate strokeColorForShapeAnnotation:self];
+ annotation.width = [delegate lineWidthForPolylineAnnotation:self];
+
+ return annotation;
}
@end
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 4a04595c33..2280c3f2ae 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -1,6 +1,5 @@
#include <mbgl/platform/default/glfw_view.hpp>
-#include <mbgl/annotation/point_annotation.hpp>
-#include <mbgl/annotation/shape_annotation.hpp>
+#include <mbgl/annotation/annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/style/property_transition.hpp>
#include <mbgl/gl/gl.hpp>
@@ -208,14 +207,10 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
}
}
-mbgl::LatLng GLFWView::makeRandomLatLng() const {
+mbgl::Point<double> GLFWView::makeRandomPoint() const {
const double x = width * double(std::rand()) / RAND_MAX;
const double y = height * double(std::rand()) / RAND_MAX;
- return map->latLngForPixel({ x, y });
-}
-
-mbgl::Point<double> GLFWView::makeRandomPoint() const {
- mbgl::LatLng latLng = makeRandomLatLng();
+ mbgl::LatLng latLng = map->latLngForPixel({ x, y });
return { latLng.longitude, latLng.latitude };
}
@@ -259,53 +254,34 @@ void GLFWView::nextOrientation() {
}
void GLFWView::addRandomCustomPointAnnotations(int count) {
- std::vector<mbgl::PointAnnotation> points;
-
for (int i = 0; i < count; i++) {
static int spriteID = 1;
const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++);
map->addAnnotationIcon(name, makeSpriteImage(22, 22, 1));
spriteIDs.push_back(name);
- points.emplace_back(makeRandomLatLng(), name);
+ annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), name }));
}
-
- auto newIDs = map->addPointAnnotations(points);
- annotationIDs.insert(annotationIDs.end(), newIDs.begin(), newIDs.end());
}
void GLFWView::addRandomPointAnnotations(int count) {
- std::vector<mbgl::PointAnnotation> points;
-
for (int i = 0; i < count; i++) {
- points.emplace_back(makeRandomLatLng(), "default_marker");
+ annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), "default_marker" }));
}
-
- auto newIDs = map->addPointAnnotations(points);
- annotationIDs.insert(annotationIDs.end(), newIDs.begin(), newIDs.end());
}
void GLFWView::addRandomShapeAnnotations(int count) {
- std::vector<mbgl::ShapeAnnotation> shapes;
-
- mbgl::FillAnnotationProperties properties;
- properties.opacity = .1;
-
for (int i = 0; i < count; i++) {
mbgl::Polygon<double> triangle;
triangle.push_back({ makeRandomPoint(), makeRandomPoint(), makeRandomPoint() });
- shapes.emplace_back(triangle, properties);
+ annotationIDs.push_back(map->addAnnotation(mbgl::FillAnnotation { triangle, .1 }));
}
-
- auto newIDs = map->addShapeAnnotations(shapes);
- annotationIDs.insert(annotationIDs.end(), newIDs.begin(), newIDs.end());
}
void GLFWView::clearAnnotations() {
- if (annotationIDs.empty()) {
- return;
+ for (const auto& id : annotationIDs) {
+ map->removeAnnotation(id);
}
- map->removeAnnotations(annotationIDs);
annotationIDs.clear();
}
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index eacd2f7b74..87d821fba9 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -7,8 +7,7 @@
#import <OpenGLES/EAGL.h>
#include <mbgl/mbgl.hpp>
-#include <mbgl/annotation/point_annotation.hpp>
-#include <mbgl/annotation/shape_annotation.hpp>
+#include <mbgl/annotation/annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/mode.hpp>
@@ -1776,9 +1775,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// but safely updated.
if (annotation == [self annotationWithTag:annotationTag])
{
- const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(annotation.coordinate);
+ const mbgl::Point<double> point = MGLPointFromLocationCoordinate2D(annotation.coordinate);
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
- _mbglMap->updatePointAnnotation(annotationTag, { latLng, annotationImage.styleIconIdentifier.UTF8String ?: "" });
+ _mbglMap->updateAnnotation(annotationTag, mbgl::SymbolAnnotation { point, annotationImage.styleIconIdentifier.UTF8String ?: "" });
if (annotationTag == _selectedAnnotationTag)
{
[self deselectAnnotation:annotation animated:YES];
@@ -2796,11 +2795,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if ( ! annotations) return;
[self willChangeValueForKey:@"annotations"];
- NSMutableArray *userPoints = [NSMutableArray array];
- std::vector<mbgl::PointAnnotation> points;
- NSMutableArray *userShapes = [NSMutableArray array];
- std::vector<mbgl::ShapeAnnotation> shapes;
-
NSMutableDictionary *annotationImagesForAnnotation = [NSMutableDictionary dictionary];
NSMutableDictionary *annotationViewsForAnnotation = [NSMutableDictionary dictionary];
@@ -2820,8 +2814,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (!multiPoint.pointCount) {
continue;
}
- shapes.emplace_back([multiPoint shapeAnnotationObjectWithDelegate:self]);
- [userShapes addObject:annotation];
+
+ MGLAnnotationTag annotationTag = _mbglMap->addAnnotation([multiPoint annotationObjectWithDelegate:self]);
+ MGLAnnotationContext context;
+ context.annotation = annotation;
+ _annotationContextsByAnnotationTag[annotationTag] = context;
}
else if ([annotation isKindOfClass:[MGLMultiPolyline class]]
|| [annotation isKindOfClass:[MGLMultiPolygon class]]
@@ -2877,22 +2874,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
annotationImagesForAnnotation[annotationValue] = annotationImage;
}
- [userPoints addObject:annotation];
- points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName.UTF8String ?: "");
- }
- }
+ MGLAnnotationTag annotationTag = _mbglMap->addAnnotation(mbgl::SymbolAnnotation {
+ MGLPointFromLocationCoordinate2D(annotation.coordinate),
+ symbolName.UTF8String ?: ""
+ });
- if (points.size())
- {
- // refactor this to build contexts above and just associate with tags here
-
- std::vector<MGLAnnotationTag> annotationTags = _mbglMap->addPointAnnotations(points);
-
- for (size_t i = 0; i < annotationTags.size(); ++i)
- {
- id<MGLAnnotation> annotation = userPoints[i];
- NSValue *annotationValue = [NSValue valueWithNonretainedObject:annotation];
-
MGLAnnotationContext context;
context.annotation = annotation;
MGLAnnotationImage *annotationImage = annotationImagesForAnnotation[annotationValue];
@@ -2900,13 +2886,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (annotationImage) {
context.imageReuseIdentifier = annotationImage.reuseIdentifier;
}
- MGLAnnotationView *annotationView = annotationViewsForAnnotation[annotationValue];
if (annotationView) {
context.annotationView = annotationView;
context.viewReuseIdentifier = annotationView.reuseIdentifier;
}
- MGLAnnotationTag annotationTag = annotationTags[i];
_annotationContextsByAnnotationTag[annotationTag] = context;
if ([annotation isKindOfClass:[NSObject class]]) {
NSAssert(![annotation isKindOfClass:[MGLMultiPoint class]], @"Point annotation should not be MGLMultiPoint.");
@@ -2915,21 +2899,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
}
- if (shapes.size())
- {
- std::vector<MGLAnnotationTag> annotationTags = _mbglMap->addShapeAnnotations(shapes);
-
- for (size_t i = 0; i < annotationTags.size(); ++i)
- {
- MGLAnnotationTag annotationTag = annotationTags[i];
- id <MGLAnnotation> annotation = userShapes[i];
-
- MGLAnnotationContext context;
- context.annotation = annotation;
- _annotationContextsByAnnotationTag[annotationTag] = context;
- }
- }
-
[self updateAnnotationContainerViewWithAnnotationViews:newAnnotationViews];
[self didChangeValueForKey:@"annotations"];
@@ -3072,8 +3041,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ( ! annotations) return;
- std::vector<MGLAnnotationTag> annotationTagsToRemove;
- annotationTagsToRemove.reserve(annotations.count);
+ [self willChangeValueForKey:@"annotations"];
for (id <MGLAnnotation> annotation in annotations)
{
@@ -3088,8 +3056,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
MGLAnnotationView *annotationView = annotationContext.annotationView;
[annotationView removeFromSuperview];
-
- annotationTagsToRemove.push_back(annotationTag);
if (annotationTag == _selectedAnnotationTag)
{
@@ -3102,15 +3068,12 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
[(NSObject *)annotation removeObserver:self forKeyPath:@"coordinate" context:(void *)(NSUInteger)annotationTag];
}
- }
- if ( ! annotationTagsToRemove.empty())
- {
- [self willChangeValueForKey:@"annotations"];
- _mbglMap->removeAnnotations(annotationTagsToRemove);
- [self didChangeValueForKey:@"annotations"];
- UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
+ _mbglMap->removeAnnotation(annotationTag);
}
+
+ [self didChangeValueForKey:@"annotations"];
+ UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
}
- (void)addOverlay:(id <MGLOverlay>)overlay
@@ -3675,8 +3638,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ([pair.second.imageReuseIdentifier isEqualToString:reuseIdentifier])
{
- const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(pair.second.annotation.coordinate);
- _mbglMap->updatePointAnnotation(pair.first, { latLng, iconIdentifier.UTF8String ?: "" });
+ const mbgl::Point<double> point = MGLPointFromLocationCoordinate2D(pair.second.annotation.coordinate);
+ _mbglMap->updateAnnotation(pair.first, mbgl::SymbolAnnotation { point, iconIdentifier.UTF8String ?: "" });
}
}
}
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 019f497649..03b94c25ba 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -18,7 +18,7 @@
#import "MGLMapViewDelegate.h"
#import <mbgl/mbgl.hpp>
-#import <mbgl/annotation/point_annotation.hpp>
+#import <mbgl/annotation/annotation.hpp>
#import <mbgl/map/camera.hpp>
#import <mbgl/platform/darwin/reachability.h>
#import <mbgl/gl/gl.hpp>
@@ -481,9 +481,9 @@ public:
// match a valid annotation tag, the annotation will be unnecessarily
// but safely updated.
if (annotation == [self annotationWithTag:annotationTag]) {
- const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(annotation.coordinate);
+ const mbgl::Point<double> point = MGLPointFromLocationCoordinate2D(annotation.coordinate);
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
- _mbglMap->updatePointAnnotation(annotationTag, { latLng, annotationImage.styleIconIdentifier.UTF8String ?: "" });
+ _mbglMap->updateAnnotation(annotationTag, mbgl::SymbolAnnotation { point, annotationImage.styleIconIdentifier.UTF8String ?: "" });
if (annotationTag == _selectedAnnotationTag) {
[self deselectAnnotation:annotation];
}
@@ -1604,12 +1604,6 @@ public:
BOOL delegateHasImagesForAnnotations = [self.delegate respondsToSelector:@selector(mapView:imageForAnnotation:)];
- NSMutableArray *userPoints = [NSMutableArray array];
- std::vector<mbgl::PointAnnotation> points;
- NSMutableArray *userShapes = [NSMutableArray array];
- std::vector<mbgl::ShapeAnnotation> shapes;
- NSMutableArray *annotationImages = [NSMutableArray arrayWithCapacity:annotations.count];
-
for (id <MGLAnnotation> annotation in annotations) {
NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"Annotation does not conform to MGLAnnotation");
@@ -1619,8 +1613,11 @@ public:
if (!multiPoint.pointCount) {
continue;
}
- shapes.emplace_back([multiPoint shapeAnnotationObjectWithDelegate:self]);
- [userShapes addObject:annotation];
+
+ MGLAnnotationTag annotationTag = _mbglMap->addAnnotation([multiPoint annotationObjectWithDelegate:self]);
+ MGLAnnotationContext context;
+ context.annotation = annotation;
+ _annotationContextsByAnnotationTag[annotationTag] = context;
} else if ([annotation isKindOfClass:[MGLMultiPolyline class]]
|| [annotation isKindOfClass:[MGLMultiPolygon class]]
|| [annotation isKindOfClass:[MGLShapeCollection class]]) {
@@ -1647,28 +1644,12 @@ public:
self.annotationImagesByIdentifier[annotationImage.reuseIdentifier] = annotationImage;
[self installAnnotationImage:annotationImage];
}
- [annotationImages addObject:annotationImage];
-
- [userPoints addObject:annotation];
- points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName.UTF8String ?: "");
-
- // Opt into potentially expensive tooltip tracking areas.
- if (annotation.toolTip.length) {
- _wantsToolTipRects = YES;
- }
- }
- }
-
- // Add any point annotations to mbgl and our own index.
- if (points.size()) {
- std::vector<MGLAnnotationTag> annotationTags = _mbglMap->addPointAnnotations(points);
-
- for (size_t i = 0; i < annotationTags.size(); ++i) {
- MGLAnnotationTag annotationTag = annotationTags[i];
- MGLAnnotationImage *annotationImage = annotationImages[i];
- annotationImage.styleIconIdentifier = @(points[i].icon.c_str());
- id <MGLAnnotation> annotation = userPoints[i];
-
+
+ MGLAnnotationTag annotationTag = _mbglMap->addAnnotation(mbgl::SymbolAnnotation {
+ MGLPointFromLocationCoordinate2D(annotation.coordinate),
+ symbolName.UTF8String ?: ""
+ });
+
MGLAnnotationContext context;
context.annotation = annotation;
context.imageReuseIdentifier = annotationImage.reuseIdentifier;
@@ -1678,23 +1659,14 @@ public:
NSAssert(![annotation isKindOfClass:[MGLMultiPoint class]], @"Point annotation should not be MGLMultiPoint.");
[(NSObject *)annotation addObserver:self forKeyPath:@"coordinate" options:0 context:(void *)(NSUInteger)annotationTag];
}
+
+ // Opt into potentially expensive tooltip tracking areas.
+ if (annotation.toolTip.length) {
+ _wantsToolTipRects = YES;
+ }
}
}
-
- // Add any shape annotations to mbgl and our own index.
- if (shapes.size()) {
- std::vector<MGLAnnotationTag> annotationTags = _mbglMap->addShapeAnnotations(shapes);
-
- for (size_t i = 0; i < annotationTags.size(); ++i) {
- MGLAnnotationTag annotationTag = annotationTags[i];
- id <MGLAnnotation> annotation = userShapes[i];
-
- MGLAnnotationContext context;
- context.annotation = annotation;
- _annotationContextsByAnnotationTag[annotationTag] = context;
- }
- }
-
+
[self didChangeValueForKey:@"annotations"];
[self updateAnnotationTrackingAreas];
@@ -1765,16 +1737,14 @@ public:
return;
}
- std::vector<MGLAnnotationTag> annotationTagsToRemove;
- annotationTagsToRemove.reserve(annotations.count);
-
+ [self willChangeValueForKey:@"annotations"];
+
for (id <MGLAnnotation> annotation in annotations) {
NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"Annotation does not conform to MGLAnnotation");
MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation];
NSAssert(annotationTag != MGLAnnotationTagNotFound, @"No ID for annotation %@", annotation);
- annotationTagsToRemove.push_back(annotationTag);
-
+
if (annotationTag == _selectedAnnotationTag) {
[self deselectAnnotation:annotation];
}
@@ -1788,10 +1758,10 @@ public:
![annotation isKindOfClass:[MGLMultiPoint class]]) {
[(NSObject *)annotation removeObserver:self forKeyPath:@"coordinate" context:(void *)(NSUInteger)annotationTag];
}
+
+ _mbglMap->removeAnnotation(annotationTag);
}
- [self willChangeValueForKey:@"annotations"];
- _mbglMap->removeAnnotations(annotationTagsToRemove);
[self didChangeValueForKey:@"annotations"];
[self updateAnnotationTrackingAreas];
diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp
index f2cf363ea3..3200da2729 100644
--- a/platform/qt/include/qmapbox.hpp
+++ b/platform/qt/include/qmapbox.hpp
@@ -20,11 +20,9 @@ typedef quint32 AnnotationID;
typedef QList<AnnotationID> AnnotationIDs;
typedef QPair<Coordinate, QString> PointAnnotation;
-typedef QList<PointAnnotation> PointAnnotations;
// FIXME: We need to add support for custom style properties
typedef QPair<CoordinateSegments, QString> ShapeAnnotation;
-typedef QList<ShapeAnnotation> ShapeAnnotations;
enum NetworkMode {
Online, // Default
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index 3b10dadc9c..8ce6b02f47 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -165,15 +165,11 @@ public:
QStringList getClasses() const;
QMapbox::AnnotationID addPointAnnotation(const QMapbox::PointAnnotation &);
- QMapbox::AnnotationIDs addPointAnnotations(const QMapbox::PointAnnotations &);
-
QMapbox::AnnotationID addShapeAnnotation(const QMapbox::ShapeAnnotation &);
- QMapbox::AnnotationIDs addShapeAnnotations(const QMapbox::ShapeAnnotations &);
void updatePointAnnotation(QMapbox::AnnotationID, const QMapbox::PointAnnotation &);
void removeAnnotation(QMapbox::AnnotationID);
- void removeAnnotations(const QMapbox::AnnotationIDs &);
bool isRotating() const;
bool isScaling() const;
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 976da9a1eb..1f8657c044 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1,7 +1,6 @@
#include "qmapboxgl_p.hpp"
-#include <mbgl/annotation/point_annotation.hpp>
-#include <mbgl/annotation/shape_annotation.hpp>
+#include <mbgl/annotation/annotation.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/map.hpp>
@@ -376,40 +375,23 @@ QStringList QMapboxGL::getClasses() const
return classNames;
}
-mbgl::PointAnnotation fromPointAnnotation(const PointAnnotation &pointAnnotation) {
+mbgl::Annotation fromPointAnnotation(const PointAnnotation &pointAnnotation) {
const Coordinate &coordinate = pointAnnotation.first;
const QString &icon = pointAnnotation.second;
- return { { coordinate.first, coordinate.second }, icon.toStdString() };
+ return mbgl::SymbolAnnotation { mbgl::Point<double> { coordinate.second, coordinate.first }, icon.toStdString() };
}
AnnotationID QMapboxGL::addPointAnnotation(const PointAnnotation &pointAnnotation)
{
- return d_ptr->mapObj->addPointAnnotation(fromPointAnnotation(pointAnnotation));
-}
-
-AnnotationIDs QMapboxGL::addPointAnnotations(const PointAnnotations &pointAnnotations)
-{
- std::vector<mbgl::PointAnnotation> mbglPointAnnotations;
- mbglPointAnnotations.reserve(pointAnnotations.size());
-
- for (const PointAnnotation &pointAnnotation : pointAnnotations) {
- mbglPointAnnotations.emplace_back(fromPointAnnotation(pointAnnotation));
- }
-
- AnnotationIDs ids;
- for (const mbgl::AnnotationID &id : d_ptr->mapObj->addPointAnnotations(mbglPointAnnotations)) {
- ids << id;
- }
-
- return ids;
+ return d_ptr->mapObj->addAnnotation(fromPointAnnotation(pointAnnotation));
}
void QMapboxGL::updatePointAnnotation(AnnotationID id, const PointAnnotation &pointAnnotation)
{
- d_ptr->mapObj->updatePointAnnotation(id, fromPointAnnotation(pointAnnotation));
+ d_ptr->mapObj->updateAnnotation(id, fromPointAnnotation(pointAnnotation));
}
-mbgl::ShapeAnnotation fromQMapboxGLShapeAnnotation(const ShapeAnnotation &shapeAnnotation) {
+mbgl::Annotation fromQMapboxGLShapeAnnotation(const ShapeAnnotation &shapeAnnotation) {
const CoordinateSegments &segments = shapeAnnotation.first;
const QString &styleLayer = shapeAnnotation.second;
@@ -427,29 +409,12 @@ mbgl::ShapeAnnotation fromQMapboxGLShapeAnnotation(const ShapeAnnotation &shapeA
polygon.emplace_back(linearRing);
}
- return { polygon, styleLayer.toStdString() };
+ return mbgl::StyleSourcedAnnotation { polygon, styleLayer.toStdString() };
}
AnnotationID QMapboxGL::addShapeAnnotation(const ShapeAnnotation &shapeAnnotation)
{
- return d_ptr->mapObj->addShapeAnnotation(fromQMapboxGLShapeAnnotation(shapeAnnotation));
-}
-
-AnnotationIDs QMapboxGL::addShapeAnnotations(const ShapeAnnotations &shapeAnnotations)
-{
- std::vector<mbgl::ShapeAnnotation> mbglShapeAnnotations;
- mbglShapeAnnotations.reserve(shapeAnnotations.size());
-
- for (const ShapeAnnotation &shapeAnnotation : shapeAnnotations) {
- mbglShapeAnnotations.emplace_back(fromQMapboxGLShapeAnnotation(shapeAnnotation));
- }
-
- AnnotationIDs ids;
- for (const mbgl::AnnotationID &id : d_ptr->mapObj->addShapeAnnotations(mbglShapeAnnotations)) {
- ids << id;
- }
-
- return ids;
+ return d_ptr->mapObj->addAnnotation(fromQMapboxGLShapeAnnotation(shapeAnnotation));
}
void QMapboxGL::removeAnnotation(AnnotationID annotationID)
@@ -457,18 +422,6 @@ void QMapboxGL::removeAnnotation(AnnotationID annotationID)
d_ptr->mapObj->removeAnnotation(annotationID);
}
-void QMapboxGL::removeAnnotations(const AnnotationIDs &annotationIDs)
-{
- std::vector<mbgl::AnnotationID> mbglAnnotationIds;
- mbglAnnotationIds.reserve(annotationIDs.size());
-
- for (const AnnotationID annotationID : annotationIDs) {
- mbglAnnotationIds.emplace_back(annotationID);
- }
-
- d_ptr->mapObj->removeAnnotations(mbglAnnotationIds);
-}
-
bool QMapboxGL::isRotating() const
{
return d_ptr->mapObj->isRotating();