40 , monitorService(new
boost::asio::dir_monitor(ioService))
51 fs::directory_iterator end_iter;
54 for( fs::directory_iterator dir_iter(
stylesheetFolder) ; dir_iter != end_iter ; ++dir_iter) {
55 if (fs::is_regular_file(dir_iter->status()) && dir_iter->path().extension() ==
".mapcss" ) {
89 shared_ptr<Stylesheet> result;
91 result = entry->second;
103 shared_ptr<RequestManager>
manager = this->manager.lock();
106 shared_ptr<Stylesheet> stylesheet;
110 std::string new_filename = stylesheet_path.filename().string() +
".mapcss";
111 fs::path filename(new_filename);
116 shared_ptr<ParserLogger> logger = *boost::get_error_info<excp::InfoParserLogger>(e);
123 const string* errLine = boost::get_error_info<excp::InfoFailureLineContent>(e);
124 const int* errColumn = boost::get_error_info<excp::InfoFailureColumn>(e);
127 logger->errorStream() <<
"'" << *errLine <<
"'";
130 logger->errorStream() <<
string(*errColumn,
' ') <<
"^-here";
135 shared_ptr<ParserLogger> logger = boost::make_shared<ParserLogger>(stylesheet_path.string());
137 logger->errorStream() <<
"Parsing of stylesheet " << stylesheet_path <<
" took more then " << timeout <<
" ms!";
138 logger->errorStream() <<
"Parsing canceled!";
139 logger->errorStream() <<
"You can configure the timeout via '--parse-timeout'.";
153 shared_ptr<RequestManager>
manager = this->manager.lock();
156 manager->getCache()->deleteTiles(stylesheet_path.string());
158 LOG_SEV(style_log, info) <<
"Deleted Stylesheet[" << stylesheet_path <<
"] from Tile Cache and Stylesheet Cache.";
163 typedef boost::asio::dir_monitor_event eventtype;
165 if(ec != boost::system::error_code())
168 if(ec != boost::asio::error::operation_aborted)
171 LOG_SEV(style_log, error) << ec.message();
177 fs::path path = fs::path(ev.path);
180 if (path.extension() ==
".mapcss" && path.stem().string().find(
".") != 0) {
187 case eventtype::added:
189 LOG_SEV(style_log, info) <<
"Stylesheet[" << path <<
"] added!";
193 case eventtype::removed:
195 LOG_SEV(style_log, info) <<
"Stylesheet[" << path <<
"] removed!";
199 case eventtype::modified:
201 LOG_SEV(style_log, info) <<
"Stylesheet[" << path <<
"] modified!";
216 shared_ptr<StyleTemplate> canvasStyle = boost::make_shared<StyleTemplate>();
217 canvasStyle->fill_color = boost::make_shared<eval::Eval<Color>>(
Color((
uint8)0xEF, (
uint8)0xEF, (
uint8)0xD0));
219 std::vector<shared_ptr<Rule> > rules;
221 shared_ptr<Rule> highwayNodeRule = boost::make_shared<Rule>(geodata);
222 shared_ptr<ApplySelector> highwayNodeApplier = boost::make_shared<ApplySelector>(highwayNodeRule);
223 shared_ptr<Selector> highwayNodeTagSelector = boost::make_shared<HasTagSelector>(highwayNodeRule, highwayNodeApplier,
"highway");
224 highwayNodeRule->setFirstSelector(highwayNodeTagSelector);
225 shared_ptr<StyleTemplate> highwayNodeStyle = boost::make_shared<StyleTemplate>();
226 highwayNodeStyle->color = boost::make_shared<eval::Eval<Color>>(
Color((
uint8)0x00, (
uint8)0x00, (
uint8)0xFF));
227 highwayNodeStyle->width = boost::make_shared<eval::Eval<float>>(5.5);
228 highwayNodeRule->setStyleTemplate(highwayNodeStyle);
229 highwayNodeRule->setZoomBounds(16, 18);
232 rules.push_back(highwayNodeRule);
235 shared_ptr<Rule> highwayRule = boost::make_shared<Rule>(geodata);
236 shared_ptr<ApplySelector> highwayApplier = boost::make_shared<ApplySelector>(highwayRule);
237 shared_ptr<Selector> highwayTagSelector = boost::make_shared<HasTagSelector>(highwayRule, highwayApplier,
"highway");
238 highwayRule->setFirstSelector(highwayTagSelector);
239 shared_ptr<StyleTemplate> highwayStyle = boost::make_shared<StyleTemplate>();
240 highwayStyle->color = boost::make_shared<eval::Eval<Color>>(
Color((
uint8)0x55, (
uint8)0x55, (
uint8)0x55));
241 highwayStyle->width = boost::make_shared<eval::Eval<float>>(2.0);
242 highwayRule->setStyleTemplate(highwayStyle);
245 rules.push_back(highwayRule);
248 shared_ptr<Rule> highwayUpRule = boost::make_shared<Rule>(geodata);
249 shared_ptr<ApplySelector> highwayUpApplier = boost::make_shared<ApplySelector>(highwayUpRule);
250 shared_ptr<Selector> highwayUpTagSelector = boost::make_shared<HasTagSelector>(highwayUpRule, highwayUpApplier,
"highway");
251 highwayUpRule->setFirstSelector(highwayUpTagSelector);
252 shared_ptr<StyleTemplate> highwayUpStyle = boost::make_shared<StyleTemplate>();
253 highwayUpStyle->width = boost::make_shared<eval::Eval<float>>(1.0);
254 highwayUpRule->setStyleTemplate(highwayUpStyle);
255 highwayUpRule->setZoomBounds(0,15);
258 rules.push_back(highwayUpRule);
261 shared_ptr<Rule> forestRule = boost::make_shared<Rule>(geodata);
262 shared_ptr<ApplySelector> forestApplier = boost::make_shared<ApplySelector>(forestRule);
263 shared_ptr<Selector> forestTagSelector = boost::make_shared<TagEqualsSelector>(forestRule, forestApplier,
"landuse",
"forest");
264 forestRule->setFirstSelector(forestTagSelector);
265 shared_ptr<StyleTemplate> forestStyle = boost::make_shared<StyleTemplate>();
266 highwayStyle->fill_color = boost::make_shared<eval::Eval<Color>>(
Color((
uint8)0x00, (
uint8)0xaa, (
uint8)0x00));
267 forestRule->setStyleTemplate(forestStyle);
270 rules.push_back(forestRule);
272 shared_ptr<Rule> adminRule = boost::make_shared<Rule>(geodata);
273 shared_ptr<ApplySelector> adminApplier = boost::make_shared<ApplySelector>(adminRule);
274 shared_ptr<Selector> adminWaySelector = boost::make_shared<ChildWaysSelector>(adminRule, adminApplier);
275 shared_ptr<Selector> adminTagSelector = boost::make_shared<TagEqualsSelector>(adminRule, adminWaySelector,
"boundary",
"administrative");
276 adminRule->setFirstSelector(adminTagSelector);
277 shared_ptr<StyleTemplate> adminStyle = boost::make_shared<StyleTemplate>();
278 highwayStyle->fill_color = boost::make_shared<eval::Eval<Color>>(
Color((
uint8)0xaa, (
uint8)0x00, (
uint8)0x00));
279 highwayUpStyle->width = boost::make_shared<eval::Eval<float>>(2.0);
280 adminRule->setStyleTemplate(adminStyle);
283 rules.push_back(adminRule);
286 return boost::make_shared<Stylesheet>(geodata, rules, canvasStyle);
Thrown if no more time is left.
TESTABLE bool hasStylesheet(const string &path)
boost::thread monitorThread
TESTABLE void onRemovedStylesheet(const fs::path &stylesheet_path)
removes the Stylesheet from the Stylesheet Cache and the prerendered tiles from the Cache...
TESTABLE void stopStylesheetObserving()
Stops the folder observation.
boost::scoped_ptr< boost::asio::dir_monitor > monitorService
TESTABLE void startStylesheetObserving(const shared_ptr< RequestManager > &manager)
starts observing the Stylesheet directory.
Thrown if the parsing fails.
boost::shared_mutex stylesheetsLock
A TileIdentifier identifies a Tile.
static shared_ptr< Stylesheet > makeFallbackStylesheet(const shared_ptr< Geodata > &geodata)
TESTABLE void onFileSystemEvent(const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev)
handler method for dirwatch, forwards only .mapcss files to onNewStylesheet and onRemovedStylesheet ...
TESTABLE shared_ptr< Stylesheet > getStylesheet(const string &path)
Returns the Stylesheet Object for the Stylesheet specified.
#define LOG_SEV(log, lvl)
static const char * style_source
Path to be observed for stylesheets (type: string)
shared_ptr< Configuration > config
TESTABLE void onNewStylesheet(const fs::path &stylesheet_path)
tries to read and parse the given file.
StylesheetManager(const shared_ptr< Configuration > &config)
Creates a new StylesheetManager with the given Configuration.
weak_ptr< RequestManager > manager
boost::asio::io_service ioService
fs::path stylesheetFolder
static const char * config
Option to get the configuration filename (type: string)
static const char * parse_timeout
Option to get the timeout for stylesheet-parsing (type: int)
static shared_ptr< Stylesheet > Load(const boost::filesystem::path &path, const shared_ptr< Geodata > &geodata, int timeout)
Parses the MapCSS Stylesheet at the given path and returns a new Stylesheet containing the defined ru...
boost::unordered_map< fs::path, shared_ptr< Stylesheet > > parsedStylesheets