summaryrefslogtreecommitdiff
path: root/src/mbgl/map/live_tile.cpp
blob: f7a70f7d46ad1b495963b8560256fd943ebe94a4 (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
#include <mbgl/map/live_tile.hpp>
#include <mbgl/util/constants.hpp>

namespace mbgl {

LiveTileFeature::LiveTileFeature(FeatureType type_, GeometryCollection geometries_,
                                 std::unordered_map<std::string, std::string> properties_)
    : type(type_),
      properties(properties_),
      geometries(geometries_) {}

mapbox::util::optional<Value> LiveTileFeature::getValue(const std::string& key) const {
    auto it = properties.find(key);
    if (it != properties.end()) {
        return mapbox::util::optional<Value>(it->second);
    }
    return mapbox::util::optional<Value>();
}

LiveTileLayer::LiveTileLayer() {}

void LiveTileLayer::prepareToAddFeatures(size_t count) {
    features.reserve(features.size() + count);
}

void LiveTileLayer::addFeature(util::ptr<const LiveTileFeature> feature) {
    features.push_back(std::move(feature));
}

void LiveTileLayer::removeFeature(util::ptr<const LiveTileFeature> feature) {
    for (auto it = features.begin(); it != features.end(); ++it) {
        if (feature == *it) {
            features.erase(it);
            return;
        }
    }
}

LiveTile::LiveTile() {}

void LiveTile::addLayer(const std::string& name, util::ptr<LiveTileLayer> layer) {
    layers.emplace(name, std::move(layer));
}

void LiveTile::removeLayer(const std::string& name) {
    layers.erase(name);
}

util::ptr<GeometryTileLayer> LiveTile::getLayer(const std::string& name) const {
    return getMutableLayer(name);
}

util::ptr<LiveTileLayer> LiveTile::getMutableLayer(const std::string& name) const {
    auto layer_it = layers.find(name);
    if (layer_it != layers.end()) {
        return layer_it->second;
    }
    return nullptr;
}

}