summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnsis Brammanis <ansis@mapbox.com>2018-01-10 16:47:08 -0500
committerAnsis Brammanis <ansis.brammanis@gmail.com>2018-01-11 14:07:00 -0500
commitfff33ed7e71cf8bde24f7aa4bb37d0b0d9e19585 (patch)
tree44b445c382e186841b2e9c6db81c6a6282448e5c
parent68159f8d01c468e359c631fd292b146a19bb27a5 (diff)
downloadqtlocation-mapboxgl-fff33ed7e71cf8bde24f7aa4bb37d0b0d9e19585.tar.gz
[glfw] add animated annotations to glfw app for debugging
-rw-r--r--platform/glfw/glfw_view.cpp27
-rw-r--r--platform/glfw/glfw_view.hpp5
2 files changed, 32 insertions, 0 deletions
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 8fc2fba283..3988419265 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -288,6 +288,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
case GLFW_KEY_8: view->addRandomShapeAnnotations(10); break;
case GLFW_KEY_9: view->addRandomShapeAnnotations(100); break;
case GLFW_KEY_0: view->addRandomShapeAnnotations(1000); break;
+ case GLFW_KEY_M: view->addAnimatedAnnotation(); break;
}
}
}
@@ -379,12 +380,36 @@ void GLFWView::addRandomShapeAnnotations(int count) {
}
}
+void GLFWView::addAnimatedAnnotation() {
+ const double started = glfwGetTime();
+ animatedAnnotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { { 0, 0 } , "default_marker" }));
+ animatedAnnotationAddedTimes.push_back(started);
+}
+
+void GLFWView::updateAnimatedAnnotations() {
+ const double time = glfwGetTime();
+ for (size_t i = 0; i < animatedAnnotationIDs.size(); i++) {
+ auto dt = time - animatedAnnotationAddedTimes[i];
+
+ const double period = 10;
+ const double x = dt / period * 360 - 180;
+ const double y = std::sin(dt/ period * M_PI * 2.0) * 80;
+ map->updateAnnotation(animatedAnnotationIDs[i], mbgl::SymbolAnnotation { {x, y }, "default_marker" });
+ }
+}
+
void GLFWView::clearAnnotations() {
for (const auto& id : annotationIDs) {
map->removeAnnotation(id);
}
annotationIDs.clear();
+
+ for (const auto& id : animatedAnnotationIDs) {
+ map->removeAnnotation(id);
+ }
+
+ animatedAnnotationIDs.clear();
}
void GLFWView::popAnnotation() {
@@ -506,6 +531,8 @@ void GLFWView::run() {
if (animateRouteCallback)
animateRouteCallback(map);
+ updateAnimatedAnnotations();
+
activate();
rendererFrontend->render();
diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp
index 35f17b723a..d5acf697f7 100644
--- a/platform/glfw/glfw_view.hpp
+++ b/platform/glfw/glfw_view.hpp
@@ -78,6 +78,8 @@ private:
void addRandomLineAnnotations(int count);
void addRandomShapeAnnotations(int count);
void addRandomCustomPointAnnotations(int count);
+ void addAnimatedAnnotation();
+ void updateAnimatedAnnotations();
void clearAnnotations();
void popAnnotation();
@@ -85,6 +87,9 @@ private:
mbgl::AnnotationIDs annotationIDs;
std::vector<std::string> spriteIDs;
+ mbgl::AnnotationIDs animatedAnnotationIDs;
+ std::vector<double> animatedAnnotationAddedTimes;
+
private:
void toggle3DExtrusions(bool visible);