35 #include <boost/algorithm/string/trim.hpp> 43 #include <QInputDialog> 44 #include <QMessageBox> 60 std::string TileMapPlugin::BASE_URL_KEY =
"base_url";
61 std::string TileMapPlugin::BING_API_KEY =
"bing_api_key";
62 std::string TileMapPlugin::CUSTOM_SOURCES_KEY =
"custom_sources";
63 std::string TileMapPlugin::MAX_ZOOM_KEY =
"max_zoom";
64 std::string TileMapPlugin::NAME_KEY =
"name";
65 std::string TileMapPlugin::SOURCE_KEY =
"source";
66 std::string TileMapPlugin::TYPE_KEY =
"type";
67 QString TileMapPlugin::BING_NAME =
"Bing Maps (terrain)";
68 QString TileMapPlugin::STAMEN_TERRAIN_NAME =
"Stamen (terrain)";
69 QString TileMapPlugin::STAMEN_TONER_NAME =
"Stamen (toner)";
70 QString TileMapPlugin::STAMEN_WATERCOLOR_NAME =
"Stamen (watercolor)";
72 TileMapPlugin::TileMapPlugin() :
73 config_widget_(new QWidget()),
85 "http://tile.stamen.com/terrain/{level}/{x}/{y}.png",
90 "http://tile.stamen.com/toner/{level}/{x}/{y}.png",
95 "http://tile.stamen.com/watercolor/{level}/{x}/{y}.jpg",
102 p.setColor(QPalette::Background, Qt::white);
105 QPalette p2(
ui_.status->palette());
106 p2.setColor(QPalette::Text, Qt::red);
107 ui_.status->setPalette(p2);
111 QObject::connect(bing.get(), SIGNAL(ErrorMessage(
const std::string&)),
113 QObject::connect(bing.get(), SIGNAL(InfoMessage(
const std::string&)),
114 this, SLOT(
PrintInfo(
const std::string&)));
116 QObject::connect(
ui_.source_combo, SIGNAL(activated(
const QString&)),
this, SLOT(
SelectSource(
const QString&)));
118 QObject::connect(
ui_.reset_cache_button, SIGNAL(clicked()),
this, SLOT(
ResetTileCache()));
127 int source_index =
ui_.source_combo->currentIndex();
128 QString current_name =
ui_.source_combo->currentText();
131 mbox.setText(
"Are you sure you want to delete the source \"" + current_name +
"\"?");
132 mbox.setIcon(QMessageBox::Warning);
133 mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
134 mbox.setDefaultButton(QMessageBox::Cancel);
135 int ret = mbox.exec();
137 if (ret == QMessageBox::Ok)
139 ui_.source_combo->removeItem(source_index);
141 ui_.source_combo->setCurrentIndex(0);
160 std::map<QString, boost::shared_ptr<TileSource> >::iterator iter =
tile_sources_.find(source);
165 ui_.url_label->setText(
"Base URL:");
166 ui_.save_button->setText(
"Save...");
176 ui_.url_label->setText(
"API Key:");
177 ui_.save_button->setText(
"Save");
178 ui_.base_url_text->setEnabled(
true);
179 ui_.save_button->setEnabled(
true);
184 ui_.delete_button->setEnabled(
false);
194 QString current_source =
ui_.source_combo->currentText();
195 QString default_name =
"";
197 std::map<QString, boost::shared_ptr<TileSource> >::iterator iter =
tile_sources_.find(current_source);
200 if (iter->second->IsCustom())
202 default_name = current_source;
216 tr(
"Save New Tile Source"),
217 tr(
"Tile Source Name:"),
221 name = name.trimmed();
222 if (ok && !name.isEmpty())
225 ui_.base_url_text->text(),
227 ui_.max_zoom_spin_box->value());
228 int existing_index =
ui_.source_combo->findText(name);
229 if (existing_index != -1)
231 ui_.source_combo->removeItem(existing_index);
234 ui_.source_combo->addItem(name);
235 int new_index =
ui_.source_combo->findText(name);
236 ui_.source_combo->setCurrentIndex(new_index);
248 if (message ==
ui_.status->text().toStdString())
252 QPalette p(
ui_.status->palette());
253 p.setColor(QPalette::Text, Qt::red);
254 ui_.status->setPalette(p);
255 ui_.status->setText(message.c_str());
260 if (message ==
ui_.status->text().toStdString())
264 QPalette p(
ui_.status->palette());
265 p.setColor(QPalette::Text, Qt::green);
266 ui_.status->setPalette(p);
267 ui_.status->setText(message.c_str());
272 if (message ==
ui_.status->text().toStdString())
276 QPalette p(
ui_.status->palette());
277 p.setColor(QPalette::Text, Qt::darkYellow);
278 ui_.status->setPalette(p);
279 ui_.status->setText(message.c_str());
309 center = to_wgs84 * center;
325 ROS_DEBUG(
"TileMapPlugin::Draw: Successfully set view");
350 YAML::Node::const_iterator source_iter;
351 for (source_iter = sources.begin(); source_iter != sources.end(); source_iter++)
353 std::string type =
"";
360 if (type ==
"wmts" || type.empty())
363 std::string base_url;
368 source = boost::make_shared<WmtsSource>(
369 QString::fromStdString(name),
370 QString::fromStdString(base_url),
374 else if (type ==
"bing")
378 source = boost::make_shared<BingSource>(QString::fromStdString(name));
381 ui_.source_combo->addItem(source->GetName());
390 source->
SetApiKey(QString::fromStdString(key));
398 int index =
ui_.source_combo->findText(QString::fromStdString(source), Qt::MatchExactly);
402 ui_.source_combo->setCurrentIndex(index);
413 std::map<QString, boost::shared_ptr<TileSource> >::iterator iter;
416 if (iter->second->IsCustom())
418 emitter << YAML::BeginMap;
419 emitter << YAML::Key <<
BASE_URL_KEY << YAML::Value << iter->second->GetBaseUrl().toStdString();
420 emitter << YAML::Key <<
MAX_ZOOM_KEY << YAML::Value << iter->second->GetMaxZoom();
421 emitter << YAML::Key <<
NAME_KEY << YAML::Value << iter->second->GetName().toStdString();
422 emitter << YAML::Key <<
TYPE_KEY << YAML::Value << iter->second->GetType().toStdString();
423 emitter << YAML::EndMap;
426 emitter << YAML::EndSeq;
430 YAML::Value << boost::trim_copy(bing_source->
GetApiKey().toStdString());
433 YAML::Value << boost::trim_copy(
ui_.source_combo->currentText().toStdString());
447 ui_.base_url_text->setText(tile_source->GetBaseUrl());
449 ui_.max_zoom_spin_box->setValue(tile_source->GetMaxZoom());
454 ui_.base_url_text->setEnabled(
true);
455 ui_.delete_button->setEnabled(
true);
456 ui_.max_zoom_spin_box->setEnabled(
true);
457 ui_.save_button->setEnabled(
true);
462 ui_.base_url_text->setEnabled(
false);
463 ui_.delete_button->setEnabled(
false);
464 ui_.max_zoom_spin_box->setEnabled(
false);
465 ui_.save_button->setEnabled(
false);
void SetTileSource(const boost::shared_ptr< TileSource > &tile_source)
static QString STAMEN_TONER_NAME
static QString STAMEN_TERRAIN_NAME
static std::string SOURCE_KEY
std::map< QString, boost::shared_ptr< TileSource > > tile_sources_
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
static const QString BING_TYPE
QString GetApiKey() const
std::string target_frame_
static std::string CUSTOM_SOURCES_KEY
static std::string TYPE_KEY
std::string source_frame_
void Draw(double x, double y, double scale)
void PrintError(const std::string &message)
static QString STAMEN_WATERCOLOR_NAME
static std::string NAME_KEY
void startCustomEditing()
static std::string BASE_URL_KEY
bool FindValue(const YAML::Node &node, const std::string &name)
void LoadConfig(const YAML::Node &node, const std::string &path)
void SetView(double latitude, double longitude, double scale, int32_t width, int32_t height)
static std::string MAX_ZOOM_KEY
static std::string BING_API_KEY
void PrintWarning(const std::string &message)
void SelectSource(const QString &source_name)
void selectTileSource(const boost::shared_ptr< TileSource > &tile_source)
void SetApiKey(const QString &api_key)
void SetTransform(const swri_transform_util::Transform &transform)
bool Initialize(QGLWidget *canvas)
void PrintInfo(const std::string &message)
QWidget * GetConfigWidget(QWidget *parent)
swri_transform_util::TransformManagerPtr tf_manager_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)