diff --git a/bin/style.js b/bin/style.js index 5a10a57a2..c5d98180f 100644 --- a/bin/style.js +++ b/bin/style.js @@ -2,6 +2,7 @@ module.exports = { "version": 3, + "sprite": "http://mapbox-kkaefer.s3.amazonaws.com/static/outdoors-gl/sprite", "constants": { "@land": "#eee", "@water": "#999", diff --git a/config/constants.cpp b/config/constants.cpp index ab0c160a8..5be91a9fa 100644 --- a/config/constants.cpp +++ b/config/constants.cpp @@ -1,7 +1,5 @@ #include -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; diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index ec1be163f..fca18a7c9 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -50,6 +50,7 @@ public: std::shared_ptr layers; std::shared_ptr background; std::vector appliedClasses; + std::string sprite_url; private: void updateSources(); diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp index abf047fc1..c0570eae7 100644 --- a/include/llmr/style/style_parser.hpp +++ b/include/llmr/style/style_parser.hpp @@ -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 &layer); void parseBucket(JSVal value, std::shared_ptr &layer); void parseRender(JSVal value, std::shared_ptr &layer); + void parseSprite(JSVal value); // Parses optional properties into a render bucket. template @@ -86,6 +91,9 @@ private: // Store a stack of layers we're parsing right now. This is to prevent reference cycles. std::forward_list stack; + + // Base URL of the sprite image. + std::string sprite; }; } diff --git a/include/llmr/util/constants.hpp b/include/llmr/util/constants.hpp index e3a7b206e..49f7a5f4b 100644 --- a/include/llmr/util/constants.hpp +++ b/include/llmr/util/constants.hpp @@ -7,8 +7,6 @@ namespace llmr { -extern const char *kSpriteURL; -extern const char *kVectorTileURL; extern const char *kGlyphURL; namespace util { diff --git a/src/map/map.cpp b/src/map/map.cpp index 6faa637be..703cdf140 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -433,8 +433,9 @@ void Map::prepare() { if (pixelRatioChanged) { style->sprite = std::make_shared(*this, state.getPixelRatio()); - style->sprite->load(kSpriteURL); - + if (style->sprite_url.size()) { + style->sprite->load(style->sprite_url); + } spriteAtlas->resize(state.getPixelRatio()); } diff --git a/src/style/style.cpp b/src/style/style.cpp index 2fc9ef001..8a23273f0 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -102,6 +102,7 @@ void Style::loadJSON(const uint8_t *const data) { parser.parse(const_cast(doc)); layers = parser.getLayers(); + sprite_url = parser.getSprite(); updateClasses(); } diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index c2f1ab5ec..a9d5c9698 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -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 &layer) { } } +void StyleParser::parseSprite(JSVal value) { + if (value.IsString()) { + sprite = { value.GetString(), value.GetStringLength() }; + } +} + + }