diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-05-26 16:35:55 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-01 17:36:50 -0700 |
commit | 8985b1311b7d00cf761752bd9291566325ae207a (patch) | |
tree | aa42e0a0f5e0dc592d6dcafdf5ff54013ccc7a25 /platform/default | |
parent | aa1a54c577a95082824f2a5a6bdf4948506fcaa9 (diff) | |
download | qtlocation-mapboxgl-8985b1311b7d00cf761752bd9291566325ae207a.tar.gz |
[core] Use geometry.hpp types for shape annotations
Diffstat (limited to 'platform/default')
-rw-r--r-- | platform/default/glfw_view.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index f5fdb60df7..4a04595c33 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -208,12 +208,17 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, } } -mbgl::LatLng GLFWView::makeRandomPoint() const { +mbgl::LatLng GLFWView::makeRandomLatLng() 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(); + return { latLng.longitude, latLng.latitude }; +} + std::shared_ptr<const mbgl::SpriteImage> GLFWView::makeSpriteImage(int width, int height, float pixelRatio) { const int r = 255 * (double(std::rand()) / RAND_MAX); @@ -261,7 +266,7 @@ void GLFWView::addRandomCustomPointAnnotations(int count) { const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++); map->addAnnotationIcon(name, makeSpriteImage(22, 22, 1)); spriteIDs.push_back(name); - points.emplace_back(makeRandomPoint(), name); + points.emplace_back(makeRandomLatLng(), name); } auto newIDs = map->addPointAnnotations(points); @@ -272,7 +277,7 @@ void GLFWView::addRandomPointAnnotations(int count) { std::vector<mbgl::PointAnnotation> points; for (int i = 0; i < count; i++) { - points.emplace_back(makeRandomPoint(), "default_marker"); + points.emplace_back(makeRandomLatLng(), "default_marker"); } auto newIDs = map->addPointAnnotations(points); @@ -286,15 +291,9 @@ void GLFWView::addRandomShapeAnnotations(int count) { properties.opacity = .1; for (int i = 0; i < count; i++) { - mbgl::AnnotationSegment triangle; - triangle.push_back(makeRandomPoint()); - triangle.push_back(makeRandomPoint()); - triangle.push_back(makeRandomPoint()); - - mbgl::AnnotationSegments segments; - segments.push_back(triangle); - - shapes.emplace_back(segments, properties); + mbgl::Polygon<double> triangle; + triangle.push_back({ makeRandomPoint(), makeRandomPoint(), makeRandomPoint() }); + shapes.emplace_back(triangle, properties); } auto newIDs = map->addShapeAnnotations(shapes); |