diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index defc1bef1..a1c9842fb 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -52,6 +52,7 @@ public: void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height); // Styling + const std::set> getActiveSources() const; void setAppliedClasses(const std::vector &classes); void toggleClass(const std::string &name); const std::vector &getAppliedClasses() const; @@ -123,6 +124,9 @@ private: // Setup void setup(); + void updateSources(); + void updateSources(const std::shared_ptr &group); + void updateTiles(); void updateRenderState(); @@ -175,6 +179,8 @@ private: int indent = 0; + std::set> activeSources; + private: bool async = false; std::shared_ptr loop; diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index f74624925..b8ffc27f5 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,7 @@ class Texturepool; class Source : public std::enable_shared_from_this, private util::noncopyable { public: + Source(StyleSource style_source, const std::string &access_token = ""); Source(SourceType type = SourceType::Vector, const std::string &url = "", uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22, const std::string &access_token = ""); diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index cfaba1898..cf091ad81 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -2,6 +2,7 @@ #define LLMR_STYLE_STYLE #include +#include #include #include @@ -16,9 +17,7 @@ namespace llmr { -class Map; class Sprite; -class Source; class StyleLayer; class StyleLayerGroup; struct BackgroundProperties; @@ -28,7 +27,7 @@ public: struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} }; public: - Style(Map &map); + Style(); void loadJSON(const uint8_t *const data); @@ -37,8 +36,6 @@ public: void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0); - const std::set> getActiveSources() const; - void setAppliedClasses(const std::vector &classes); const std::vector &getAppliedClasses() const; void toggleClass(const std::string &name); @@ -58,14 +55,8 @@ public: std::string sprite_url; std::string glyph_url; -private: - void updateSources(); - void updateSources(const std::shared_ptr &group); - private: - Map ↦ - std::set> activeSources; PropertyTransition defaultTransition; bool initial_render_complete = false; diff --git a/include/llmr/style/style_bucket.hpp b/include/llmr/style/style_bucket.hpp index 55ffeeb18..c8529fdd2 100644 --- a/include/llmr/style/style_bucket.hpp +++ b/include/llmr/style/style_bucket.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,8 +12,6 @@ namespace llmr { -class Source; - class StyleBucketFill { public: WindingType winding = WindingType::Default; @@ -74,7 +73,7 @@ public: StyleBucket(StyleLayerType type); std::string name; - std::shared_ptr source; + std::shared_ptr style_source; std::string source_layer; FilterExpression filter; StyleBucketRender render = std::false_type(); diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp index 27dfd4757..38ef343e5 100644 --- a/include/llmr/style/style_parser.hpp +++ b/include/llmr/style/style_parser.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -17,7 +17,6 @@ namespace llmr { enum class ClassID : uint32_t; -class Map; class StyleLayer; class StyleLayerGroup; @@ -25,7 +24,7 @@ class StyleParser { public: using JSVal = const rapidjson::Value&; - StyleParser(Map &map); + StyleParser(); void parse(JSVal document); @@ -95,11 +94,9 @@ private: std::forward_list parseValues(JSVal values); private: - Map ↦ - std::unordered_map constants; - std::unordered_map> sources; + std::unordered_map> sources; // This stores the root layer. std::shared_ptr root; diff --git a/include/llmr/style/style_source.hpp b/include/llmr/style/style_source.hpp new file mode 100644 index 000000000..cf55e94be --- /dev/null +++ b/include/llmr/style/style_source.hpp @@ -0,0 +1,27 @@ +#ifndef LLMR_STYLE_STYLE_SOURCE +#define LLMR_STYLE_STYLE_SOURCE + +#include + +namespace llmr { + +struct StyleSource { + const SourceType type; + const std::string url; + const uint32_t tile_size; + const int32_t min_zoom; + const int32_t max_zoom; + + StyleSource(SourceType type = SourceType::Vector, + const std::string &url = "", + uint32_t tile_size = 512, uint32_t min_zoom = 0, + uint32_t max_zoom = 22) + : type(type), + url(url), + tile_size(tile_size), + min_zoom(min_zoom), + max_zoom(max_zoom) {} + }; +}; + +#endif diff --git a/src/map/map.cpp b/src/map/map.cpp index d65b66f78..08b14bcf3 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -22,7 +22,7 @@ using namespace llmr; Map::Map(View& view) : view(view), transform(), - style(std::make_shared