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

[core] Annotations refactor #2420

Merged
merged 9 commits into from
Sep 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/test/fixtures/api/1.png
/test/fixtures/api/2.png
/test/fixtures/database/*.db
/test/output
/include/mbgl/shader/shaders.hpp
/src/shader/shaders_gl.cpp
/src/shader/shaders_gles2.cpp
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/map/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class Update : uint32_t {
Zoom = 1 << 4,
RenderStill = 1 << 5,
Repaint = 1 << 6,
Annotations = 1 << 7,
};

inline Update operator| (const Update& lhs, const Update& rhs) {
Expand Down

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef MBGL_MAP_ANNOTATIONS
#define MBGL_MAP_ANNOTATIONS

#include <mbgl/map/map.hpp>
#include <mbgl/map/geometry_tile.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geojsonvt/geojsonvt.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/vec.hpp>

#include <string>
#include <vector>
#include <memory>
#include <unordered_map>
#include <unordered_set>

namespace mbgl {

class Annotation;
class PointAnnotation;
class ShapeAnnotation;
class LiveTile;
class Style;

using GeoJSONVT = mapbox::util::geojsonvt::GeoJSONVT;

class AnnotationManager : private util::noncopyable {
public:
AnnotationManager();
~AnnotationManager();

void setDefaultPointAnnotationSymbol(const std::string& symbol);

AnnotationIDs addPointAnnotations(const std::vector<PointAnnotation>&, const uint8_t maxZoom);
AnnotationIDs addShapeAnnotations(const std::vector<ShapeAnnotation>&, const uint8_t maxZoom);
void removeAnnotations(const AnnotationIDs&, const uint8_t maxZoom);

AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const uint8_t maxZoom, const AnnotationType& = AnnotationType::Any) const;
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;

void updateStyle(Style&);
const LiveTile* getTile(const TileID& id);

static const std::string PointSourceID;
static const std::string ShapeSourceID;

private:
inline uint32_t nextID();
static vec2<double> projectPoint(const LatLng& point);

uint32_t addShapeAnnotation(const ShapeAnnotation&, const uint8_t maxZoom);
uint32_t addPointAnnotation(const PointAnnotation&, const uint8_t maxZoom);

std::string defaultPointAnnotationSymbol;
std::unordered_map<uint32_t, std::unique_ptr<Annotation>> annotations;
std::vector<uint32_t> orderedShapeAnnotations;
std::unordered_map<TileID, std::pair<std::unordered_set<uint32_t>, std::unique_ptr<LiveTile>>, TileID::Hash> tiles;
std::unordered_map<uint32_t, std::unique_ptr<GeoJSONVT>> shapeTilers;
std::unordered_set<TileID, TileID::Hash> stalePointTileIDs;
uint32_t nextID_ = 0;
};

}

#endif
117 changes: 0 additions & 117 deletions src/mbgl/map/annotation.hpp

This file was deleted.

20 changes: 17 additions & 3 deletions src/mbgl/map/live_tile_data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <mbgl/map/annotation.hpp>
#include <mbgl/map/live_tile_data.hpp>
#include <mbgl/map/live_tile.hpp>
#include <mbgl/style/style_layer.hpp>
Expand All @@ -13,7 +12,7 @@
using namespace mbgl;

LiveTileData::LiveTileData(const TileID& id_,
const LiveTile* tile,
const LiveTile* tile_,
Style& style_,
const SourceInfo& source_,
std::function<void()> callback)
Expand All @@ -25,15 +24,28 @@ LiveTileData::LiveTileData(const TileID& id_,
style_,
style_.layers,
state,
std::make_unique<CollisionTile>(0, 0, false)) {
std::make_unique<CollisionTile>(0, 0, false)),
tile(tile_) {
state = State::loaded;

if (!tile) {
state = State::parsed;
return;
}

reparse(callback);
}

bool LiveTileData::reparse(std::function<void()> callback) {
if (parsing || (state != State::loaded && state != State::partial)) {
return false;
}

parsing = true;

workRequest = worker.parseLiveTile(tileWorker, *tile, [this, callback] (TileParseResult result) {
parsing = false;

if (result.is<State>()) {
state = result.get<State>();
} else {
Expand All @@ -43,6 +55,8 @@ LiveTileData::LiveTileData(const TileID& id_,

callback();
});

return true;
}

LiveTileData::~LiveTileData() {
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/map/live_tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ class LiveTileData : public TileData {
std::function<void ()> callback);
~LiveTileData();

bool reparse(std::function<void ()> callback) override;

void cancel() override;
Bucket* getBucket(const StyleLayer&) override;

private:
Worker& worker;
TileWorker tileWorker;
std::unique_ptr<WorkRequest> workRequest;
bool parsing = false;
const LiveTile* tile;
};

}
Expand Down
12 changes: 6 additions & 6 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ uint32_t Map::addPointAnnotation(const PointAnnotation& annotation) {

AnnotationIDs Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) {
auto result = data->getAnnotationManager()->addPointAnnotations(annotations, getMaxZoom());
context->invoke(&MapContext::updateAnnotationTiles, result.first);
return result.second;
update(Update::Annotations);
return result;
}

uint32_t Map::addShapeAnnotation(const ShapeAnnotation& annotation) {
Expand All @@ -358,17 +358,17 @@ uint32_t Map::addShapeAnnotation(const ShapeAnnotation& annotation) {

AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) {
auto result = data->getAnnotationManager()->addShapeAnnotations(annotations, getMaxZoom());
context->invoke(&MapContext::updateAnnotationTiles, result.first);
return result.second;
update(Update::Annotations);
return result;
}

void Map::removeAnnotation(uint32_t annotation) {
removeAnnotations({ annotation });
}

void Map::removeAnnotations(const std::vector<uint32_t>& annotations) {
auto result = data->getAnnotationManager()->removeAnnotations(annotations, getMaxZoom());
context->invoke(&MapContext::updateAnnotationTiles, result);
data->getAnnotationManager()->removeAnnotations(annotations, getMaxZoom());
update(Update::Annotations);
}

std::vector<uint32_t> Map::getAnnotationsInBounds(const LatLngBounds& bounds, const AnnotationType& type) {
Expand Down
Loading