From af87fb6c264e232a6945f7f6304989a459501720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 2 Jul 2014 12:10:09 +0200 Subject: [PATCH] load glyphset url from stylesheet --- bin/style.js | 2 +- config/constants.cpp | 2 -- include/llmr/map/source.hpp | 3 +-- include/llmr/style/style.hpp | 1 + include/llmr/style/style_parser.hpp | 8 ++++++++ include/llmr/text/glyph_store.hpp | 7 ++++++- include/llmr/util/constants.hpp | 2 -- src/map/map.cpp | 11 ++++++++++- src/map/source.cpp | 3 +-- src/map/tile_parser.cpp | 6 ++++++ src/style/style.cpp | 1 + src/style/style_parser.cpp | 14 +++++++++++--- src/text/glyph_store.cpp | 16 ++++++++++++---- 13 files changed, 58 insertions(+), 18 deletions(-) diff --git a/bin/style.js b/bin/style.js index c5d98180f..b3e692904 100644 --- a/bin/style.js +++ b/bin/style.js @@ -3,6 +3,7 @@ module.exports = { "version": 3, "sprite": "http://mapbox-kkaefer.s3.amazonaws.com/static/outdoors-gl/sprite", + "glyphs": "http://mapbox.s3.amazonaws.com/gl-glyphs-256/{{fontstack}}/{{range}}.pbf", "constants": { "@land": "#eee", "@water": "#999", @@ -19,7 +20,6 @@ module.exports = { "mapbox.mapbox-streets-v5": { "type": "vector", "url": "mapbox://mapbox.mapbox-streets-v5", - "glyphs": "http://mapbox.s3.amazonaws.com/gl-glyphs-256/{fontstack}/{range}.pbf", "maxZoom": 14 } }, diff --git a/config/constants.cpp b/config/constants.cpp index 5be91a9fa..36f51559e 100644 --- a/config/constants.cpp +++ b/config/constants.cpp @@ -1,7 +1,5 @@ #include -const char *llmr::kGlyphURL = "http://mapbox.s3.amazonaws.com/gl-glyphs-256/%s/%d-%d.pbf"; - const float llmr::util::tileSize = 512.0f; #if defined(DEBUG) diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index 0d6ef864f..2937a8f69 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -22,7 +22,7 @@ class Texturepool; class Source : public std::enable_shared_from_this, private util::noncopyable { public: - Source(SourceType type = SourceType::Vector, const std::string &url = "", const std::string &glyphs = "", + Source(SourceType type = SourceType::Vector, const std::string &url = "", uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22); bool update(Map &map); @@ -40,7 +40,6 @@ public: public: const SourceType type; const std::string url; - const std::string glyphs; const uint32_t tile_size; const int32_t min_zoom; const int32_t max_zoom; diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index fca18a7c9..47539fb0b 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -51,6 +51,7 @@ public: std::shared_ptr background; std::vector appliedClasses; std::string sprite_url; + std::string glyph_url; private: void updateSources(); diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp index c0570eae7..777a8934d 100644 --- a/include/llmr/style/style_parser.hpp +++ b/include/llmr/style/style_parser.hpp @@ -34,6 +34,10 @@ public: return sprite; } + std::string getGlyphURL() const { + return glyph_url; + } + private: void parseConstants(JSVal value); JSVal replaceConstant(JSVal value); @@ -51,6 +55,7 @@ private: void parseBucket(JSVal value, std::shared_ptr &layer); void parseRender(JSVal value, std::shared_ptr &layer); void parseSprite(JSVal value); + void parseGlyphURL(JSVal value); // Parses optional properties into a render bucket. template @@ -94,6 +99,9 @@ private: // Base URL of the sprite image. std::string sprite; + + // URL template for glyph PBFs. + std::string glyph_url; }; } diff --git a/include/llmr/text/glyph_store.hpp b/include/llmr/text/glyph_store.hpp index e44b94fe0..a1d1046b7 100644 --- a/include/llmr/text/glyph_store.hpp +++ b/include/llmr/text/glyph_store.hpp @@ -51,7 +51,7 @@ private: class GlyphPBF { public: - GlyphPBF(const std::string &fontStack, GlyphRange glyphRange); + GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange); void parse(FontStack &stack); @@ -67,6 +67,8 @@ private: // Manages Glyphrange PBF loading. class GlyphStore { public: + GlyphStore(const std::string &glyphURL); + // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set &glyphRanges); @@ -78,6 +80,9 @@ private: FontStack &createFontStack(const std::string &fontStack); +public: + const std::string glyphURL; + private: std::unordered_map>> ranges; std::unordered_map> stacks; diff --git a/include/llmr/util/constants.hpp b/include/llmr/util/constants.hpp index 49f7a5f4b..999ef05fc 100644 --- a/include/llmr/util/constants.hpp +++ b/include/llmr/util/constants.hpp @@ -7,8 +7,6 @@ namespace llmr { -extern const char *kGlyphURL; - namespace util { extern const float tileSize; diff --git a/src/map/map.cpp b/src/map/map.cpp index 703cdf140..50c172caa 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -24,7 +24,6 @@ Map::Map(View& view) transform(), style(std::make_shared