summaryrefslogtreecommitdiff
path: root/include/mbgl/map/annotation.hpp
blob: e88d98b5c623fdf10183353868128ba904acf1ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef MBGL_MAP_ANNOTATIONS
#define MBGL_MAP_ANNOTATIONS

#include <mbgl/map/tile.hpp>
#include <mbgl/map/live_tile.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/vec.hpp>

#include <string>
#include <vector>
#include <map>
#include <mutex>
#include <memory>

namespace mbgl {

class Annotation;
class Map;

typedef std::vector<LatLng> AnnotationSegment;

enum class AnnotationType : uint8_t {
    Point,
    Shape
};

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

    void setDefaultPointAnnotationSymbol(std::string& symbol) { defaultPointAnnotationSymbol = symbol; }
    std::pair<std::vector<Tile::ID>, std::vector<uint32_t>> addPointAnnotations(std::vector<LatLng>, std::vector<std::string>& symbols, const Map&);
    std::vector<Tile::ID> removeAnnotations(std::vector<uint32_t>);
    std::vector<uint32_t> getAnnotationsInBounds(LatLngBounds, const Map&) const;
    LatLngBounds getBoundsForAnnotations(std::vector<uint32_t>) const;

    const std::unique_ptr<LiveTile>& getTile(Tile::ID const& id);

private:
    uint32_t nextID() { return nextID_++; }
    static vec2<double> projectPoint(LatLng& point);

private:
    std::mutex mtx;
    std::string defaultPointAnnotationSymbol;
    std::map<uint32_t, std::unique_ptr<Annotation>> annotations;
    std::map<Tile::ID, std::pair<std::vector<uint32_t>, std::unique_ptr<LiveTile>>> annotationTiles;
    std::unique_ptr<LiveTile> nullTile;
    uint32_t nextID_ = 0;
};

class Annotation : private util::noncopyable {
    friend class AnnotationManager;
public:
    Annotation(AnnotationType, std::vector<AnnotationSegment>);

private:
    LatLng getPoint() const;
    LatLngBounds getBounds() const { return bounds; }

private:
    const AnnotationType type = AnnotationType::Point;
    const std::vector<AnnotationSegment> geometry;
    std::map<Tile::ID, std::vector<std::weak_ptr<const LiveTileFeature>>> tileFeatures;
    LatLngBounds bounds;
};

}

#endif