Revert "use array of structs rather than parallel arrays for annotations"

This reverts commit 2435c1ad26 (#1710), which needs to be revisited in light of #1655, which is a much higher priority at the moment.
This commit is contained in:
Minh Nguyễn
2015-06-15 15:58:22 -07:00
parent a08bcb6d0e
commit 714b68f7b3
7 changed files with 28 additions and 45 deletions

View File

@@ -1,22 +0,0 @@
#ifndef MBGL_ANNOTATION_POINT_ANNOTATION
#define MBGL_ANNOTATION_POINT_ANNOTATION
#include <mbgl/util/geo.hpp>
#include <string>
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

View File

@@ -21,7 +21,6 @@ class View;
class MapData;
class MapContext;
class StillImage;
class PointAnnotation;
namespace util {
template <class T> class Thread;
@@ -112,8 +111,9 @@ public:
// Annotations
void setDefaultPointAnnotationSymbol(const std::string&);
double getTopOffsetPixelsForAnnotationSymbol(const std::string&);
uint32_t addPointAnnotation(const PointAnnotation&);
std::vector<uint32_t> addPointAnnotations(const std::vector<PointAnnotation>&);
uint32_t addPointAnnotation(const LatLng&, const std::string& symbol);
std::vector<uint32_t> addPointAnnotations(const std::vector<LatLng>&,
const std::vector<std::string>& symbols);
void removeAnnotation(uint32_t);
void removeAnnotations(const std::vector<uint32_t>&);
std::vector<uint32_t> getAnnotationsInBounds(const LatLngBounds&);

View File

@@ -1,4 +1,3 @@
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/platform/log.hpp>
@@ -131,7 +130,8 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
}
void GLFWView::addRandomPointAnnotations(int count) {
std::vector<mbgl::PointAnnotation> points;
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) });
@@ -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) {

View File

@@ -8,7 +8,6 @@
#import <OpenGLES/EAGL.h>
#include <mbgl/mbgl.hpp>
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/darwin/reachability.h>
#include <mbgl/storage/default_file_source.hpp>
@@ -1670,8 +1669,11 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
{
if ( ! annotations) return;
std::vector<mbgl::PointAnnotation> points;
points.reserve(annotations.count);
std::vector<mbgl::LatLng> latLngs;
latLngs.reserve(annotations.count);
std::vector<std::string> symbols;
symbols.reserve(annotations.count);
BOOL delegateImplementsSymbolLookup = [self.delegate respondsToSelector:@selector(mapView:symbolNameForAnnotation:)];
@@ -1679,6 +1681,8 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
{
assert([annotation conformsToProtocol:@protocol(MGLAnnotation)]);
latLngs.push_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate));
NSString *symbolName = nil;
if (delegateImplementsSymbolLookup)
@@ -1686,10 +1690,10 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
symbolName = [self.delegate mapView:self symbolNameForAnnotation:annotation];
}
points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), (symbolName ? [symbolName UTF8String] : ""));
symbols.push_back((symbolName ? [symbolName UTF8String] : ""));
}
std::vector<uint32_t> annotationIDs = _mbglMap->addPointAnnotations(points);
std::vector<uint32_t> annotationIDs = _mbglMap->addPointAnnotations(latLngs, symbols);
for (size_t i = 0; i < annotationIDs.size(); ++i)
{

View File

@@ -85,7 +85,8 @@ vec2<double> AnnotationManager::projectPoint(const LatLng& point) {
}
std::pair<std::vector<TileID>, AnnotationIDs>
AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& points,
AnnotationManager::addPointAnnotations(const std::vector<LatLng>& points,
const std::vector<std::string>& symbols,
const MapData& data) {
std::lock_guard<std::mutex> lock(mtx);
@@ -102,14 +103,14 @@ AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& point
std::vector<TileID> 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<Annotation>(AnnotationType::Point,
AnnotationSegments({ { point.position } })));
AnnotationSegments({ { points[i] } })));
const uint8_t maxZoom = data.transform.getMaxZoom();
@@ -117,7 +118,7 @@ AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& point
uint32_t z2 = 1 << maxZoom;
// projection conversion into unit space
const vec2<double> p = projectPoint(point.position);
const vec2<double> 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<PointAnnotation>& point
// at render time we style the annotation according to its {sprite} field
const std::map<std::string, std::string> properties = {
{ "sprite", (point.icon.length() ? point.icon : defaultPointAnnotationSymbol) }
{ "sprite", (symbols[i].length() ? symbols[i] : defaultPointAnnotationSymbol) }
};
auto feature =

View File

@@ -2,7 +2,6 @@
#define MBGL_MAP_ANNOTATIONS
#include <mbgl/map/tile_id.hpp>
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/vec.hpp>
@@ -30,7 +29,7 @@ public:
void setDefaultPointAnnotationSymbol(const std::string& symbol);
std::pair<std::vector<TileID>, AnnotationIDs> addPointAnnotations(
const std::vector<PointAnnotation>&, const MapData&);
const std::vector<LatLng>&, const std::vector<std::string>& symbols, const MapData&);
std::vector<TileID> removeAnnotations(const AnnotationIDs&, const MapData&);
AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const MapData&) const;
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;

View File

@@ -235,12 +235,12 @@ double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
return context->invokeSync<double>(&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<uint32_t> Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) {
auto result = data->annotationManager.addPointAnnotations(annotations, *data);
std::vector<uint32_t> Map::addPointAnnotations(const std::vector<LatLng>& points, const std::vector<std::string>& symbols) {
auto result = data->annotationManager.addPointAnnotations(points, symbols, *data);
context->invoke(&MapContext::updateAnnotationTiles, result.first);
return result.second;
}