summaryrefslogtreecommitdiff
path: root/platform/default
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/default
parentcfd6757ecc9bd4d9b1f4c5266d19da48c529f58b (diff)
downloadqtlocation-mapboxgl-0fba70d5a8465499b0dce900e5aa74f7189e4594.tar.gz
[all] Rationalize annotation API
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/glfw_view.cpp40
1 files changed, 8 insertions, 32 deletions
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();
}