Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 714b68f

Browse files
committed
Revert "use array of structs rather than parallel arrays for annotations"
This reverts commit 2435c1a (#1710), which needs to be revisited in light of #1655, which is a much higher priority at the moment.
1 parent a08bcb6 commit 714b68f

7 files changed

Lines changed: 28 additions & 45 deletions

File tree

include/mbgl/annotation/point_annotation.hpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/mbgl/map/map.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class View;
2121
class MapData;
2222
class MapContext;
2323
class StillImage;
24-
class PointAnnotation;
2524

2625
namespace util {
2726
template <class T> class Thread;
@@ -112,8 +111,9 @@ class Map : private util::noncopyable {
112111
// Annotations
113112
void setDefaultPointAnnotationSymbol(const std::string&);
114113
double getTopOffsetPixelsForAnnotationSymbol(const std::string&);
115-
uint32_t addPointAnnotation(const PointAnnotation&);
116-
std::vector<uint32_t> addPointAnnotations(const std::vector<PointAnnotation>&);
114+
uint32_t addPointAnnotation(const LatLng&, const std::string& symbol);
115+
std::vector<uint32_t> addPointAnnotations(const std::vector<LatLng>&,
116+
const std::vector<std::string>& symbols);
117117
void removeAnnotation(uint32_t);
118118
void removeAnnotations(const std::vector<uint32_t>&);
119119
std::vector<uint32_t> getAnnotationsInBounds(const LatLngBounds&);

platform/default/glfw_view.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <mbgl/annotation/point_annotation.hpp>
21
#include <mbgl/platform/default/glfw_view.hpp>
32
#include <mbgl/platform/gl.hpp>
43
#include <mbgl/platform/log.hpp>
@@ -131,7 +130,8 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
131130
}
132131

133132
void GLFWView::addRandomPointAnnotations(int count) {
134-
std::vector<mbgl::PointAnnotation> points;
133+
std::vector<mbgl::LatLng> points;
134+
std::vector<std::string> markers;
135135

136136
const auto sw = map->latLngForPixel({ 0, 0 });
137137
const auto ne = map->latLngForPixel({ double(width), double(height) });
@@ -140,10 +140,11 @@ void GLFWView::addRandomPointAnnotations(int count) {
140140
const double lon = sw.longitude + (ne.longitude - sw.longitude) * (double(std::rand()) / RAND_MAX);
141141
const double lat = sw.latitude + (ne.latitude - sw.latitude) * (double(std::rand()) / RAND_MAX);
142142

143-
points.emplace_back(mbgl::LatLng{ lat, lon }, "default_marker");
143+
points.push_back({ lat, lon });
144+
markers.push_back("default_marker");
144145
}
145146

146-
map->addPointAnnotations(points);
147+
map->addPointAnnotations(points, markers);
147148
}
148149

149150
void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset) {

platform/ios/MGLMapView.mm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#import <OpenGLES/EAGL.h>
99

1010
#include <mbgl/mbgl.hpp>
11-
#include <mbgl/annotation/point_annotation.hpp>
1211
#include <mbgl/platform/platform.hpp>
1312
#include <mbgl/platform/darwin/reachability.h>
1413
#include <mbgl/storage/default_file_source.hpp>
@@ -1670,26 +1669,31 @@ - (void)addAnnotations:(NSArray *)annotations
16701669
{
16711670
if ( ! annotations) return;
16721671

1673-
std::vector<mbgl::PointAnnotation> points;
1674-
points.reserve(annotations.count);
1672+
std::vector<mbgl::LatLng> latLngs;
1673+
latLngs.reserve(annotations.count);
1674+
1675+
std::vector<std::string> symbols;
1676+
symbols.reserve(annotations.count);
16751677

16761678
BOOL delegateImplementsSymbolLookup = [self.delegate respondsToSelector:@selector(mapView:symbolNameForAnnotation:)];
16771679

16781680
for (id <MGLAnnotation> annotation in annotations)
16791681
{
16801682
assert([annotation conformsToProtocol:@protocol(MGLAnnotation)]);
16811683

1684+
latLngs.push_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate));
1685+
16821686
NSString *symbolName = nil;
16831687

16841688
if (delegateImplementsSymbolLookup)
16851689
{
16861690
symbolName = [self.delegate mapView:self symbolNameForAnnotation:annotation];
16871691
}
16881692

1689-
points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), (symbolName ? [symbolName UTF8String] : ""));
1693+
symbols.push_back((symbolName ? [symbolName UTF8String] : ""));
16901694
}
16911695

1692-
std::vector<uint32_t> annotationIDs = _mbglMap->addPointAnnotations(points);
1696+
std::vector<uint32_t> annotationIDs = _mbglMap->addPointAnnotations(latLngs, symbols);
16931697

16941698
for (size_t i = 0; i < annotationIDs.size(); ++i)
16951699
{

src/mbgl/map/annotation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ vec2<double> AnnotationManager::projectPoint(const LatLng& point) {
8585
}
8686

8787
std::pair<std::vector<TileID>, AnnotationIDs>
88-
AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& points,
88+
AnnotationManager::addPointAnnotations(const std::vector<LatLng>& points,
89+
const std::vector<std::string>& symbols,
8990
const MapData& data) {
9091
std::lock_guard<std::mutex> lock(mtx);
9192

@@ -102,22 +103,22 @@ AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& point
102103

103104
std::vector<TileID> affectedTiles;
104105

105-
for (const PointAnnotation& point : points) {
106+
for (size_t i = 0; i < points.size(); ++i) {
106107
const uint32_t annotationID = nextID();
107108

108109
// track the annotation global ID and its geometry
109110
auto anno_it = annotations.emplace(
110111
annotationID,
111112
std::make_unique<Annotation>(AnnotationType::Point,
112-
AnnotationSegments({ { point.position } })));
113+
AnnotationSegments({ { points[i] } })));
113114

114115
const uint8_t maxZoom = data.transform.getMaxZoom();
115116

116117
// side length of map at this zoom
117118
uint32_t z2 = 1 << maxZoom;
118119

119120
// projection conversion into unit space
120-
const vec2<double> p = projectPoint(point.position);
121+
const vec2<double> p = projectPoint(points[i]);
121122

122123
uint32_t x = p.x * z2;
123124
uint32_t y = p.y * z2;
@@ -133,7 +134,7 @@ AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& point
133134

134135
// at render time we style the annotation according to its {sprite} field
135136
const std::map<std::string, std::string> properties = {
136-
{ "sprite", (point.icon.length() ? point.icon : defaultPointAnnotationSymbol) }
137+
{ "sprite", (symbols[i].length() ? symbols[i] : defaultPointAnnotationSymbol) }
137138
};
138139

139140
auto feature =

src/mbgl/map/annotation.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define MBGL_MAP_ANNOTATIONS
33

44
#include <mbgl/map/tile_id.hpp>
5-
#include <mbgl/annotation/point_annotation.hpp>
65
#include <mbgl/util/geo.hpp>
76
#include <mbgl/util/noncopyable.hpp>
87
#include <mbgl/util/vec.hpp>
@@ -30,7 +29,7 @@ class AnnotationManager : private util::noncopyable {
3029

3130
void setDefaultPointAnnotationSymbol(const std::string& symbol);
3231
std::pair<std::vector<TileID>, AnnotationIDs> addPointAnnotations(
33-
const std::vector<PointAnnotation>&, const MapData&);
32+
const std::vector<LatLng>&, const std::vector<std::string>& symbols, const MapData&);
3433
std::vector<TileID> removeAnnotations(const AnnotationIDs&, const MapData&);
3534
AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const MapData&) const;
3635
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;

src/mbgl/map/map.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
235235
return context->invokeSync<double>(&MapContext::getTopOffsetPixelsForAnnotationSymbol, symbol);
236236
}
237237

238-
uint32_t Map::addPointAnnotation(const PointAnnotation& annotation) {
239-
return addPointAnnotations({ annotation }).front();
238+
uint32_t Map::addPointAnnotation(const LatLng& point, const std::string& symbol) {
239+
return addPointAnnotations({ point }, { symbol }).front();
240240
}
241241

242-
std::vector<uint32_t> Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) {
243-
auto result = data->annotationManager.addPointAnnotations(annotations, *data);
242+
std::vector<uint32_t> Map::addPointAnnotations(const std::vector<LatLng>& points, const std::vector<std::string>& symbols) {
243+
auto result = data->annotationManager.addPointAnnotations(points, symbols, *data);
244244
context->invoke(&MapContext::updateAnnotationTiles, result.first);
245245
return result.second;
246246
}

0 commit comments

Comments
 (0)