read sprite image from style

This commit is contained in:
Konstantin Käfer
2014-07-02 11:38:36 +02:00
parent 5d92e7c610
commit e93803ac80
8 changed files with 25 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
module.exports = {
"version": 3,
"sprite": "http://mapbox-kkaefer.s3.amazonaws.com/static/outdoors-gl/sprite",
"constants": {
"@land": "#eee",
"@water": "#999",

View File

@@ -1,7 +1,5 @@
#include <llmr/util/constants.hpp>
const char *llmr::kSpriteURL = "http://mapbox-kkaefer.s3.amazonaws.com/static/outdoors-gl/sprite";
const char *llmr::kVectorTileURL = "http://a.tiles.mapbox.com/v3/mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5/%d/%d/%d.vector.pbf";
const char *llmr::kGlyphURL = "http://mapbox.s3.amazonaws.com/gl-glyphs-256/%s/%d-%d.pbf";
const float llmr::util::tileSize = 512.0f;

View File

@@ -50,6 +50,7 @@ public:
std::shared_ptr<StyleLayerGroup> layers;
std::shared_ptr<StyleLayer> background;
std::vector<std::string> appliedClasses;
std::string sprite_url;
private:
void updateSources();

View File

@@ -30,6 +30,10 @@ public:
return root;
}
std::string getSprite() const {
return sprite;
}
private:
void parseConstants(JSVal value);
JSVal replaceConstant(JSVal value);
@@ -46,6 +50,7 @@ private:
void parseReference(JSVal value, std::shared_ptr<StyleLayer> &layer);
void parseBucket(JSVal value, std::shared_ptr<StyleLayer> &layer);
void parseRender(JSVal value, std::shared_ptr<StyleLayer> &layer);
void parseSprite(JSVal value);
// Parses optional properties into a render bucket.
template<typename T>
@@ -86,6 +91,9 @@ private:
// Store a stack of layers we're parsing right now. This is to prevent reference cycles.
std::forward_list<StyleLayer *> stack;
// Base URL of the sprite image.
std::string sprite;
};
}

View File

@@ -7,8 +7,6 @@
namespace llmr {
extern const char *kSpriteURL;
extern const char *kVectorTileURL;
extern const char *kGlyphURL;
namespace util {

View File

@@ -433,8 +433,9 @@ void Map::prepare() {
if (pixelRatioChanged) {
style->sprite = std::make_shared<Sprite>(*this, state.getPixelRatio());
style->sprite->load(kSpriteURL);
if (style->sprite_url.size()) {
style->sprite->load(style->sprite_url);
}
spriteAtlas->resize(state.getPixelRatio());
}

View File

@@ -102,6 +102,7 @@ void Style::loadJSON(const uint8_t *const data) {
parser.parse(const_cast<const rapidjson::Document &>(doc));
layers = parser.getLayers();
sprite_url = parser.getSprite();
updateClasses();
}

View File

@@ -21,6 +21,10 @@ void StyleParser::parse(JSVal document) {
root = createLayers(document["layers"]);
parseLayers();
}
if (document.HasMember("sprite")) {
parseSprite(document["sprite"]);
}
}
void StyleParser::parseConstants(JSVal value) {
@@ -911,4 +915,11 @@ void StyleParser::parseRender(JSVal value, std::shared_ptr<StyleLayer> &layer) {
}
}
void StyleParser::parseSprite(JSVal value) {
if (value.IsString()) {
sprite = { value.GetString(), value.GetStringLength() };
}
}
}