alaCarte Maps
Renderer for OpenStreetMap tiles
style.cpp
Go to the documentation of this file.
1 
22 #include <limits>
23 #include <boost/algorithm/string/replace.hpp>
24 #include <boost/filesystem/operations.hpp>
25 
26 #include "server/style.hpp"
27 #include "general/geo_object.hpp"
28 #include "server/stylesheet.hpp"
30 #include "server/eval/eval.hpp"
31 
33 
34 #define OVERMERGE_IMPL(_attr) if (templ-> _attr) { \
35  templ-> _attr ->overwrite(obj, &(this-> _attr )); \
36  }
37 
38 void Style::overmerge(GeoObject* obj, const shared_ptr<StyleTemplate>& templ)
39 {
42 
45 
49 
58 
61 
66 
71 
81 
84 
86 }
87 
88 void Style::finish(GeoObject* associatedObject, shared_ptr<const Stylesheet> stylesheet)
89 {
90 
91  if (this->icon_image.str().size()) {
92  // if the icon path is set, prepend the path to the stylesheet directory and check for existence
93  this->icon_image = (stylesheet->getPath().parent_path() / boost::filesystem::path(this->icon_image.str())).string();
94  if (!boost::filesystem::exists(this->icon_image.str())) {
95  // delete non existing icon paths so that every remaining icon path for the renderer is valid
96  this->icon_image = "";
97  }
98  }
99 
100  if (this->shield_image.str().size()) {
101  // if the shield image path is set, prepend the path to the stylesheet directory and check for existence
102  this->shield_image = (stylesheet->getPath().parent_path() / boost::filesystem::path(this->shield_image.str())).string();
103  if (!boost::filesystem::exists(this->shield_image.str())) {
104  // delete non existing shield image paths so that every remaining path for the renderer is valid
105  this->shield_image = "";
106  }
107  }
108 
109  if (this->image.str().size()) {
110  // if the image is set, prepend the path to the stylesheet directory and check for existence
111  this->image = (stylesheet->getPath().parent_path() / boost::filesystem::path(this->image.str())).string();
112  if (!boost::filesystem::exists(this->image.str())) {
113  // delete non existing image paths so that every remaining path for the renderer is valid
114  this->image = "";
115  }
116  }
117 
118  if (this->fill_image.str().size()) {
119  // if the fill image is set, prepend the path to the stylesheet directory and check for existence
120  this->fill_image = (stylesheet->getPath().parent_path() / boost::filesystem::path(this->fill_image.str())).string();
121  if (!boost::filesystem::exists(this->fill_image.str())) {
122  // delete non existing fill image paths so that every remaining path for the renderer is valid
123  this->fill_image = "";
124  }
125  }
126 
127  if (this->dashes.size()) {
128  bool zero = true;
129  bool negative = false;
130  for (double d : this->dashes) {
131  if (d > 0.0) {
132  zero = false;
133  } else if (d < 0.0) {
134  negative = true;
135  break;
136  }
137  }
138  if (zero || negative)
139  this->dashes.clear();
140  }
141 
142  if (this->casing_dashes.size()) {
143  bool zero = true;
144  bool negative = false;
145  for (double d : this->casing_dashes) {
146  if (d > 0.0) {
147  zero = false;
148  } else if (d < 0.0) {
149  negative = true;
150  break;
151  }
152  }
153  if (zero || negative)
154  this->casing_dashes.clear();
155  }
156 
157  if (!associatedObject)
158  return;
159 
160  if (this->text.str().size())
161  {
162  // text is not null, so do a tag lookup and display the tag value
163  auto entry = associatedObject->getTags().find(this->text, boost::hash<MaybeCachedString>(), CachedComparator());
164  if (entry != associatedObject->getTags().end()) {
165  this->text = entry->second.str();
166  } else {
167  // no tag of that name found. display empty text
168  this->text = "";
169  }
170  }
171 
172  if (this->shield_text.str().size())
173  {
174  // shield_text is not null, so do a tag lookup and display the tag value
175  auto entry = associatedObject->getTags().find(this->shield_text, boost::hash<MaybeCachedString>(), CachedComparator());
176  if (entry != associatedObject->getTags().end()) {
177  this->shield_text = entry->second.str();
178  } else {
179  // no tag of that name found. display empty text
180  this->shield_text = "";
181  }
182  }
183 
184  auto entry = associatedObject->getTags().find(precached_layer);
185  if (entry != associatedObject->getTags().end()) {
186  std::stringstream strstream(entry->second.str());
187  int layer;
188  strstream >> layer;
189 
190  if (!strstream.bad()) {
191  this->z_index += layer * 100;
192  }
193  }
194 
195 }
196 
197 
199 {
200  color = Color(0.0f, 0.0f, 0.0f, 1.0f);
201 
202  fill_color = Color(1.0f, 1.0f, 1.0f, 0.0f);
203  width = 0.0;
204  casing_width = 0.0;
205  casing_color = Color(1.0f, 1.0f, 1.0f, 1.0f);
206 
207  text_position = Style::TextPosition::POSITION_CENTER;
208  text_color = Color(0.0f, 0.0f, 0.0f, 1.0f);
209  text_offset = 0.0;
210  font_size = 0.0;
212  font_weight = Style::FontWeight::WEIGHT_NORMAL;
213  font_style = Style::FontStyle::STYLE_NORMAL;
214 
215  text_halo_color = Color(1.0f, 1.0f, 1.0f, 0.0f);
216  text_halo_radius = 0.0;
217 
218  linecap = Style::LineCap::CAP_NONE;
219  linejoin = Style::LineJoin::JOIN_MITER;
220  casing_linecap = Style::LineCap::CAP_NONE;
221  casing_linejoin = Style::LineJoin::JOIN_MITER;
222 
223  icon_width = -1.0;
224  icon_height = -1.0;
225  icon_opacity = 1.0;
226 
227 
228  shield_color = Color(1.0f, 1.0f, 1.0f, 0.0f);
229  float shield_opacity = 0.0f;
230  Color shield_frame_color = Color(1.0f, 1.0f, 1.0f, 0.0f);
231  float shield_frame_width = 0.0f;
232  Color shield_casing_color = Color(1.0f, 1.0f, 1.0f, 0.0f);
233  float shield_casing_width = 0.0f;
234  ShieldShape shield_shape = Style::ShieldShape::ROUNDED;
235 
236 
237  z_index = 0;
238 
239 }
MaybeCachedString shield_text
Definition: style.hpp:120
float text_halo_radius
Definition: style.hpp:99
void finish(GeoObject *associatedObject, shared_ptr< const Stylesheet > stylesheet)
Performs finishing operations on the style, like resolve tags for texts or check for icon path existe...
Definition: style.cpp:88
float casing_width
Definition: style.hpp:85
#define DEFAULT_FONT
Definition: settings.hpp:129
float shield_casing_width
Definition: style.hpp:119
LineJoin casing_linejoin
Definition: style.hpp:104
float text_offset
Definition: style.hpp:91
float shield_frame_width
Definition: style.hpp:117
TESTABLE void overmerge(GeoObject *obj, const shared_ptr< StyleTemplate > &style)
Takes all non-"null" (meaning only properties that were explicitely set) properties from the given St...
Definition: style.cpp:38
Color shield_frame_color
Definition: style.hpp:115
ShieldShape
Definition: style.hpp:53
TESTABLE const DataMap< CachedString, CachedString > & getTags() const
Returns a map with key-to-tag-mapping for osm-tags.
Definition: geo_object.cpp:30
Definition: color.hpp:40
const string & str() const
Returns the internal string.
int z_index
Definition: style.hpp:128
MaybeCachedString image
Definition: style.hpp:81
MaybeCachedString fill_image
Definition: style.hpp:82
LineCap casing_linecap
Definition: style.hpp:103
ShieldShape shield_shape
Definition: style.hpp:122
float shield_opacity
Definition: style.hpp:114
MaybeCachedString font_family
Definition: style.hpp:93
Color text_color
Definition: style.hpp:90
float icon_width
Definition: style.hpp:107
Color shield_casing_color
Definition: style.hpp:118
#define OVERMERGE_IMPL(_attr)
This file is part of alaCarte.
Definition: style.cpp:34
FontWeight font_weight
Definition: style.hpp:94
MaybeCachedString shield_image
Definition: style.hpp:121
LineJoin linejoin
Definition: style.hpp:102
float icon_opacity
Definition: style.hpp:109
Style()
Definition: style.cpp:198
Color color
Definition: style.hpp:78
float icon_height
Definition: style.hpp:108
std::vector< double > casing_dashes
Definition: style.hpp:126
float font_size
Definition: style.hpp:92
MaybeCachedString icon_image
Definition: style.hpp:106
Specifies the color.
Definition: mapcss_def.hpp:108
Color fill_color
Definition: style.hpp:79
LineCap linecap
Definition: style.hpp:101
TextPosition text_position
Definition: style.hpp:89
float width
Definition: style.hpp:84
std::vector< double > dashes
Definition: style.hpp:125
FontStyle font_style
Definition: style.hpp:95
Color text_halo_color
Definition: style.hpp:98
void clear()
Sets this string to be the empty string.
CachedString precached_layer("layer")
Color casing_color
Definition: style.hpp:86
Color shield_color
Definition: style.hpp:112
MaybeCachedString text
Definition: style.hpp:88