summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-04-23 14:25:07 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-28 14:32:25 -0400
commitf0b229730f401972624da3ec2a3b394b7f31d533 (patch)
treef18d4068242337a21baab87a87f57ddc1eb1d979 /src
parentb5b58086a8f27c4c1cc34274aa51a857ba8c16a8 (diff)
downloadqtlocation-mapboxgl-f0b229730f401972624da3ec2a3b394b7f31d533.tar.gz
Move style info to MapContext
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp28
-rw-r--r--src/mbgl/map/map_context.cpp58
-rw-r--r--src/mbgl/map/map_context.hpp11
-rw-r--r--src/mbgl/map/map_data.hpp16
4 files changed, 42 insertions, 71 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index aefabc8f77..35b5f982d3 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -95,36 +95,22 @@ void Map::update(Update update_) {
context->invoke(&MapContext::triggerUpdate, update_);
}
-#pragma mark - Setup
-
-std::string Map::getStyleURL() const {
- return data->getStyleInfo().url;
-}
+#pragma mark - Style
void Map::setStyleURL(const std::string &url) {
- assert(Environment::currentlyOn(ThreadType::Main));
-
- const std::string styleURL = mbgl::util::mapbox::normalizeStyleURL(url, getAccessToken());
-
- const size_t pos = styleURL.rfind('/');
- std::string base = "";
- if (pos != std::string::npos) {
- base = styleURL.substr(0, pos + 1);
- }
-
- data->setStyleInfo({ styleURL, base, "" });
- update(Update::StyleInfo);
+ context->invoke(&MapContext::setStyleURL, url);
}
void Map::setStyleJSON(const std::string& json, const std::string& base) {
- assert(Environment::currentlyOn(ThreadType::Main));
+ context->invoke(&MapContext::setStyleJSON, json, base);
+}
- data->setStyleInfo({ "", base, json });
- update(Update::StyleInfo);
+std::string Map::getStyleURL() const {
+ return context->invokeSync<std::string>(&MapContext::getStyleURL);
}
std::string Map::getStyleJSON() const {
- return data->getStyleInfo().json;
+ return context->invokeSync<std::string>(&MapContext::getStyleJSON);
}
#pragma mark - Size
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index 13fdd085f9..86a3ec7b4e 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -95,6 +95,32 @@ void MapContext::triggerUpdate(const Update u) {
asyncUpdate->send();
}
+void MapContext::setStyleURL(const std::string& url) {
+ styleURL = mbgl::util::mapbox::normalizeStyleURL(url, data.getAccessToken());
+ styleJSON.clear();
+
+ const size_t pos = styleURL.rfind('/');
+ std::string base = "";
+ if (pos != std::string::npos) {
+ base = styleURL.substr(0, pos + 1);
+ }
+
+ env.request({ Resource::Kind::JSON, styleURL }, [this, base](const Response &res) {
+ if (res.status == Response::Successful) {
+ loadStyleJSON(res.data, base);
+ } else {
+ Log::Error(Event::Setup, "loading style failed: %s", res.message.c_str());
+ }
+ });
+}
+
+void MapContext::setStyleJSON(const std::string& json, const std::string& base) {
+ styleURL.clear();
+ styleJSON = json;
+
+ loadStyleJSON(json, base);
+}
+
Worker& MapContext::getWorker() {
assert(workers);
return *workers;
@@ -114,27 +140,6 @@ util::ptr<Sprite> MapContext::getSprite() {
return sprite;
}
-void MapContext::reloadStyle() {
- assert(Environment::currentlyOn(ThreadType::Map));
-
- const auto styleInfo = data.getStyleInfo();
-
- if (!styleInfo.url.empty()) {
- const auto base = styleInfo.base;
- // We have a style URL
- env.request({ Resource::Kind::JSON, styleInfo.url }, [this, base](const Response &res) {
- if (res.status == Response::Successful) {
- loadStyleJSON(res.data, base);
- } else {
- Log::Error(Event::Setup, "loading style failed: %s", res.message.c_str());
- }
- });
- } else if (!styleInfo.json.empty()) {
- // We got JSON data directly.
- loadStyleJSON(styleInfo.json, styleInfo.base);
- }
-}
-
void MapContext::loadStyleJSON(const std::string& json, const std::string& base) {
assert(Environment::currentlyOn(ThreadType::Map));
@@ -190,16 +195,8 @@ void MapContext::update() {
auto u = updated.exchange(static_cast<UpdateType>(Update::Nothing)) |
data.transform.updateTransitions(now);
- if (!style) {
- u |= static_cast<UpdateType>(Update::StyleInfo);
- }
-
transformState = data.transform.currentState();
- if (u & static_cast<UpdateType>(Update::StyleInfo)) {
- reloadStyle();
- }
-
if (u & static_cast<UpdateType>(Update::Debug)) {
assert(painter);
painter->setDebug(data.getDebug());
@@ -214,8 +211,7 @@ void MapContext::update() {
style->cascade(data.getClasses());
}
- if (u & static_cast<UpdateType>(Update::StyleInfo) ||
- u & static_cast<UpdateType>(Update::Classes) ||
+ if (u & static_cast<UpdateType>(Update::Classes) ||
u & static_cast<UpdateType>(Update::Zoom)) {
style->recalculate(transformState.getNormalizedZoom(), now);
}
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index c56dabf707..4b2d726523 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -48,6 +48,11 @@ public:
// Notifies the Map thread that the state has changed and an update might be necessary.
void triggerUpdate(Update = Update::Nothing);
+ void setStyleURL(const std::string&);
+ void setStyleJSON(const std::string& json, const std::string& base);
+ std::string getStyleURL() const { return styleURL; }
+ std::string getStyleJSON() const { return styleJSON; }
+
double getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol);
void updateAnnotationTiles(const std::vector<TileID>&);
@@ -62,9 +67,6 @@ private:
// Update the state indicated by the accumulated Update flags, then render.
void update();
- // Loads the style set in the data object. Called by Update::StyleInfo
- void reloadStyle();
-
// Loads the actual JSON object an creates a new Style object.
void loadStyleJSON(const std::string& json, const std::string& base);
@@ -88,6 +90,9 @@ private:
util::ptr<Sprite> sprite;
util::ptr<Style> style;
+ std::string styleURL;
+ std::string styleJSON;
+
size_t sourceCacheSize;
TransformState transformState;
};
diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp
index 248614edf4..6642299126 100644
--- a/src/mbgl/map/map_data.hpp
+++ b/src/mbgl/map/map_data.hpp
@@ -20,12 +20,6 @@ namespace mbgl {
class StillImage;
-struct StyleInfo {
- std::string url;
- std::string base;
- std::string json;
-};
-
class MapData {
using Lock = std::lock_guard<std::mutex>;
@@ -35,15 +29,6 @@ public:
setDefaultTransitionDuration(Duration::zero());
}
- inline StyleInfo getStyleInfo() const {
- Lock lock(mtx);
- return styleInfo;
- }
- inline void setStyleInfo(StyleInfo&& info) {
- Lock lock(mtx);
- styleInfo = info;
- }
-
inline std::string getAccessToken() const {
Lock lock(mtx);
return accessToken;
@@ -105,7 +90,6 @@ public:
private:
mutable std::mutex mtx;
- StyleInfo styleInfo;
std::string accessToken;
std::vector<std::string> classes;
std::atomic<uint8_t> debug { false };