diff --git a/include/mbgl/annotation/point_annotation.hpp b/include/mbgl/annotation/point_annotation.hpp deleted file mode 100644 index 17b6fe53695..00000000000 --- a/include/mbgl/annotation/point_annotation.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MBGL_ANNOTATION_POINT_ANNOTATION -#define MBGL_ANNOTATION_POINT_ANNOTATION - -#include - -#include - -namespace mbgl { - -class PointAnnotation { -public: - inline PointAnnotation(const LatLng& position_, const std::string& icon_ = "") - : position(position_), icon(icon_) { - } - - const LatLng position; - const std::string icon; -}; - -} - -#endif diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 4418bcaaa4d..5535dbcc917 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -21,7 +21,6 @@ class View; class MapData; class MapContext; class StillImage; -class PointAnnotation; namespace util { template class Thread; @@ -112,8 +111,9 @@ class Map : private util::noncopyable { // Annotations void setDefaultPointAnnotationSymbol(const std::string&); double getTopOffsetPixelsForAnnotationSymbol(const std::string&); - uint32_t addPointAnnotation(const PointAnnotation&); - std::vector addPointAnnotations(const std::vector&); + uint32_t addPointAnnotation(const LatLng&, const std::string& symbol); + std::vector addPointAnnotations(const std::vector&, + const std::vector& symbols); void removeAnnotation(uint32_t); void removeAnnotations(const std::vector&); std::vector getAnnotationsInBounds(const LatLngBounds&); diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index e9da7529098..0f063e59253 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -131,7 +130,8 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, } void GLFWView::addRandomPointAnnotations(int count) { - std::vector points; + std::vector points; + std::vector markers; const auto sw = map->latLngForPixel({ 0, 0 }); const auto ne = map->latLngForPixel({ double(width), double(height) }); @@ -140,10 +140,11 @@ void GLFWView::addRandomPointAnnotations(int count) { 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); - points.emplace_back(mbgl::LatLng{ lat, lon }, "default_marker"); + points.push_back({ lat, lon }); + markers.push_back("default_marker"); } - map->addPointAnnotations(points); + map->addPointAnnotations(points, markers); } void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset) { diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 793363b6386..4ef63d4bf87 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -8,7 +8,6 @@ #import #include -#include #include #include #include @@ -1670,8 +1669,11 @@ - (void)addAnnotations:(NSArray *)annotations { if ( ! annotations) return; - std::vector points; - points.reserve(annotations.count); + std::vector latLngs; + latLngs.reserve(annotations.count); + + std::vector symbols; + symbols.reserve(annotations.count); BOOL delegateImplementsSymbolLookup = [self.delegate respondsToSelector:@selector(mapView:symbolNameForAnnotation:)]; @@ -1679,6 +1681,8 @@ - (void)addAnnotations:(NSArray *)annotations { assert([annotation conformsToProtocol:@protocol(MGLAnnotation)]); + latLngs.push_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate)); + NSString *symbolName = nil; if (delegateImplementsSymbolLookup) @@ -1686,10 +1690,10 @@ - (void)addAnnotations:(NSArray *)annotations symbolName = [self.delegate mapView:self symbolNameForAnnotation:annotation]; } - points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), (symbolName ? [symbolName UTF8String] : "")); + symbols.push_back((symbolName ? [symbolName UTF8String] : "")); } - std::vector annotationIDs = _mbglMap->addPointAnnotations(points); + std::vector annotationIDs = _mbglMap->addPointAnnotations(latLngs, symbols); for (size_t i = 0; i < annotationIDs.size(); ++i) { diff --git a/src/mbgl/map/annotation.cpp b/src/mbgl/map/annotation.cpp index 481d19cd503..6df49ec647a 100644 --- a/src/mbgl/map/annotation.cpp +++ b/src/mbgl/map/annotation.cpp @@ -85,7 +85,8 @@ vec2 AnnotationManager::projectPoint(const LatLng& point) { } std::pair, AnnotationIDs> -AnnotationManager::addPointAnnotations(const std::vector& points, +AnnotationManager::addPointAnnotations(const std::vector& points, + const std::vector& symbols, const MapData& data) { std::lock_guard lock(mtx); @@ -102,14 +103,14 @@ AnnotationManager::addPointAnnotations(const std::vector& point std::vector affectedTiles; - for (const PointAnnotation& point : points) { + for (size_t i = 0; i < points.size(); ++i) { const uint32_t annotationID = nextID(); // track the annotation global ID and its geometry auto anno_it = annotations.emplace( annotationID, std::make_unique(AnnotationType::Point, - AnnotationSegments({ { point.position } }))); + AnnotationSegments({ { points[i] } }))); const uint8_t maxZoom = data.transform.getMaxZoom(); @@ -117,7 +118,7 @@ AnnotationManager::addPointAnnotations(const std::vector& point uint32_t z2 = 1 << maxZoom; // projection conversion into unit space - const vec2 p = projectPoint(point.position); + const vec2 p = projectPoint(points[i]); uint32_t x = p.x * z2; uint32_t y = p.y * z2; @@ -133,7 +134,7 @@ AnnotationManager::addPointAnnotations(const std::vector& point // at render time we style the annotation according to its {sprite} field const std::map properties = { - { "sprite", (point.icon.length() ? point.icon : defaultPointAnnotationSymbol) } + { "sprite", (symbols[i].length() ? symbols[i] : defaultPointAnnotationSymbol) } }; auto feature = diff --git a/src/mbgl/map/annotation.hpp b/src/mbgl/map/annotation.hpp index fb78a832c9e..0c9a078e579 100644 --- a/src/mbgl/map/annotation.hpp +++ b/src/mbgl/map/annotation.hpp @@ -2,7 +2,6 @@ #define MBGL_MAP_ANNOTATIONS #include -#include #include #include #include @@ -30,7 +29,7 @@ class AnnotationManager : private util::noncopyable { void setDefaultPointAnnotationSymbol(const std::string& symbol); std::pair, AnnotationIDs> addPointAnnotations( - const std::vector&, const MapData&); + const std::vector&, const std::vector& symbols, const MapData&); std::vector removeAnnotations(const AnnotationIDs&, const MapData&); AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const MapData&) const; LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 70194152d92..47c9472d59e 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -235,12 +235,12 @@ double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) { return context->invokeSync(&MapContext::getTopOffsetPixelsForAnnotationSymbol, symbol); } -uint32_t Map::addPointAnnotation(const PointAnnotation& annotation) { - return addPointAnnotations({ annotation }).front(); +uint32_t Map::addPointAnnotation(const LatLng& point, const std::string& symbol) { + return addPointAnnotations({ point }, { symbol }).front(); } -std::vector Map::addPointAnnotations(const std::vector& annotations) { - auto result = data->annotationManager.addPointAnnotations(annotations, *data); +std::vector Map::addPointAnnotations(const std::vector& points, const std::vector& symbols) { + auto result = data->annotationManager.addPointAnnotations(points, symbols, *data); context->invoke(&MapContext::updateAnnotationTiles, result.first); return result.second; }