alaCarte Maps
Renderer for OpenStreetMap tiles
object_renderer.cpp
Go to the documentation of this file.
1 
23 #include <boost/unordered_map.hpp>
24 
25 #include "general/geodata.hpp"
26 #include "general/way.hpp"
27 #include "general/node.hpp"
28 
29 #include "server/style.hpp"
30 
33 #include "object_renderer.hpp"
34 
40 void ObjectRenderer::paintLine(cairo_t* cr,
41  const std::vector<NodeId>& nodeIDs,
42  bool reverse, bool connect) const
43 {
44  cairo_save(cr);
45  cairo_set_matrix(cr, transform);
46 
47  Node* n;
48  bool first = true;
49  int size = nodeIDs.size();
50  for (int i = 0; i < size; i++)
51  {
52  NodeId nid;
53  if (reverse)
54  nid = nodeIDs[size - 1 - i];
55  else
56  nid = nodeIDs[i];
57  n = data->getNode(nid);
58  const FixedPoint& p = n->getLocation();
59 
60  if (first && !connect)
61  cairo_move_to(cr, p.x, p.y);
62  else
63  cairo_line_to(cr, p.x, p.y);
64 
65  first = false;
66  }
67 
68  cairo_restore(cr);
69 }
70 
75 void ObjectRenderer::addShield(std::list<shared_ptr<Shield> >& shields,
76  const FloatPoint& p,
77  const cairo_text_extents_t* textSize) const
78 {
79  double border = ceil(s->shield_frame_width + s->shield_casing_width + 3.0);
80  double x = floor(p.x - textSize->width / 2.0);
81  double y = floor(p.y - textSize->height / 2.0);
82  FloatPoint origin = FloatPoint(x - textSize->x_bearing, y - textSize->y_bearing);
83  FloatRect shield = FloatRect(FloatPoint(x - border, y - border),
84  ceil(textSize->width + 2*border),
85  ceil(textSize->height + 2*border));
87  p.y - RENDERER_SHIELD_DISTANCE / 2.0),
89  shields.push_back(boost::make_shared<Shield>(box, bounds, s->shield_text, s, origin, shield));
90 }
91 
92 
97 void ObjectRenderer::addLabel(std::list<shared_ptr<Label> >& labels,
98  const FloatPoint& p,
99  const cairo_text_extents_t* textSize) const
100 {
101  double x = p.x - textSize->width/2.0;
102  double y = p.y - textSize->height/2.0;
103  double border = s->text_halo_radius;
104  FloatPoint origin = FloatPoint(x - textSize->x_bearing, y - textSize->y_bearing);
105  FloatRect box = FloatRect(FloatPoint(x, y), textSize->width, textSize->height).grow(border, border);
106  labels.push_back(boost::make_shared<Label>(box, bounds, s->text, s, origin));
107 }
108 
109 ObjectRenderer::ObjectRenderer(const shared_ptr<Geodata>& data, const Style* s, const cairo_matrix_t* transform)
110  : data(data)
111  , s(s)
112  , transform(transform)
113 {
114 }
MaybeCachedString shield_text
Definition: style.hpp:120
basic_rect< double > FloatRect
Definition: rect.hpp:170
float text_halo_radius
Definition: style.hpp:99
float shield_casing_width
Definition: style.hpp:119
const cairo_matrix_t * transform
Definition: node.hpp:28
float shield_frame_width
Definition: style.hpp:117
const shared_ptr< Geodata > & data
A Style stores the MapCSS properties for a single Node or Way, or a Relation of type multipolygon...
Definition: style.hpp:35
TESTABLE const FixedPoint & getLocation() const
Definition: node.cpp:43
FloatRect bounds
is set by addWayPath for ways or in transformLocation for nodes
basic_rect< T > grow(T dx, T dy) const
Definition: rect.hpp:91
void paintLine(cairo_t *cr, const std::vector< NodeId > &nodeIDs, bool reverse=false, bool connect=false) const
This file is part of alaCarte.
basic_vector2< double > FloatPoint
Definition: point.hpp:145
void addLabel(std::list< shared_ptr< Label > > &labels, const FloatPoint &p, const cairo_text_extents_t *textSize) const
used by node and way renderer to place a shield.
void addShield(std::list< shared_ptr< Shield > > &shields, const FloatPoint &p, const cairo_text_extents_t *textSize) const
used by node and way renderer to place a shield.
#define RENDERER_SHIELD_DISTANCE
This file is part of alaCarte.
ObjectRenderer(const shared_ptr< Geodata > &data, const Style *s, const cairo_matrix_t *transform)
MaybeCachedString text
Definition: style.hpp:88
const Style * s