better warning messages

This commit is contained in:
Konstantin Käfer
2014-07-31 18:55:48 +02:00
parent 75c079adb1
commit d01b996acd
4 changed files with 25 additions and 29 deletions

View File

@@ -2085,8 +2085,7 @@ module.exports = {
"filter": { "scalerank": [1, 2] },
"type": "symbol",
"render": {
"icon-image": "{maki}-12",
"icon-size": 12
"icon-image": "{maki}-12"
},
"style.night": {}
}, {
@@ -2123,8 +2122,7 @@ module.exports = {
"filter": { "scalerank": 3 },
"type": "symbol",
"render": {
"icon-image": "{maki}-12",
"icon-size": 12
"icon-image": "{maki}-12"
},
"style": {
"icon-opacity": {
@@ -2176,8 +2174,7 @@ module.exports = {
"filter": { "scalerank": 4 },
"type": "symbol",
"render": {
"icon-image": "{maki}-12",
"icon-size": 12
"icon-image": "{maki}-12"
},
"style": {
"icon-opacity": {
@@ -2229,8 +2226,7 @@ module.exports = {
"filter": { "maki": "airport" },
"type": "symbol",
"render": {
"icon-image": "{maki}-12",
"icon-size": 12
"icon-image": "{maki}-12"
},
"style": {
"icon-opacity": {

View File

@@ -46,9 +46,13 @@ public:
operator bool() const;
private:
const bool valid;
public:
const float pixelRatio;
const std::string url;
const std::string spriteURL;
const std::string jsonURL;
std::unique_ptr<util::Image> raster;
private:

View File

@@ -185,6 +185,7 @@ void Map::setup() {
void Map::setStyleJSON(std::string newStyleJSON) {
styleJSON.swap(newStyleJSON);
sprite.reset();
style->loadJSON((const uint8_t *)styleJSON.c_str());
update();
}
@@ -202,9 +203,9 @@ std::string Map::getAccessToken() const {
}
std::shared_ptr<Sprite> Map::getSprite() {
float pixelRatio = state.getPixelRatio();
const float pixelRatio = state.getPixelRatio();
const std::string &sprite_url = style->getSpriteURL();
if (!sprite || sprite->pixelRatio != pixelRatio || sprite->url != sprite_url) {
if (!sprite || sprite->pixelRatio != pixelRatio) {
sprite = Sprite::Create(sprite_url, pixelRatio);
}
@@ -531,11 +532,8 @@ void Map::prepare() {
updateSources();
style->updateProperties(state.getNormalizedZoom(), animationTime);
if (pixelRatioChanged) {
spriteAtlas->resize(state.getPixelRatio());
}
// Allow the sprite atlas to potentially pull new sprite images if needed.
spriteAtlas->resize(state.getPixelRatio());
spriteAtlas->update(*getSprite());
updateTiles();

View File

@@ -27,8 +27,10 @@ std::shared_ptr<Sprite> Sprite::Create(const std::string& base_url, float pixelR
}
Sprite::Sprite(const Key &, const std::string& base_url, float pixelRatio)
: pixelRatio(pixelRatio),
url(base_url),
: valid(base_url.length() > 0),
pixelRatio(pixelRatio),
spriteURL(base_url + (pixelRatio > 1 ? "@2x" : "") + ".png"),
jsonURL(base_url + (pixelRatio > 1 ? "@2x" : "") + ".json"),
raster(),
loadedImage(false),
loadedJSON(false),
@@ -40,7 +42,7 @@ void Sprite::waitUntilLoaded() const {
}
Sprite::operator bool() const {
return isLoaded() && !pos.empty();
return valid && isLoaded() && !pos.empty();
}
@@ -48,8 +50,8 @@ Sprite::operator bool() const {
// The reason this isn't part of the constructor is that calling shared_from_this() in
// the constructor fails.
void Sprite::load() {
if (url.length() == 0) {
// Treat a non-existent sprite as an empty sprite.
if (!valid) {
// Treat a non-existent sprite as a successfully loaded empty sprite.
loadedImage = true;
loadedJSON = true;
promise.set_value();
@@ -58,28 +60,24 @@ void Sprite::load() {
std::shared_ptr<Sprite> sprite = shared_from_this();
const std::string suffix = (pixelRatio > 1 ? "@2x" : "");
platform::request_http(url + suffix + ".json", [sprite](platform::Response *res) {
platform::request_http(jsonURL, [sprite](platform::Response *res) {
if (res->code == 200) {
sprite->body.swap(res->body);
sprite->parseJSON();
sprite->complete();
} else {
fprintf(stderr, "failed to load sprite info\n");
fprintf(stderr, "error %d: %s\n", res->code, res->error_message.c_str());
Log::Warning(Event::Sprite, "Failed to load sprite info: Error %d: %s", res->code, res->error_message.c_str());
sprite->promise.set_exception(std::make_exception_ptr(std::runtime_error(res->error_message)));
}
});
platform::request_http(url + suffix + ".png", [sprite](platform::Response *res) {
platform::request_http(spriteURL, [sprite](platform::Response *res) {
if (res->code == 200) {
sprite->image.swap(res->body);
sprite->parseImage();
sprite->complete();
} else {
fprintf(stderr, "failed to load sprite image\n");
fprintf(stderr, "error %d: %s\n", res->code, res->error_message.c_str());
Log::Warning(Event::Sprite, "Failed to load sprite image: Error %d: %s", res->code, res->error_message.c_str());
sprite->promise.set_exception(std::make_exception_ptr(std::runtime_error(res->error_message)));
}
});
@@ -87,7 +85,7 @@ void Sprite::load() {
void Sprite::complete() {
if (loadedImage && loadedJSON) {
Log::Info(Event::Sprite, "loaded %s", url.c_str());
Log::Info(Event::Sprite, "loaded %s", spriteURL.c_str());
promise.set_value();
}
}