alaCarte Maps
Renderer for OpenStreetMap tiles
Go to the documentation of this file.
21 #ifndef RENDERER_HPP
22 #define RENDERER_HPP
24 #include "settings.hpp"
26 #include <boost/thread/mutex.hpp>
28 #include <cairo.h>
31 #include "server/tile.hpp"
33 #define TILE_SIZE 256
35 class MetaIdentifier;
36 class RenderAttributes;
37 class Geodata;
38 class GeoObject;
39 class Tile;
40 class Node;
41 class Way;
42 class Style;
43 class Label;
44 class Shield;
45 class AssetCache;
46 class RenderCanvas;
47 struct CairoLayer;
49 class Renderer
50 {
51 public:
52  Renderer(const shared_ptr<Geodata>& data);
54  TESTABLE void renderEmptyTile(RenderAttributes& map, const shared_ptr<RenderCanvas>& canvas, const shared_ptr<Tile>& tile);
55  TESTABLE void renderMetaTile(RenderAttributes& map, const shared_ptr<RenderCanvas>& canvas, const shared_ptr<MetaIdentifier>& id);
56  TESTABLE void sliceTile(const shared_ptr<RenderCanvas>& canvas, const shared_ptr<MetaIdentifier>& id, const shared_ptr<Tile>& tile) const;
58 protected:
59  void placeLabels(const std::list<shared_ptr<Label> >& labels,
60  std::vector<shared_ptr<Label> >& placed);
61  void placeShields(const std::list<shared_ptr<Shield> >& shields,
62  std::vector<shared_ptr<Shield> >& placed);
64 private:
67  const shared_ptr<Geodata> data;
72  void printTileId(cairo_t* cr, const shared_ptr<TileIdentifier>& id) const;
73  void sortObjects(RenderAttributes& map, std::vector<NodeId>& nodes, std::vector<WayId>& ways, std::vector<RelId>& relations) const;
74  bool isCutOff(const FloatRect& box, const FloatRect& owner);
75  void compositeLayers(CairoLayer* layers) const;
76  void paintBackground(CairoLayer& layer, const Style* canvasStyle) const;
77  void renderObjects(CairoLayer* layers, RenderAttributes& map, const cairo_matrix_t* transform,
78  std::vector<NodeId>& nodes, std::vector<WayId>& ways, std::vector<RelId>& relations,
79  std::list<shared_ptr<Label>>& labels, std::list<shared_ptr<Shield>>& shields,
80  AssetCache& cache) const;
81  template <typename LabelType>
82  void renderLabels(cairo_t* cr, std::vector<shared_ptr<LabelType> >& labels, AssetCache& cache) const;
83  void renderShields(cairo_t* cr, std::vector<shared_ptr<Shield> >& shields) const;
84  void renderArea(const FixedRect& area,
85  const shared_ptr<RenderCanvas>& canvas,
86  double width, double height,
87  RenderAttributes& map,
88  AssetCache& cache);
91  static boost::mutex renderLock;
92 };
94 #endif
void paintBackground(CairoLayer &layer, const Style *canvasStyle) const
Definition: renderer.cpp:465
void placeLabels(const std::list< shared_ptr< Label > > &labels, std::vector< shared_ptr< Label > > &placed)
Place labels with greedy algorithm.
Definition: renderer.cpp:362
FloatRect bounds
Definition: renderer.hpp:68
Definition: node.hpp:28
A RenderAttributes object contains mappings from NodeIDs and WayIDs to Style objects which define how...
void sortObjects(RenderAttributes &map, std::vector< NodeId > &nodes, std::vector< WayId > &ways, std::vector< RelId > &relations) const
Sort objetcs into painting order.
Definition: renderer.cpp:140
Definition: tile.hpp:30
Stores bounding box and style of a label that needs to be placed.
TESTABLE void sliceTile(const shared_ptr< RenderCanvas > &canvas, const shared_ptr< MetaIdentifier > &id, const shared_ptr< Tile > &tile) const
Definition: renderer.cpp:557
A Style stores the MapCSS properties for a single Node or Way, or a Relation of type multipolygon...
Definition: style.hpp:35
void renderArea(const FixedRect &area, const shared_ptr< RenderCanvas > &canvas, double width, double height, RenderAttributes &map, AssetCache &cache)
Definition: renderer.cpp:510
FloatRect neighbours[8]
Definition: renderer.hpp:69
void renderShields(cairo_t *cr, std::vector< shared_ptr< Shield > > &shields) const
Only renders the shield background, the text is rendered in renderLabels.
Definition: renderer.cpp:262
A MetaIdentifier identifies a set of Tiles that a rendered together.
void placeShields(const std::list< shared_ptr< Shield > > &shields, std::vector< shared_ptr< Shield > > &placed)
Place labels with greedy algorithm.
Definition: renderer.cpp:424
const shared_ptr< Geodata > data
stores the actual data
Definition: renderer.hpp:67
bool isCutOff(const FloatRect &box, const FloatRect &owner)
Checks if all neighbour tile know about the owner of the label.
Definition: renderer.cpp:353
void renderLabels(cairo_t *cr, std::vector< shared_ptr< LabelType > > &labels, AssetCache &cache) const
Definition: renderer.cpp:313
void renderObjects(CairoLayer *layers, RenderAttributes &map, const cairo_matrix_t *transform, std::vector< NodeId > &nodes, std::vector< WayId > &ways, std::vector< RelId > &relations, std::list< shared_ptr< Label >> &labels, std::list< shared_ptr< Shield >> &shields, AssetCache &cache) const
Renders a OSM layer onto the given cairo surface.
Definition: renderer.cpp:170
void compositeLayers(CairoLayer *layers) const
Composited all layers into the first layer.
Definition: renderer.cpp:449
This file is part of alaCarte.
#define TESTABLE
Definition: settings.hpp:85
static boost::mutex renderLock
lock calls to cairo for old versions that are not thread-safe.
Definition: renderer.hpp:91
TESTABLE void renderEmptyTile(RenderAttributes &map, const shared_ptr< RenderCanvas > &canvas, const shared_ptr< Tile > &tile)
Definition: renderer.cpp:485
FloatRect neighbourRequests[8]
Definition: renderer.hpp:70
void printTileId(cairo_t *cr, const shared_ptr< TileIdentifier > &id) const
Debug function that prints identifier on the tile.
Definition: renderer.cpp:115
Definition: way.hpp:31
TESTABLE void renderMetaTile(RenderAttributes &map, const shared_ptr< RenderCanvas > &canvas, const shared_ptr< MetaIdentifier > &id)
Definition: renderer.cpp:583
Renderer(const shared_ptr< Geodata > &data)
Definition: renderer.cpp:90