diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-06-23 18:05:06 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-06-23 18:05:25 +0200 |
commit | ba4294ae0c06c1ed160f0be47863c9515da8d403 (patch) | |
tree | 5a16d8c200d21fbdf1bb0d91168452aea6142b90 /include | |
parent | f51fd9be585814dedf108cb6e81a674717e39fe6 (diff) | |
download | qtlocation-mapboxgl-ba4294ae0c06c1ed160f0be47863c9515da8d403.tar.gz |
saving current state
Diffstat (limited to 'include')
25 files changed, 663 insertions, 463 deletions
diff --git a/include/llmr/geometry/buffer.hpp b/include/llmr/geometry/buffer.hpp index 27807c809c..607f902bf1 100644 --- a/include/llmr/geometry/buffer.hpp +++ b/include/llmr/geometry/buffer.hpp @@ -32,6 +32,10 @@ public: return pos / itemSize; } + inline bool empty() const { + return pos == 0; + } + // Transfers this buffer to the GPU and binds the buffer to the GL context. void bind(bool force = false) { if (buffer == 0) { diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index e20803b99e..ee5debe4d6 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -21,8 +21,6 @@ namespace llmr { class Source; -typedef std::map<std::string, const std::unique_ptr<Source>> Sources; - class Map : private util::noncopyable { public: explicit Map(View &view); @@ -53,8 +51,9 @@ public: void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height); // Styling - void setAppliedClasses(std::set<std::string> appliedClasses); - std::set<std::string> getAppliedClasses() const; + void toggleClass(const std::string &name); +// void setAppliedClasses(const std::vector<std::string> &appliedClasses); +// const std::vector<std::string> &getAppliedClasses() const; void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0); void setStyleJSON(std::string newStyleJSON); std::string getStyleJSON() const; @@ -108,7 +107,7 @@ public: inline std::shared_ptr<Texturepool> getTexturepool() { return texturepool; } inline std::shared_ptr<uv::loop> getLoop() { return loop; } inline time getAnimationTime() const { return animationTime; } - inline const Sources &getSources() { return sources; } + inline time getTime() const { return animationTime; } private: // uv async callbacks @@ -133,8 +132,8 @@ private: // Unconditionally performs a render with the current map state. void render(); - void renderLayers(const std::vector<LayerDescription>& layers); - void renderLayer(const LayerDescription& layer_desc, RenderPass pass); + void renderLayers(std::shared_ptr<StyleLayerGroup> layers); + void renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass); private: // If cleared, the next time the render thread attempts to render the map, it will *actually* @@ -162,8 +161,6 @@ private: Painter painter; - Sources sources; - std::string styleJSON = ""; bool debug = false; diff --git a/include/llmr/map/raster_tile_data.hpp b/include/llmr/map/raster_tile_data.hpp index fd72cca9b9..f84b540d48 100644 --- a/include/llmr/map/raster_tile_data.hpp +++ b/include/llmr/map/raster_tile_data.hpp @@ -16,8 +16,8 @@ public: ~RasterTileData(); virtual void parse(); - virtual void render(Painter &painter, const LayerDescription& layer_desc); - virtual bool hasData(const LayerDescription& layer_desc) const; + virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc); + virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const; protected: RasterBucket bucket; diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index 7ce6aa632e..c272508584 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -16,60 +16,49 @@ namespace llmr { -class Map; class TransformState; -class Painter; class Texturepool; class Source : public std::enable_shared_from_this<Source>, private util::noncopyable { public: - enum class Type { - vector, - raster - }; + Source(SourceType type = SourceType::Vector, const std::string &url = "", const std::string &glyphs = "", + uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22); -public: - Source(Map &map, Painter &painter, - const char *url = "", Type type = Type::vector, std::vector<uint32_t> zooms = {0}, - uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 14, - bool enabled = true); - - - bool update(); - void updateMatrices(const TransformState &transform); - void drawClippingMasks(); + bool update(Map &map); + void updateMatrices(const mat4 &projMatrix, const TransformState &transform); + void drawClippingMasks(Painter &painter); size_t getTileCount() const; - void render(const LayerDescription& layer_desc, const BucketDescription &bucket_desc); - void finishRender(); + void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc); + void finishRender(Painter &painter); std::forward_list<Tile::ID> getIDs() const; void updateClipIDs(const std::map<Tile::ID, ClipID> &mapping); + static std::string normalizeSourceURL(const std::string &url); + public: - bool enabled; + 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; private: bool findLoadedChildren(const Tile::ID& id, int32_t maxCoveringZoom, std::forward_list<Tile::ID>& retain); bool findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::forward_list<Tile::ID>& retain); - std::forward_list<Tile::ID> covering_tiles(int32_t zoom, const box& points); + std::forward_list<Tile::ID> covering_tiles(const TransformState &state, int32_t clamped_zoom, const box& points); - bool updateTiles(); + bool updateTiles(Map &map); - TileData::State addTile(const Tile::ID& id); + TileData::State addTile(Map &map, const Tile::ID& id); TileData::State hasTile(const Tile::ID& id); - double getZoom() const; + double getZoom(const TransformState &state) const; private: - Map& map; - Painter& painter; - - const Type type; - const std::vector<uint32_t> zooms; - const std::string url; - const uint32_t tile_size; - const int32_t min_zoom; - const int32_t max_zoom; + // Stores the time when this source was most recently updated. + time updated = 0; std::map<Tile::ID, std::unique_ptr<Tile>> tiles; std::map<Tile::ID, std::weak_ptr<TileData>> tile_data; diff --git a/include/llmr/map/tile_data.hpp b/include/llmr/map/tile_data.hpp index 0717f6c924..09f36d59b0 100644 --- a/include/llmr/map/tile_data.hpp +++ b/include/llmr/map/tile_data.hpp @@ -16,7 +16,7 @@ namespace llmr { class Map; class Painter; -class LayerDescription; +class StyleLayer; class TileData : public std::enable_shared_from_this<TileData>, private util::noncopyable { @@ -49,8 +49,8 @@ public: virtual void beforeParse(); virtual void parse() = 0; virtual void afterParse(); - virtual void render(Painter &painter, const LayerDescription& layer_desc) = 0; - virtual bool hasData(const LayerDescription& layer_desc) const = 0; + virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc) = 0; + virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const = 0; public: diff --git a/include/llmr/map/tile_parser.hpp b/include/llmr/map/tile_parser.hpp index edeb3b0008..9e763a13af 100644 --- a/include/llmr/map/tile_parser.hpp +++ b/include/llmr/map/tile_parser.hpp @@ -6,6 +6,7 @@ #include <llmr/text/glyph_store.hpp> #include <llmr/text/glyph.hpp> #include <llmr/util/utf.hpp> +#include <llmr/map/filter_expression.hpp> namespace llmr { @@ -14,8 +15,13 @@ class GlyphAtlas; class GlyphStore; class SpriteAtlas; class VectorTileData; +class StyleLayer; +typedef std::vector<std::shared_ptr<StyleLayer>> StyleLayerGroup; +class StyleBucket; +class StyleBucketFill; +class StyleBucketLine; +class StyleBucketIcon; -class LayerDescription; class Bucket; class TileParser { @@ -32,15 +38,17 @@ public: private: bool obsolete() const; void parseGlyphs(); - void parseStyleLayers(const std::vector<LayerDescription>& layers); + void parseStyleLayers(std::shared_ptr<StyleLayerGroup> layers); void addGlyph(uint64_t tileid, const std::string stackname, const std::u32string &string, const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face); - std::unique_ptr<Bucket> createBucket(const BucketDescription& bucket_desc); - std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); - std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); - std::unique_ptr<Bucket> createIconBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); - std::unique_ptr<Bucket> createTextBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); - template <class Bucket> void addBucketFeatures(Bucket& bucket, const VectorTileLayer& layer, const BucketDescription& bucket_desc); - template <class Bucket, typename ...Args> void addBucketFeatures(Bucket& bucket, const VectorTileLayer& layer, const BucketDescription& bucket_desc, Args&& ...args); + std::unique_ptr<Bucket> createBucket(std::shared_ptr<StyleBucket> bucket_desc); + + std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const PropertyFilterExpression &filter, const StyleBucketFill &fill); + std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const PropertyFilterExpression &filter, const StyleBucketLine &line); + std::unique_ptr<Bucket> createIconBucket(const VectorTileLayer& layer, const PropertyFilterExpression &filter, const StyleBucketIcon &icon); + std::unique_ptr<Bucket> createTextBucket(const VectorTileLayer& layer, const PropertyFilterExpression &filter, const StyleBucketText &text); + + template <class Bucket> void addBucketFeatures(Bucket& bucket, const VectorTileLayer& layer, const PropertyFilterExpression &filter); + template <class Bucket, typename ...Args> void addBucketFeatures(Bucket& bucket, const VectorTileLayer& layer, const PropertyFilterExpression &filter, Args&& ...args); private: const VectorTile vector_data; diff --git a/include/llmr/map/vector_tile.hpp b/include/llmr/map/vector_tile.hpp index 904cc9a2e6..b2f3d416e3 100644 --- a/include/llmr/map/vector_tile.hpp +++ b/include/llmr/map/vector_tile.hpp @@ -67,14 +67,14 @@ public: }; public: - FilteredVectorTileLayer(const VectorTileLayer& layer, const BucketDescription& bucket_desc); + FilteredVectorTileLayer(const VectorTileLayer& layer, const PropertyFilterExpression &filterExpression); iterator begin() const; iterator end() const; private: const VectorTileLayer& layer; - const BucketDescription& bucket_desc; + const PropertyFilterExpression& filterExpression; }; std::ostream& operator<<(std::ostream&, const GlyphPlacement& placement); diff --git a/include/llmr/map/vector_tile_data.hpp b/include/llmr/map/vector_tile_data.hpp index 717ed79a3b..d6f5391c22 100644 --- a/include/llmr/map/vector_tile_data.hpp +++ b/include/llmr/map/vector_tile_data.hpp @@ -29,8 +29,8 @@ public: virtual void beforeParse(); virtual void parse(); virtual void afterParse(); - virtual void render(Painter &painter, const LayerDescription& layer_desc); - virtual bool hasData(const LayerDescription& layer_desc) const; + virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc); + virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const; protected: // Holds the actual geometries in this tile. diff --git a/include/llmr/renderer/bucket.hpp b/include/llmr/renderer/bucket.hpp index 43bd96e3f5..c135b8ee16 100644 --- a/include/llmr/renderer/bucket.hpp +++ b/include/llmr/renderer/bucket.hpp @@ -10,10 +10,11 @@ namespace llmr { class Painter; +class StyleLayer; class Bucket : private util::noncopyable { public: - virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id) = 0; + virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id) = 0; virtual bool hasData() const = 0; virtual ~Bucket() {} diff --git a/include/llmr/renderer/debug_bucket.hpp b/include/llmr/renderer/debug_bucket.hpp index 0b9df57fad..b0b4f7cd04 100644 --- a/include/llmr/renderer/debug_bucket.hpp +++ b/include/llmr/renderer/debug_bucket.hpp @@ -21,7 +21,7 @@ class DebugBucket : public Bucket { public: DebugBucket(DebugFontBuffer& fontBuffer); - virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id); + virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); virtual bool hasData() const; void drawLines(PlainShader& shader); diff --git a/include/llmr/renderer/fill_bucket.hpp b/include/llmr/renderer/fill_bucket.hpp index 95d53ce75f..95de064648 100644 --- a/include/llmr/renderer/fill_bucket.hpp +++ b/include/llmr/renderer/fill_bucket.hpp @@ -41,10 +41,10 @@ public: FillBucket(FillVertexBuffer& vertexBuffer, TriangleElementsBuffer& triangleElementsBuffer, LineElementsBuffer& lineElementsBuffer, - const BucketFillDescription& properties); + const StyleBucketFill& properties); ~FillBucket(); - virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id); + virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); virtual bool hasData() const; void addGeometry(pbf& data); @@ -55,7 +55,7 @@ public: void drawVertices(OutlineShader& shader); public: - const BucketFillDescription &properties; + const StyleBucketFill &properties; private: TESSalloc *allocator; diff --git a/include/llmr/renderer/icon_bucket.hpp b/include/llmr/renderer/icon_bucket.hpp index 5d653a15fd..e6fe161f1a 100644 --- a/include/llmr/renderer/icon_bucket.hpp +++ b/include/llmr/renderer/icon_bucket.hpp @@ -26,9 +26,9 @@ class VectorTileFeature; class IconBucket : public Bucket { public: IconBucket(IconVertexBuffer& vertexBuffer, - const BucketIconDescription& properties); + const StyleBucketIcon& properties); - virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id); + virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); virtual bool hasData() const; void addFeature(const VectorTileFeature &feature, SpriteAtlas &sprite_atlas); @@ -37,7 +37,7 @@ public: void drawIcons(DotShader& shader); public: - const BucketIconDescription &properties; + const StyleBucketIcon &properties; private: diff --git a/include/llmr/renderer/line_bucket.hpp b/include/llmr/renderer/line_bucket.hpp index d7253ace9c..f33982a527 100644 --- a/include/llmr/renderer/line_bucket.hpp +++ b/include/llmr/renderer/line_bucket.hpp @@ -25,9 +25,9 @@ public: LineBucket(LineVertexBuffer& vertexBuffer, TriangleElementsBuffer& triangleElementsBuffer, PointElementsBuffer& pointElementsBuffer, - const BucketLineDescription& properties); + const StyleBucketLine& properties); - virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id); + virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); virtual bool hasData() const; void addGeometry(pbf& data); @@ -39,7 +39,7 @@ public: void drawPoints(LinejoinShader& shader); public: - const BucketLineDescription &properties; + const StyleBucketLine &properties; private: diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 104f4c9bd5..1adca70456 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -24,6 +24,7 @@ #include <llmr/map/transform_state.hpp> #include <map> +#include <unordered_map> namespace llmr { @@ -42,8 +43,6 @@ class RasterBucket; class LayerDescription; class RasterTileData; -typedef std::map<std::string, const std::unique_ptr<Source>> Sources; - class Painter : private util::noncopyable { public: Painter(Map &map); @@ -64,7 +63,7 @@ public: void changeMatrix(); // Renders a particular layer from a tile. - void renderTileLayer(const Tile& tile, const LayerDescription &layer_desc); + void renderTileLayer(const Tile& tile, std::shared_ptr<StyleLayer> layer_desc); // Renders debug information for a tile. void renderTileDebug(const Tile& tile); @@ -79,15 +78,15 @@ public: void renderDebugText(DebugBucket& bucket); void renderDebugText(const std::vector<std::string> &strings); void renderFill(FillBucket& bucket, const FillProperties& properties, const Tile::ID& id, const mat4 &mat); - void renderFill(FillBucket& bucket, const std::string& layer_name, const Tile::ID& id); - void renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& id); - void renderIcon(IconBucket& bucket, const std::string& layer_name, const Tile::ID& id); - void renderText(TextBucket& bucket, const std::string& layer_name, const Tile::ID& id); - void renderRaster(RasterBucket& bucket, const std::string& layer_name, const Tile::ID& id); + void renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); + void renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); + void renderIcon(IconBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); + void renderText(TextBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); + void renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); void preparePrerender(PrerenderedTexture &texture); void finishPrerender(PrerenderedTexture &texture); - void renderPrerenderedTexture(PrerenderedTexture &texture, const GenericProperties &properties); +// void renderPrerenderedTexture(PrerenderedTexture &texture, const GenericProperties &properties); void resize(); @@ -101,7 +100,7 @@ public: // Configures the painter strata that is used for early z-culling of fragments. void setStrata(float strata); - void drawClippingMasks(const Sources &sources); + void drawClippingMasks(const std::set<std::shared_ptr<Source>> &sources); void drawClippingMask(const mat4& matrix, const ClipID& clip); void clearFramebuffers(); @@ -115,7 +114,7 @@ public: bool needsAnimation() const; private: void setupShaders(); - const mat4 &translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor = TranslateAnchor::Map); + const mat4 &translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor = parseTranslateAnchorType()); void prepareTile(const Tile& tile); diff --git a/include/llmr/renderer/raster_bucket.hpp b/include/llmr/renderer/raster_bucket.hpp index 675d15f820..bbd5dee27d 100644 --- a/include/llmr/renderer/raster_bucket.hpp +++ b/include/llmr/renderer/raster_bucket.hpp @@ -15,7 +15,7 @@ class RasterBucket : public Bucket { public: RasterBucket(const std::shared_ptr<Texturepool> &texturepool); - virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id); + virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); virtual bool hasData() const; bool setImage(const std::string &data); diff --git a/include/llmr/renderer/text_bucket.hpp b/include/llmr/renderer/text_bucket.hpp index 566ed459e3..abc95b165b 100644 --- a/include/llmr/renderer/text_bucket.hpp +++ b/include/llmr/renderer/text_bucket.hpp @@ -28,9 +28,9 @@ public: TextBucket( TextVertexBuffer &vertexBuffer, TriangleElementsBuffer &triangleElementsBuffer, - const BucketTextDescription &properties, Placement &placement); + const StyleBucketText &properties, Placement &placement); - virtual void render(Painter &painter, const std::string &layer_name, const Tile::ID &id); + virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID &id); virtual bool hasData() const; void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, @@ -43,7 +43,7 @@ public: void drawGlyphs(TextShader &shader); public: - const BucketTextDescription &properties; + const StyleBucketText &properties; private: TextVertexBuffer& vertexBuffer; diff --git a/include/llmr/style/bucket_description.hpp b/include/llmr/style/bucket_description.hpp index a2386e436b..9b1bb5c774 100644 --- a/include/llmr/style/bucket_description.hpp +++ b/include/llmr/style/bucket_description.hpp @@ -8,125 +8,11 @@ #include <llmr/util/vec.hpp> #include <llmr/map/filter_expression.hpp> #include <llmr/style/value.hpp> +#include <llmr/style/style_bucket.hpp> namespace llmr { -enum class BucketType { - None = 0, - Fill = 1, - Line = 2, - Icon = 3, - Text = 4, - Raster = 5 -}; - -enum class CapType { - None = 0, - Round = 1, - Butt = 2, - Square = 3 -}; - -enum class JoinType { - None = 0, - Miter = 1, - Bevel = 2, - Round = 3 -}; - -enum class TextPathType { - Horizontal = 0, - Curve = 1 -}; - - -inline BucketType bucketType(const std::string& type) { - if (type == "fill") return BucketType::Fill; - else if (type == "line") return BucketType::Line; - else if (type == "point") return BucketType::Icon; - else if (type == "text") return BucketType::Text; - else if (type == "raster") return BucketType::Raster; - else return BucketType::None; -} - -inline CapType capType(const std::string& cap) { - if (cap == "round") return CapType::Round; - else if (cap == "butt") return CapType::Butt; - else if (cap == "square") return CapType::Square; - else return CapType::None; -} - - -inline JoinType joinType(const std::string& join) { - if (join == "miter") return JoinType::Miter; - else if (join == "bevel") return JoinType::Bevel; - else if (join == "round") return JoinType::Round; - else return JoinType::None; -} - -inline TextPathType textPathType(const std::string& path) { - if (path == "horizontal") return TextPathType::Horizontal; - else if (path == "curve") return TextPathType::Curve; - else return TextPathType::Horizontal; -}; - -inline float alignmentType(const std::string& alignment) { - if (alignment == "right") return 1.0f; - else if (alignment == "left") return 0.0f; - else return 0.5; -}; - -inline float verticalAlignmentType(const std::string& alignment) { - if (alignment == "bottom") return 1.0f; - else if (alignment == "top") return 0.0f; - else return 0.5; -}; - -class BucketFillDescription { -public: -}; - -class BucketLineDescription { -public: - CapType cap = CapType::None; - JoinType join = JoinType::None; - float miter_limit = 2.0f; - float round_limit = 1.0f; -}; - -class BucketIconDescription { -public: - uint16_t size = 16; - vec2<float> translate {0, 0}; - std::string icon; -}; - -class BucketTextDescription { -public: - std::string field; - TextPathType path = TextPathType::Horizontal; - std::string font; - float max_size = 16.0f; - float max_width = 15.0f * 24; - float line_height = 1.2f * 24; - float letter_spacing = 0.0f; - float alignment = 0.5f; - float vertical_alignment = 0.5; - vec2<float> translate {0, 0}; - float max_angle_delta = M_PI; - float min_distance = 250.0f; - float rotate = 0.0f; // what is this? - float padding = 2.0f; - bool always_visible = false; -}; - -class BucketRasterDescription { -public: -}; - -typedef util::variant<BucketFillDescription, BucketLineDescription, BucketIconDescription, - BucketTextDescription, BucketRasterDescription> BucketRenderDescription; - +// Deprecated class BucketDescription { public: BucketType feature_type = BucketType::None; @@ -139,7 +25,7 @@ public: PropertyFilterExpression filter = std::true_type(); // Specifies how the geometry for this bucket should be created - BucketRenderDescription render; + StyleBucketRender render; }; std::ostream& operator<<(std::ostream&, const BucketDescription& bucket); diff --git a/include/llmr/style/layer_description.hpp b/include/llmr/style/layer_description.hpp index 97cb7d6f2d..75013db726 100644 --- a/include/llmr/style/layer_description.hpp +++ b/include/llmr/style/layer_description.hpp @@ -5,17 +5,17 @@ #include <vector> namespace llmr { - -class LayerDescription { -public: - std::string name; - std::string bucket_name; - std::vector<LayerDescription> child_layer; - - size_t size() const; -}; - -std::ostream& operator<<(std::ostream&, const LayerDescription& layer); +// +//class LayerDescription { +//public: +// std::string name; +// std::string bucket_name; +// std::vector<LayerDescription> child_layer; +// +// size_t size() const; +//}; +// +//std::ostream& operator<<(std::ostream&, const LayerDescription& layer); } diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp index c31942f94a..cc85122a20 100644 --- a/include/llmr/style/properties.hpp +++ b/include/llmr/style/properties.hpp @@ -13,16 +13,14 @@ #include <boost/optional.hpp> #include <llmr/util/variant.hpp> +#include <llmr/style/types.hpp> + namespace llmr { // Stores a premultiplied color, with all four channels ranging from 0..1 typedef std::array<float, 4> Color; -struct PropertyTransition { - inline PropertyTransition(uint16_t duration, uint16_t delay = 0) - : duration(duration), delay(delay) {} - inline PropertyTransition(const PropertyTransition &transition) - : duration(transition.duration), delay(transition.delay) {} +struct ClassPropertyTransition { uint16_t duration = 0; uint16_t delay = 0; }; @@ -43,32 +41,12 @@ enum class TransitionablePropertyKey { HaloBlur = 13, }; -enum class Winding { - EvenOdd = 1, - NonZero = 2 -}; - -// enum LineCap { -// Round = 1 -// }; - -// enum LineJoin { -// Butt = 1, -// Bevel = 2 -// }; - enum class Property { Null = 1, Constant = 2, Stops = 3, Linear = 4 }; - -enum class TranslateAnchor : uint8_t { - Map = 1, - Viewport = 2 -}; - namespace functions { float null(float z, const std::vector<float>&); @@ -104,88 +82,73 @@ struct FunctionProperty { template <typename T> inline T evaluate(float z) const { return function(z, values); } }; - -enum class RenderType { - Fill, - Line, - Icon, - Text, - Raster, - Composite, - Background -}; - enum class ClassPropertyKey { - Enabled, - TranslateX, - TranslateY, - TranslateTransition, - TranslateAnchor, - Opacity, - OpacityTransition, - Prerender, - PrerenderBuffer, - PrerenderSize, - PrerenderBlur, - - FillWinding, + FillEnabled, FillAntialias, + FillOpacity, FillColor, - FillColorTransition, - FillStrokeColor, - FillStrokeColorTransition, + FillOutlineColor, + FillTranslate, // for transitions only + FillTranslateX, + FillTranslateY, + FillTranslateAnchor, FillImage, + LineEnabled, + LineOpacity, + LineColor, + LineTranslate, // for transitions only + LineTranslateX, + LineTranslateY, + LineTranslateAnchor, LineWidth, - LineWidthTransition, LineOffset, - LineOffsetTransition, - LineColor, - LineColorTransition, + LineBlur, + LineDashArray, // for transitions only LineDashLand, LineDashGap, - LineDashTransition, + LineImage, - IconSize, - IconColor, - IconColorTransition, - IconImage, - IconRadius, - IconRadiusTransition, - IconBlur, - IconBlurTransition, + IconEnabled, + IconOpacity, + IconRotate, + IconRotateAnchor, + TextEnabled, + TextOpacity, + TextSize, TextColor, - TextColorTransition, TextHaloColor, - TextHaloColorTransition, - TextHaloRadius, - TextHaloRadiusTransition, + TextHaloWidth, TextHaloBlur, - TextHaloBlurTransition, - TextSize, - TextRotate, - TextAlwaysVisible, - BackgroundColor, - BackgroundColorTransition, + CompositeEnabled, + CompositeOpacity, + + RasterSpin, + RasterBrightnessLow, + RasterBrightnessHigh, + RasterSaturation, + RasterContrast, + RasterFade, + + BackgroundColor }; typedef util::variant< FunctionProperty, - PropertyTransition, - TranslateAnchor, + TranslateAnchorType, + RotateAnchorType, Color, - Winding, std::string, bool > ClassPropertyValue; class ClassProperties { public: - inline ClassProperties(RenderType type) : type(type) {} + inline ClassProperties() {} inline ClassProperties(ClassProperties &&properties) - : type(properties.type), properties(std::move(properties.properties)) {} + : properties(std::move(properties.properties)) {} template <typename T> inline const T *get(ClassPropertyKey key) const { @@ -196,16 +159,27 @@ public: return nullptr; } } + inline const ClassPropertyTransition *getTransition(ClassPropertyKey key) const { + const auto it = transitions.find(key); + if (it != transitions.end()) { + return ::std::addressof(it->second); + } else { + return nullptr; + } + } template <typename ...Args> - inline void emplace(Args&& ...args) { + inline void set(Args&& ...args) { properties.emplace(::std::forward<Args>(args)...); } + template <typename ...Args> + inline void setTransition(Args&& ...args) { + transitions.emplace(::std::forward<Args>(args)...); + } - const RenderType type; - -private: +public: std::map<ClassPropertyKey, ClassPropertyValue> properties; + std::map<ClassPropertyKey, ClassPropertyTransition> transitions; }; struct PrerenderProperties { @@ -213,98 +187,163 @@ struct PrerenderProperties { uint16_t size = 256; uint16_t blur = 0; }; - -struct GenericProperties { +// +//struct GenericProperties { +// bool enabled = true; +// std::array<float, 2> translate = {{ 0, 0 }}; +// TranslateAnchorType translateAnchor = parseTranslateAnchorType(); +// float opacity = 1.0; +// +// // These are unresolved properties because the value here is per tile, so it might differ. +// boost::optional<FunctionProperty> prerender; +// boost::optional<FunctionProperty> prerenderBuffer; +// boost::optional<FunctionProperty> prerenderSize; +// boost::optional<FunctionProperty> prerenderBlur; +// +// inline bool getPrerender(int8_t z) const { +// return prerender && prerender.get().evaluate<bool>(z); +// } +// +// // Obtains prerender properties by integer zoom level. +// inline PrerenderProperties getPrerenderProperties(int8_t z) const { +// PrerenderProperties props; +// if (prerenderBuffer) props.buffer = prerenderBuffer.get().evaluate<float>(z); +// if (prerenderSize) props.size = prerenderSize.get().evaluate<uint16_t>(z); +// if (prerenderBlur) props.blur = prerenderBlur.get().evaluate<uint16_t>(z); +// return props; +// } +// +// virtual bool isVisible() const { +// if (!enabled) { return false; } +// if (opacity <= 0) { return false; } +// return true; +// } +//}; + +struct FillProperties { + FillProperties() {} bool enabled = true; + bool antialias = true; + float opacity = 1.0f; + Color fill_color = {{ 0, 0, 0, 1 }}; + Color stroke_color = {{ 0, 0, 0, 1 }}; std::array<float, 2> translate = {{ 0, 0 }}; - TranslateAnchor translateAnchor = TranslateAnchor::Map; - float opacity = 1.0; - - // These are unresolved properties because the value here is per tile, so it might differ. - boost::optional<FunctionProperty> prerender; - boost::optional<FunctionProperty> prerenderBuffer; - boost::optional<FunctionProperty> prerenderSize; - boost::optional<FunctionProperty> prerenderBlur; - - inline bool getPrerender(int8_t z) const { - return prerender && prerender.get().evaluate<bool>(z); - } - - // Obtains prerender properties by integer zoom level. - inline PrerenderProperties getPrerenderProperties(int8_t z) const { - PrerenderProperties props; - if (prerenderBuffer) props.buffer = prerenderBuffer.get().evaluate<float>(z); - if (prerenderSize) props.size = prerenderSize.get().evaluate<uint16_t>(z); - if (prerenderBlur) props.blur = prerenderBlur.get().evaluate<uint16_t>(z); - return props; - } + TranslateAnchorType translateAnchor = parseTranslateAnchorType(); + std::string image; - virtual bool isVisible() const { - if (!enabled) { return false; } - if (opacity <= 0) { return false; } - return true; + inline bool isVisible() const { + return enabled && opacity > 0 && (fill_color[3] > 0 || stroke_color[3] > 0); } }; -struct IconProperties : public GenericProperties { - inline IconProperties() : GenericProperties() {} - float size = 0; - Color color = {{ 1, 1, 1, 1 }}; - std::string image; - float radius = 0; - float blur = 0; -}; - -struct LineProperties : public GenericProperties { - inline LineProperties() : GenericProperties() {} +struct LineProperties { + inline LineProperties() {} + bool enabled = true; + float opacity = 1.0f; + Color color = {{ 0, 0, 0, 1 }}; + std::array<float, 2> translate = {{ 0, 0 }}; + TranslateAnchorType translateAnchor = parseTranslateAnchorType(); float width = 0; float offset = 0; - Color color = {{ 0, 0, 0, 1 }}; + float blur = 0; std::array<float, 2> dash_array = {{ 1, -1 }}; + std::string image; + + inline bool isVisible() const { + return enabled && opacity > 0 && color[3] > 0 && width > 0; + } }; -struct FillProperties : public GenericProperties { - inline FillProperties() : GenericProperties() {} - Winding winding = Winding::NonZero; - bool antialias = true; - Color fill_color = {{ 0, 0, 0, 1 }}; - Color stroke_color = {{ 0, 0, 0, 1 }}; - float blur = 0.0f; - std::string image; +struct IconProperties { + inline IconProperties() {} + bool enabled = true; + float opacity = 1.0f; + float rotate = 0.0f; + RotateAnchorType rotate_anchor = parseRotateAnchorType(); + + inline bool isVisible() const { + return enabled && opacity > 0; + } }; -struct TextProperties : public GenericProperties { - inline TextProperties() : GenericProperties() {} +struct TextProperties { + inline TextProperties() {} + bool enabled = true; + float opacity = 1.0f; + float size = 12.0f; Color color = {{ 0, 0, 0, 1 }}; - Color halo = {{ 1, 1, 1, 0.75 }}; - float halo_radius = 0.25f; + Color halo_color = {{ 1, 1, 1, 0.75 }}; + float halo_width = 0.25f; float halo_blur = 1.0f; - float size = 12.0f; - float rotate = 0.0f; - bool always_visible = false; + + inline bool isVisible() const { + return enabled && opacity > 0 && (color[3] > 0 || halo_color[3] > 0) && size > 0; + } }; -struct BackgroundProperties : public GenericProperties { - inline BackgroundProperties() : GenericProperties() {} - Color color = {{ 1, 1, 1, 1 }}; +struct CompositeProperties { + inline CompositeProperties() {} + bool enabled = true; + float opacity = 1.0f; + + inline bool isVisible() const { + return enabled && opacity > 0; + } }; -struct RasterProperties : public GenericProperties { - inline RasterProperties() : GenericProperties() {} +struct RasterProperties { + inline RasterProperties() {} + bool enabled = true; + float opacity = 1.0f; + float spin = 0.0f; + std::array<float, 2> brightness = {{ 0, 1 }}; + float saturation = 0.0f; + float contrast = 0.0f; + float fade = 0.0f; + + inline bool isVisible() const { + return enabled && opacity > 0; + } }; -struct CompositeProperties : public GenericProperties { - inline CompositeProperties() : GenericProperties() {} +struct BackgroundProperties { + inline BackgroundProperties() {} + Color color = {{ 1, 1, 1, 1 }}; }; +typedef util::variant< + FillProperties, + LineProperties, + IconProperties, + TextProperties, + CompositeProperties, + RasterProperties, + BackgroundProperties, + std::false_type +> StyleProperties; + +template <typename T> +const T &defaultStyleProperties(); + + -const IconProperties defaultIconProperties; -const LineProperties defaultLineProperties; -const FillProperties defaultFillProperties; -const TextProperties defaultTextProperties; -const BackgroundProperties defaultBackgroundProperties; -const RasterProperties defaultRasterProperties; -const CompositeProperties defaultCompositeProperties; + +//class StyleSource { +//public: +// typedef std::shared_ptr<StyleSource> Ptr; +// +// enum { Vector, Raster } type = Vector; +// std::string url; +// float tileSize = 512.0f; +//}; + +class RasterizeProperties { +public: + boost::optional<FunctionProperty> enabled; + boost::optional<FunctionProperty> buffer; + boost::optional<FunctionProperty> size; + boost::optional<FunctionProperty> blur; +}; } diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index 5dc19a11ab..d4b5a7961c 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -21,6 +21,33 @@ namespace llmr { class Sprite; +class StyleLayer; +typedef std::vector<std::shared_ptr<StyleLayer>> StyleLayerGroup; + +class StyleLayer { +public: + typedef std::shared_ptr<StyleLayer> Ptr; + +public: + template <typename T> const T &getProperties() { + if (style.is<T>()) { + return style.get<T>(); + } else { + return defaultStyleProperties<T>(); + } + } + +public: + std::string id; + StyleBucket::Ptr bucket; + std::unordered_map<std::string, ClassProperties> styles; + StyleProperties style; + std::unique_ptr<RasterizeProperties> rasterize; + std::shared_ptr<StyleLayerGroup> layers; +}; + + + class Style { public: struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} }; @@ -41,69 +68,90 @@ public: void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0); + void updateSources(); + const std::set<std::shared_ptr<Source>> getActiveSources() const; + + void toggleClass(const std::string &name); + public: std::shared_ptr<Sprite> sprite; + std::shared_ptr<StyleLayerGroup> layers; + std::shared_ptr<StyleLayer> background; + std::vector<std::string> appliedClasses; + + +private: + void updateSources(const std::shared_ptr<StyleLayerGroup> &layers); + void cascade(const std::shared_ptr<StyleLayerGroup> &layers, float z); + +private: + std::set<std::shared_ptr<Source>> activeSources; // This is static information parsed from the stylesheet. - std::map<std::string, BucketDescription> buckets; - std::vector<LayerDescription> layers; - std::map<std::string, ClassDescription> classes; - - // Currently applied settings. - std::set<std::string> appliedClasses; - struct { - BackgroundProperties background; - std::unordered_map<std::string, FillProperties> fills; - std::unordered_map<std::string, LineProperties> lines; - std::unordered_map<std::string, IconProperties> icons; - std::unordered_map<std::string, TextProperties> texts; - std::unordered_map<std::string, RasterProperties> rasters; - std::unordered_map<std::string, CompositeProperties> composites; - std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, std::string>> effective_classes; - } computed; + +// // This is unused!!! +// std::map<std::string, BucketDescription> buckets; +// +// +// std::vector<LayerDescription> layers; +// +// // These are unused!!! +// std::map<std::string, ClassDescription> classes; +// +// // Currently applied settings. +// struct { +// BackgroundProperties background; +// std::unordered_map<std::string, FillProperties> fills; +// std::unordered_map<std::string, LineProperties> lines; +// std::unordered_map<std::string, IconProperties> icons; +// std::unordered_map<std::string, TextProperties> texts; +// std::unordered_map<std::string, RasterProperties> rasters; +// std::unordered_map<std::string, CompositeProperties> composites; +// std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, std::string>> effective_classes; +// } computed; private: - bool transitionInProgress(const std::string &layer_name, TransitionablePropertyKey key, time start); - bool transitionExists(const std::string &layer_name, TransitionablePropertyKey key) const; - bool inNeedOfTransition(const std::string &layer_name, TransitionablePropertyKey key) const; - uint64_t transitionDuration(const std::string &layer_name, TransitionablePropertyKey key) const; - uint64_t transitionDelay(const std::string &layer_name, TransitionablePropertyKey key) const; - - void cascadeProperties(GenericProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(FillProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(LineProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(IconProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(TextProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(RasterProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(CompositeProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); - void cascadeProperties(BackgroundProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// bool transitionInProgress(const std::string &layer_name, TransitionablePropertyKey key, time start); +// bool transitionExists(const std::string &layer_name, TransitionablePropertyKey key) const; +// bool inNeedOfTransition(const std::string &layer_name, TransitionablePropertyKey key) const; +// uint64_t transitionDuration(const std::string &layer_name, TransitionablePropertyKey key) const; +// uint64_t transitionDelay(const std::string &layer_name, TransitionablePropertyKey key) const; +// +// void cascadeProperties(GenericProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(FillProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(LineProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(IconProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(TextProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(RasterProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(CompositeProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); +// void cascadeProperties(BackgroundProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); private: // Last applied settings. - struct { - BackgroundProperties background; - std::unordered_map<std::string, FillProperties> fills; - std::unordered_map<std::string, LineProperties> lines; - std::unordered_map<std::string, IconProperties> icons; - std::unordered_map<std::string, TextProperties> texts; - std::unordered_map<std::string, RasterProperties> rasters; - std::unordered_map<std::string, CompositeProperties> composites; - std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, std::string>> effective_classes; - } previous; - - // Settings values currently being transitioned. - struct { - BackgroundProperties background; - std::unordered_map<std::string, FillProperties> fills; - std::unordered_map<std::string, LineProperties> lines; - std::unordered_map<std::string, IconProperties> icons; - std::unordered_map<std::string, TextProperties> texts; - std::unordered_map<std::string, RasterProperties> rasters; - std::unordered_map<std::string, CompositeProperties> composites; - } transitioning; - - std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, PropertyTransition>> properties_to_transition; - std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, std::shared_ptr<util::transition>>> transitions; +// struct { +// BackgroundProperties background; +// std::unordered_map<std::string, FillProperties> fills; +// std::unordered_map<std::string, LineProperties> lines; +// std::unordered_map<std::string, IconProperties> icons; +// std::unordered_map<std::string, TextProperties> texts; +// std::unordered_map<std::string, RasterProperties> rasters; +// std::unordered_map<std::string, CompositeProperties> composites; +// std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, std::string>> effective_classes; +// } previous; + +// // Settings values currently being transitioned. +// struct { +// BackgroundProperties background; +// std::unordered_map<std::string, FillProperties> fills; +// std::unordered_map<std::string, LineProperties> lines; +// std::unordered_map<std::string, IconProperties> icons; +// std::unordered_map<std::string, TextProperties> texts; +// std::unordered_map<std::string, RasterProperties> rasters; +// std::unordered_map<std::string, CompositeProperties> composites; +// } transitioning; + +// std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, ClassPropertyTransition>> properties_to_transition; +// std::unordered_map<std::string, std::unordered_map<TransitionablePropertyKey, std::shared_ptr<util::transition>>> transitions; uint64_t default_transition_duration = 0; bool initial_render_complete = false; diff --git a/include/llmr/style/style_bucket.hpp b/include/llmr/style/style_bucket.hpp new file mode 100644 index 0000000000..f39ea0161f --- /dev/null +++ b/include/llmr/style/style_bucket.hpp @@ -0,0 +1,82 @@ +#ifndef LLMR_STYLE_STYLE_BUCKET +#define LLMR_STYLE_STYLE_BUCKET + +#include <llmr/style/types.hpp> +#include <llmr/map/filter_expression.hpp> +#include <llmr/util/vec.hpp> +#include <llmr/util/variant.hpp> + +namespace llmr { + +class Source; + +class StyleBucketFill { +public: + WindingType winding = parseWindingType(); +}; + +class StyleBucketLine { +public: + CapType cap = parseCapType(); + JoinType join = parseJoinType(); + float miter_limit = 2.0f; + float round_limit = 1.0f; +}; + +class StyleBucketIcon { +public: + uint16_t size = 16; + vec2<float> translate {0, 0}; + TranslateAnchorType translate_anchor = parseTranslateAnchorType(); + std::string icon; + float spacing = 0.0f; + float padding = 2.0f; +}; + +class StyleBucketText { +public: + std::string field; + TextPathType path = parseTextPathType(); + std::string font; + float max_size = 16.0f; + float max_width = 15.0f * 24; + float line_height = 1.2f * 24; + float letter_spacing = 0.0f; + float alignment = 0.5f; + float vertical_alignment = 0.5; + vec2<float> translate {0, 0}; + TranslateAnchorType translate_anchor = parseTranslateAnchorType(); + float max_angle_delta = M_PI; + float min_distance = 250.0f; + float rotate = 0.0f; // what is this? + float padding = 2.0f; + float slant = 0.0f; + bool always_visible = false; +}; + +class StyleBucketRaster { +public: +}; + +typedef util::variant<StyleBucketFill, StyleBucketLine, StyleBucketIcon, + StyleBucketText, StyleBucketRaster, + std::false_type> StyleBucketRender; + + +class StyleBucket { +public: + typedef std::shared_ptr<StyleBucket> Ptr; + + BucketType type = BucketType::None; + std::string name; + std::shared_ptr<Source> source; + std::string source_layer; + PropertyFilterExpression filter = std::true_type(); + StyleBucketRender render = std::false_type(); +}; + + + +}; + +#endif diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp index 0d254f33e6..cdfd61094e 100644 --- a/include/llmr/style/style_parser.hpp +++ b/include/llmr/style/style_parser.hpp @@ -3,63 +3,74 @@ #include <rapidjson/document.h> #include <llmr/style/style.hpp> +#include <llmr/map/source.hpp> + +#include <unordered_map> +#include <forward_list> + namespace llmr { +class StyleLayer; +typedef std::vector<std::shared_ptr<StyleLayer>> StyleLayerGroup; + class StyleParser { public: using JSVal = const rapidjson::Value&; - void parseBuckets(JSVal value, std::map<std::string, BucketDescription>& buckets); - void parseLayers(JSVal value, std::vector<LayerDescription>& layers); - void parseConstants(JSVal value); - void parseClasses(JSVal value, std::map<std::string, ClassDescription> &classes, - const std::map<std::string, BucketDescription> &buckets, - const std::vector<LayerDescription> &layers); - -private: - LayerDescription parseLayer(JSVal value); - BucketDescription parseBucket(JSVal value); - - std::pair<std::string, ClassDescription> - parseClassDescription(JSVal value, - const std::map<std::string, BucketDescription> &buckets, - const std::map<std::string, std::string> &layerBuckets); - - void parseClass(const std::string &name, JSVal value, ClassDescription &class_desc, - const std::map<std::string, BucketDescription> &buckets, - const std::map<std::string, std::string> &layerBuckets); + void parse(JSVal document); - void parseGenericClass(ClassProperties &klass, JSVal value); - ClassProperties parseFillClass(JSVal value); - ClassProperties parseLineClass(JSVal value); - ClassProperties parseIconClass(JSVal value); - ClassProperties parseTextClass(JSVal value); - ClassProperties parseBackgroundClass(JSVal value); - ClassProperties parseRasterClass(JSVal value); - ClassProperties parseCompositeClass(JSVal value); - - PropertyFilterExpression parseFilterOrExpression(JSVal value); + std::shared_ptr<StyleLayerGroup> getLayers() { + return root; + } +private: + void parseConstants(JSVal value); JSVal replaceConstant(JSVal value); - Value parseValue(JSVal value); + void parseSources(JSVal value); + + std::unique_ptr<StyleLayerGroup> createLayers(JSVal value); + std::shared_ptr<StyleLayer> createLayer(JSVal value); + void parseLayers(); + void parseLayer(std::pair<JSVal, std::shared_ptr<StyleLayer>> &pair); + void parseStyles(JSVal value, std::shared_ptr<StyleLayer> &layer); + void parseStyle(JSVal, ClassProperties &properties); + void parseRasterize(JSVal value, std::shared_ptr<StyleLayer> &layer); + void parseReference(JSVal value, std::shared_ptr<StyleLayer> &layer); + void parseBucket(JSVal value, std::shared_ptr<StyleLayer> &layer); + void parseFilter(JSVal value, std::shared_ptr<StyleLayer> &layer); + void parseRender(JSVal value, std::shared_ptr<StyleLayer> &layer); + + // Parses optional properties into a render bucket. + template<typename T> + bool parseRenderProperty(JSVal value, T &target, const char *name); + template <typename T, typename Parser> + bool parseRenderProperty(JSVal value, T &target, const char *name, Parser &parser); + + // Parses optional properties into style class properties. template <typename T> - T parse(JSVal value); - + bool parseStyleProperty(const char *property_name, ClassPropertyKey key, ClassProperties &klass, JSVal value); template <typename T> - inline void parse(const char *property_name, ClassPropertyKey key, ClassProperties &klass, JSVal value) { - if (value.HasMember(property_name)) { - klass.emplace(key, parse<T>(value[property_name])); - } - } - - void parseTransition(const char *property_name, ClassPropertyKey key, ClassProperties &klass, JSVal value); - void parseFunctionArray(const char *property_name, const std::vector<ClassPropertyKey> &keys, ClassProperties &klass, JSVal value); + bool parseStyleProperty(const char *property_name, const std::vector<ClassPropertyKey> &keys, ClassProperties &klass, JSVal value); +// PropertyFilterExpression parseFilterOrExpression(JSVal value); +// Value parseValue(JSVal value); +// private: - std::map<std::string, const rapidjson::Value *> constants; + std::unordered_map<std::string, const rapidjson::Value *> constants; + + std::unordered_map<std::string, const std::shared_ptr<Source>> sources; + + // This stores the root layer. + std::shared_ptr<StyleLayerGroup> root; + + // This maps ids to Layer objects, with all items being at the root level. + std::unordered_map<std::string, std::pair<JSVal, std::shared_ptr<StyleLayer>>> layers; + + // Store a stack of layers we're parsing right now. This is to prevent reference cycles. + std::forward_list<StyleLayer *> stack; }; } diff --git a/include/llmr/style/types.hpp b/include/llmr/style/types.hpp new file mode 100644 index 0000000000..0d1061d5df --- /dev/null +++ b/include/llmr/style/types.hpp @@ -0,0 +1,136 @@ +#ifndef LLMR_STYLE_TYPES +#define LLMR_STYLE_TYPES + +#include <string> + +namespace llmr { + +enum class BucketType : uint8_t { + None, + Fill, + Line, + Icon, + Text, + Raster +}; + +enum class WindingType : uint8_t { + EvenOdd, + NonZero +}; + +enum class CapType : uint8_t { + None, + Round, + Butt, + Square +}; + +enum class JoinType : uint8_t { + None, + Miter, + Bevel, + Round +}; + +enum class TextPathType : uint8_t { + Horizontal, + Curve +}; + +enum class TranslateAnchorType : uint8_t { + Map, + Viewport +}; + +enum class RotateAnchorType : uint8_t { + Map, + Viewport +}; + +enum class SourceType : uint8_t { + Vector, + Raster, + GeoJSON, + Video +}; + +inline constexpr BucketType parseBucketType(const std::string &type = "") { + return + type.compare("fill") == 0 ? BucketType::Fill : + type.compare("line") == 0 ? BucketType::Line : + type.compare("icon") == 0 ? BucketType::Icon : + type.compare("text") == 0 ? BucketType::Text : + type.compare("raster") == 0 ? BucketType::Raster : + BucketType::None; +} + +inline constexpr WindingType parseWindingType(const std::string &type = "") { + return + type.compare("even-odd") == 0 ? WindingType::EvenOdd : + WindingType::NonZero; +} + +inline constexpr CapType parseCapType(const std::string &cap = "") { + return + cap.compare("round") == 0 ? CapType::Round : + cap.compare("butt") == 0 ? CapType::Butt : + cap.compare("square") == 0 ? CapType::Square : + CapType::None; +} + +inline constexpr JoinType parseJoinType(const std::string &join = "") { + return + join.compare("miter") == 0 ? JoinType::Miter : + join.compare("bevel") == 0 ? JoinType::Bevel : + join.compare("round") == 0 ? JoinType::Round : + JoinType::None; +} + +inline constexpr TextPathType parseTextPathType(const std::string &path = "") { + return + path.compare("horizontal") == 0 ? TextPathType::Horizontal : + path.compare("curve") == 0 ? TextPathType::Curve : + TextPathType::Horizontal; +} + +inline constexpr TranslateAnchorType parseTranslateAnchorType(const std::string &anchor = "") { + return + anchor.compare("viewport") == 0 ? TranslateAnchorType::Viewport : + TranslateAnchorType::Map; +} + +inline constexpr RotateAnchorType parseRotateAnchorType(const std::string &anchor = "") { + return + anchor.compare("map") == 0 ? RotateAnchorType::Map : + RotateAnchorType::Viewport; +} + +inline constexpr float parseAlignmentType(const std::string &alignment = "") { + return + alignment.compare("right") == 0 ? 1.0f : + alignment.compare("left") == 0 ? 0.0f : + 0.5f; +}; + +inline constexpr float parseVerticalAlignmentType(const std::string &alignment = "") { + return + alignment.compare("bottom") == 0 ? 1.0f : + alignment.compare("top") == 0 ? 0.0f : + 0.5f; +}; + +inline constexpr SourceType parseSourceType(const std::string &source = "") { + return + source.compare("vector") == 0 ? SourceType::Vector : + source.compare("raster") == 0 ? SourceType::Raster : + source.compare("geojson") == 0 ? SourceType::GeoJSON : + source.compare("video") == 0 ? SourceType::Video : + SourceType::Vector; +} + + +} + +#endif + diff --git a/include/llmr/text/glyph.hpp b/include/llmr/text/glyph.hpp index a5775b87d9..99c8964701 100644 --- a/include/llmr/text/glyph.hpp +++ b/include/llmr/text/glyph.hpp @@ -12,7 +12,7 @@ namespace llmr { typedef std::pair<uint16_t, uint16_t> GlyphRange; // Note: this only works for the BMP -GlyphRange getGlyphRange(uint32_t glyph); +GlyphRange getGlyphRange(char32_t glyph); struct GlyphMetrics { operator bool() const { diff --git a/include/llmr/text/placement.hpp b/include/llmr/text/placement.hpp index ec7462aa99..c245e260f0 100644 --- a/include/llmr/text/placement.hpp +++ b/include/llmr/text/placement.hpp @@ -10,14 +10,14 @@ namespace llmr { class TextBucket; -class BucketTextDescription; +class StyleBucketText; class Placement { public: Placement(int8_t zoom); void addFeature(TextBucket &bucket, const std::vector<Coordinate> &line, - const BucketTextDescription &info, + const StyleBucketText &info, const GlyphPositions &face, const Shaping &shaping); |