void MapContext::setStyleURL(const std::string& url) { FileSource* fs = util::ThreadContext::getFileSource(); if (styleRequest) { fs->cancel(styleRequest); } styleURL = url; styleJSON.clear(); style = std::make_unique<Style>(data, asyncUpdate->get()->loop); const size_t pos = styleURL.rfind('/'); std::string base = ""; if (pos != std::string::npos) { base = styleURL.substr(0, pos + 1); } styleRequest = fs->request({ Resource::Kind::Style, styleURL }, util::RunLoop::getLoop(), [this, base](const Response &res) { styleRequest = nullptr; 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; style = std::make_unique<Style>(data, asyncUpdate->get()->loop); loadStyleJSON(json, base); }
void MapContext::setStyleJSON(const std::string& json, const std::string& base) { if (styleJSON == json) { return; } styleURL.clear(); styleJSON = json; style = std::make_unique<Style>(data); loadStyleJSON(json, base); }
void MapContext::setStyleJSON(const std::string& json, const std::string& base) { if (styleJSON == json) { return; } styleURL.clear(); styleJSON = json; style = std::make_unique<Style>(data); if (painter) { painter->updateRenderOrder(*style); } loadStyleJSON(json, base); }
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::setStyleURL(const std::string& url) { if (styleURL == url) { return; } styleRequest = nullptr; styleURL = url; styleJSON.clear(); style = std::make_unique<Style>(data); if (painter) { painter->updateRenderOrder(*style); } const size_t pos = styleURL.rfind('/'); std::string base = ""; if (pos != std::string::npos) { base = styleURL.substr(0, pos + 1); } FileSource* fs = util::ThreadContext::getFileSource(); styleRequest = fs->request({ Resource::Kind::Style, styleURL }, util::RunLoop::getLoop(), [this, base](const Response &res) { if (res.stale) { // Only handle fresh responses. return; } styleRequest = nullptr; if (res.error) { if (res.error->reason == Response::Error::Reason::NotFound && styleURL.find("mapbox://") == 0) { Log::Error(Event::Setup, "style %s could not be found or is an incompatible legacy map or style", styleURL.c_str()); } else { Log::Error(Event::Setup, "loading style failed: %s", res.error->message.c_str()); data.loading = false; } } else { loadStyleJSON(*res.data, base); } }); }
void MapContext::setStyleJSON(const std::string& json, const std::string& base) { styleURL.clear(); styleJSON = json; loadStyleJSON(json, base); }