summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-06-17 15:02:29 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-06-18 13:39:18 +0300
commit1f12bcee900732064e6956ac2c23c9066ab5779f (patch)
treebea01a8215b5415cb1ca4565eacbbea48719c7ca /platform
parentff0e54f35a52bf2a4ddfce6e72c11418bd7b88ce (diff)
downloadqtlocation-mapboxgl-1f12bcee900732064e6956ac2c23c9066ab5779f.tar.gz
Support shape annotations on GLFWView
Add different random triangles count by using the keys 7, 8, 9 or 0. Q will clear all the annotations. W will remove one annotation.
Diffstat (limited to 'platform')
-rw-r--r--platform/default/glfw_view.cpp73
1 files changed, 66 insertions, 7 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 0f063e5925..61d553ae3d 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -114,37 +114,96 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
if (!mods)
view->map->resetNorth();
break;
+ case GLFW_KEY_Q:
+ view->clearAnnotations();
+ break;
}
}
if (action == GLFW_RELEASE || action == GLFW_REPEAT) {
switch (key) {
+ case GLFW_KEY_W: view->popAnnotation(); break;
case GLFW_KEY_1: view->addRandomPointAnnotations(1); break;
case GLFW_KEY_2: view->addRandomPointAnnotations(10); break;
case GLFW_KEY_3: view->addRandomPointAnnotations(100); break;
case GLFW_KEY_4: view->addRandomPointAnnotations(1000); break;
case GLFW_KEY_5: view->addRandomPointAnnotations(10000); break;
case GLFW_KEY_6: view->addRandomPointAnnotations(100000); break;
+ case GLFW_KEY_7: view->addRandomShapeAnnotations(1); break;
+ case GLFW_KEY_8: view->addRandomShapeAnnotations(10); break;
+ case GLFW_KEY_9: view->addRandomShapeAnnotations(100); break;
+ case GLFW_KEY_0: view->addRandomShapeAnnotations(1000); break;
}
}
}
+mbgl::LatLng GLFWView::makeRandomPoint() const {
+ const auto sw = map->latLngForPixel({ 0, 0 });
+ const auto ne = map->latLngForPixel({ double(width), double(height) });
+
+ const double lon = sw.longitude + (ne.longitude - sw.longitude) * (double(std::rand()) / RAND_MAX);
+ const double lat = sw.latitude + (ne.latitude - sw.latitude) * (double(std::rand()) / RAND_MAX);
+
+ return { lat, lon };
+}
+
+
void GLFWView::addRandomPointAnnotations(int count) {
std::vector<mbgl::LatLng> points;
std::vector<std::string> markers;
- const auto sw = map->latLngForPixel({ 0, 0 });
- const auto ne = map->latLngForPixel({ double(width), double(height) });
+ for (int i = 0; i < count; i++) {
+ points.push_back(makeRandomPoint());
+ markers.push_back("default_marker");
+ }
+
+ auto newIDs = map->addPointAnnotations(points, markers);
+ annotationIDs.insert(annotationIDs.end(), newIDs.begin(), newIDs.end());
+}
+
+void GLFWView::addRandomShapeAnnotations(int count) {
+ std::vector<mbgl::AnnotationSegments> shapes;
+ std::vector<mbgl::StyleProperties> shapesProperties;
+
+ mbgl::FillProperties fillProperties;
+ fillProperties.opacity = .1;
+
+ mbgl::StyleProperties properties;
+ properties.set<mbgl::FillProperties>(fillProperties);
for (int i = 0; i < count; i++) {
- const double lon = sw.longitude + (ne.longitude - sw.longitude) * (double(std::rand()) / RAND_MAX);
- const double lat = sw.latitude + (ne.latitude - sw.latitude) * (double(std::rand()) / RAND_MAX);
+ mbgl::AnnotationSegment triangle;
+ triangle.push_back(makeRandomPoint());
+ triangle.push_back(makeRandomPoint());
+ triangle.push_back(makeRandomPoint());
- points.push_back({ lat, lon });
- markers.push_back("default_marker");
+ mbgl::AnnotationSegments segments;
+ segments.push_back(triangle);
+
+ shapes.push_back(segments);
+ shapesProperties.push_back(properties);
+ }
+
+ auto newIDs = map->addShapeAnnotations(shapes, shapesProperties);
+ annotationIDs.insert(annotationIDs.end(), newIDs.begin(), newIDs.end());
+}
+
+void GLFWView::clearAnnotations() {
+ if (annotationIDs.empty()) {
+ return;
+ }
+
+ map->removeAnnotations(annotationIDs);
+ annotationIDs.clear();
+}
+
+void GLFWView::popAnnotation() {
+ if (annotationIDs.empty()) {
+ return;
}
- map->addPointAnnotations(points, markers);
+ map->removeAnnotation(annotationIDs.back());
+ annotationIDs.pop_back();
}
void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset) {