37 #include <QInputDialog> 38 #include <QMessageBox> 54 std::string TileMapPlugin::BASE_URL_KEY =
"base_url";
55 std::string TileMapPlugin::BING_API_KEY =
"bing_api_key";
56 std::string TileMapPlugin::CUSTOM_SOURCES_KEY =
"custom_sources";
57 std::string TileMapPlugin::MAX_ZOOM_KEY =
"max_zoom";
58 std::string TileMapPlugin::NAME_KEY =
"name";
59 std::string TileMapPlugin::SOURCE_KEY =
"source";
60 std::string TileMapPlugin::TYPE_KEY =
"type";
61 QString TileMapPlugin::BING_NAME =
"Bing Maps (terrain)";
62 QString TileMapPlugin::STAMEN_TERRAIN_NAME =
"Stamen (terrain)";
63 QString TileMapPlugin::STAMEN_TONER_NAME =
"Stamen (toner)";
64 QString TileMapPlugin::STAMEN_WATERCOLOR_NAME =
"Stamen (watercolor)";
66 TileMapPlugin::TileMapPlugin() :
67 config_widget_(new QWidget()),
79 "http://tile.stamen.com/terrain/{level}/{x}/{y}.png",
84 "http://tile.stamen.com/toner/{level}/{x}/{y}.png",
89 "http://tile.stamen.com/watercolor/{level}/{x}/{y}.jpg",
96 p.setColor(QPalette::Background, Qt::white);
99 QPalette p2(
ui_.status->palette());
100 p2.setColor(QPalette::Text, Qt::red);
101 ui_.status->setPalette(p2);
105 QObject::connect(bing.get(), SIGNAL(ErrorMessage(
const std::string&)),
107 QObject::connect(bing.get(), SIGNAL(InfoMessage(
const std::string&)),
108 this, SLOT(
PrintInfo(
const std::string&)));
110 QObject::connect(
ui_.source_combo, SIGNAL(activated(
const QString&)),
this, SLOT(
SelectSource(
const QString&)));
112 QObject::connect(
ui_.reset_cache_button, SIGNAL(clicked()),
this, SLOT(
ResetTileCache()));
121 int source_index =
ui_.source_combo->currentIndex();
122 QString current_name =
ui_.source_combo->currentText();
125 mbox.setText(
"Are you sure you want to delete the source \"" + current_name +
"\"?");
126 mbox.setIcon(QMessageBox::Warning);
127 mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
128 mbox.setDefaultButton(QMessageBox::Cancel);
129 int ret = mbox.exec();
131 if (ret == QMessageBox::Ok)
133 ui_.source_combo->removeItem(source_index);
135 ui_.source_combo->setCurrentIndex(0);
154 std::map<QString, boost::shared_ptr<TileSource> >::iterator iter =
tile_sources_.find(source);
159 ui_.url_label->setText(
"Base URL:");
160 ui_.save_button->setText(
"Save...");
170 ui_.url_label->setText(
"API Key:");
171 ui_.save_button->setText(
"Save");
172 ui_.base_url_text->setEnabled(
true);
173 ui_.save_button->setEnabled(
true);
178 ui_.delete_button->setEnabled(
false);
188 QString current_source =
ui_.source_combo->currentText();
189 QString default_name =
"";
191 std::map<QString, boost::shared_ptr<TileSource> >::iterator iter =
tile_sources_.find(current_source);
194 if (iter->second->IsCustom())
196 default_name = current_source;
210 tr(
"Save New Tile Source"),
211 tr(
"Tile Source Name:"),
215 name = name.trimmed();
216 if (ok && !name.isEmpty())
219 ui_.base_url_text->text(),
221 ui_.max_zoom_spin_box->value());
222 int existing_index =
ui_.source_combo->findText(name);
223 if (existing_index != -1)
225 ui_.source_combo->removeItem(existing_index);
228 ui_.source_combo->addItem(name);
229 int new_index =
ui_.source_combo->findText(name);
230 ui_.source_combo->setCurrentIndex(new_index);
242 if (message ==
ui_.status->text().toStdString())
246 QPalette p(
ui_.status->palette());
247 p.setColor(QPalette::Text, Qt::red);
248 ui_.status->setPalette(p);
249 ui_.status->setText(message.c_str());
254 if (message ==
ui_.status->text().toStdString())
258 QPalette p(
ui_.status->palette());
259 p.setColor(QPalette::Text, Qt::green);
260 ui_.status->setPalette(p);
261 ui_.status->setText(message.c_str());
266 if (message ==
ui_.status->text().toStdString())
270 QPalette p(
ui_.status->palette());
271 p.setColor(QPalette::Text, Qt::darkYellow);
272 ui_.status->setPalette(p);
273 ui_.status->setText(message.c_str());
298 center = to_wgs84 * center;
337 YAML::Node::const_iterator source_iter;
338 for (source_iter = sources.begin(); source_iter != sources.end(); source_iter++)
340 std::string type =
"";
344 type = ((*source_iter)[
TYPE_KEY]).as<std::string>();
347 if (type ==
"wmts" || type.empty())
349 source = boost::make_shared<WmtsSource>(
350 QString::fromStdString(((*source_iter)[
NAME_KEY]).as<std::string>()),
351 QString::fromStdString((*source_iter)[
BASE_URL_KEY].as<std::string>()),
355 else if (type ==
"bing")
357 source = boost::make_shared<BingSource>(
358 QString::fromStdString(((*source_iter)[
NAME_KEY]).as<std::string>()));
361 ui_.source_combo->addItem(source->GetName());
369 source->
SetApiKey(QString::fromStdString(key));
374 std::string source = node[
SOURCE_KEY].as<std::string>();
376 int index =
ui_.source_combo->findText(QString::fromStdString(source), Qt::MatchExactly);
380 ui_.source_combo->setCurrentIndex(index);
391 std::map<QString, boost::shared_ptr<TileSource> >::iterator iter;
394 if (iter->second->IsCustom())
396 emitter << YAML::BeginMap;
397 emitter << YAML::Key <<
BASE_URL_KEY << YAML::Value << iter->second->GetBaseUrl().toStdString();
398 emitter << YAML::Key <<
MAX_ZOOM_KEY << YAML::Value << iter->second->GetMaxZoom();
399 emitter << YAML::Key <<
NAME_KEY << YAML::Value << iter->second->GetName().toStdString();
400 emitter << YAML::Key <<
TYPE_KEY << YAML::Value << iter->second->GetType().toStdString();
401 emitter << YAML::EndMap;
404 emitter << YAML::EndSeq;
408 YAML::Value << boost::trim_copy(bing_source->
GetApiKey().toStdString());
411 YAML::Value << boost::trim_copy(
ui_.source_combo->currentText().toStdString());
425 ui_.base_url_text->setText(tile_source->GetBaseUrl());
427 ui_.max_zoom_spin_box->setValue(tile_source->GetMaxZoom());
432 ui_.base_url_text->setEnabled(
true);
433 ui_.delete_button->setEnabled(
true);
434 ui_.max_zoom_spin_box->setEnabled(
true);
435 ui_.save_button->setEnabled(
true);
440 ui_.base_url_text->setEnabled(
false);
441 ui_.delete_button->setEnabled(
false);
442 ui_.max_zoom_spin_box->setEnabled(
false);
443 ui_.save_button->setEnabled(
false);
void SetTileSource(const boost::shared_ptr< TileSource > &tile_source)
static QString STAMEN_TONER_NAME
static QString STAMEN_TERRAIN_NAME
swri_transform_util::TransformManager tf_manager_
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)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)