summaryrefslogtreecommitdiff
path: root/src/mbgl/annotation/shape_annotation_impl.hpp
blob: caf2cff1a5c71d7d3752d67d31e846fa53cfc6a2 (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
#pragma once

#include <mbgl/util/string.hpp>
#include <mapbox/geojsonvt.hpp>

#include <mbgl/annotation/annotation.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/style/style.hpp>

#include <string>
#include <memory>

namespace mbgl {

class AnnotationTileData;
class CanonicalTileID;

class ShapeAnnotationImpl {
public:
    ShapeAnnotationImpl(const AnnotationID, const uint8_t maxZoom);
    virtual ~ShapeAnnotationImpl() = default;

    virtual void updateStyle(style::Style::Impl&) const = 0;
    virtual const ShapeAnnotationGeometry& geometry() const = 0;

    void updateTileData(const CanonicalTileID&, AnnotationTileData&);

    const AnnotationID id;
    const uint8_t maxZoom;
    const std::string layerID;
    std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> shapeTiler;
};

struct CloseShapeAnnotation {
    ShapeAnnotationGeometry operator()(const mbgl::LineString<double> &geom) const {
        return geom;
    }
    ShapeAnnotationGeometry operator()(const mbgl::MultiLineString<double> &geom) const {
        return geom;
    }
    ShapeAnnotationGeometry operator()(const mbgl::Polygon<double> &geom) const {
        mbgl::Polygon<double> closed = geom;
        for (auto &ring : closed) {
            if (!ring.empty() && ring.front() != ring.back()) {
                ring.emplace_back(ring.front());
            }
        }
        return closed;
    }
    ShapeAnnotationGeometry operator()(const mbgl::MultiPolygon<double> &geom) const {
        mbgl::MultiPolygon<double> closed = geom;
        for (auto &polygon : closed) {
            for (auto &ring : polygon) {
                if (!ring.empty() && ring.front() != ring.back()) {
                    ring.emplace_back(ring.front());
                }
            }
        }
        return closed;
    }
};

} // namespace mbgl