blob: 087e28b2bb5981ca26067481fb55dbb312bbbc74 (
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
|
#include <mbgl/renderer/source_state.hpp>
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/util/logging.hpp>
namespace mbgl {
void SourceFeatureState::updateState(const optional<std::string>& sourceLayerID, const std::string& featureID, const FeatureState& newState) {
std::string sourceLayer = sourceLayerID.value_or(std::string());
for (const auto& state : newState) {
auto& layerStates = stateChanges[sourceLayer];
auto& featureStates = layerStates[featureID];
featureStates[state.first] = state.second;
}
}
void SourceFeatureState::getState(FeatureState& result, const optional<std::string>& sourceLayerID, const std::string& featureID) const {
std::string sourceLayer = sourceLayerID.value_or(std::string());
FeatureState current, changes;
auto layerStates = currentStates.find(sourceLayer);
if (layerStates != currentStates.end()) {
const auto currentStateEntry = layerStates->second.find(featureID);
if (currentStateEntry != layerStates->second.end()) {
current = currentStateEntry->second;
}
}
layerStates = stateChanges.find(sourceLayer);
if (layerStates != stateChanges.end()) {
const auto stateChangesEntry = layerStates->second.find(featureID);
if (stateChangesEntry != layerStates->second.end()) {
changes = stateChangesEntry->second;
}
}
result = std::move(changes);
result.insert(current.begin(), current.end());
}
void SourceFeatureState::coalesceChanges(std::vector<RenderTile>& tiles) {
LayerFeatureStates changes;
for (const auto& layerStatesEntry : stateChanges) {
const auto& sourceLayer = layerStatesEntry.first;
FeatureStates layerStates;
for (const auto& featureStatesEntry : stateChanges[sourceLayer]) {
const auto& featureID = featureStatesEntry.first;
for (const auto& stateEntry : stateChanges[sourceLayer][featureID]) {
const auto& stateKey = stateEntry.first;
const auto& stateVal = stateEntry.second;
auto currentState = currentStates[sourceLayer][featureID].find(stateKey);
if (currentState != currentStates[sourceLayer][featureID].end()) {
currentState->second = stateVal;
} else {
currentStates[sourceLayer][featureID].insert(std::make_pair(stateKey, stateVal));
}
}
layerStates[featureID] = currentStates[sourceLayer][featureID];
}
changes[sourceLayer] = std::move(layerStates);
}
stateChanges.clear();
if (changes.empty()) return;
for (auto& tile : tiles) {
tile.setFeatureState(changes);
}
}
} // namespace mbgl
|