+ export as mapnik SVG
This commit is contained in:
parent
a2691d57ca
commit
179631560d
4 changed files with 84 additions and 16 deletions
|
@ -267,7 +267,7 @@ void MainWindow::export_as()
|
|||
void MainWindow::export_as_skia_pdf()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QByteArray fileFormat("pdf");
|
||||
QByteArray fileFormat = action->data().toByteArray();
|
||||
QString initialPath = QDir::currentPath() + "/map-skia." + fileFormat;
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Skia PDF"),
|
||||
|
@ -287,9 +287,8 @@ void MainWindow::export_as_skia_pdf()
|
|||
#ifdef HAVE_CAIRO
|
||||
void MainWindow::export_as_cairo_pdf()
|
||||
{
|
||||
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QByteArray fileFormat("pdf");
|
||||
QByteArray fileFormat = action->data().toByteArray();
|
||||
QString initialPath = QDir::currentPath() + "/map-cairo." + fileFormat;
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Cairo PDF"),
|
||||
|
@ -306,6 +305,29 @@ void MainWindow::export_as_cairo_pdf()
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef SVG_RENDERER
|
||||
|
||||
void MainWindow::export_as_mapnik_svg()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QByteArray fileFormat = action->data().toByteArray();
|
||||
QString initialPath = QDir::currentPath() + "/map-mapnik." + fileFormat;
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Mapnik SVG"),
|
||||
initialPath,
|
||||
tr("%1 Files (*.%2);;All Files (*)")
|
||||
.arg(QString(fileFormat.toUpper()))
|
||||
.arg(QString(fileFormat)));
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
std::cerr << "Mapnik SVG" << std::endl;
|
||||
mapWidget_->export_mapnik_svg(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void MainWindow::print()
|
||||
{
|
||||
|
||||
|
@ -378,13 +400,21 @@ void MainWindow::createActions()
|
|||
exportAsActs.append(action);
|
||||
}
|
||||
#ifdef SKIA_RENDERER
|
||||
exportSkiaPdf = new QAction("Skia",this);
|
||||
connect(exportSkiaPdf, SIGNAL(triggered()), this, SLOT(export_as_skia_pdf()));
|
||||
exportSkiaPDF = new QAction("Skia",this);
|
||||
exportSkiaPDF->setData(QByteArray("pdf"));
|
||||
connect(exportSkiaPDF, SIGNAL(triggered()), this, SLOT(export_as_skia_pdf()));
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CAIRO
|
||||
exportCairoPdf = new QAction("Cairo",this);
|
||||
connect(exportCairoPdf, SIGNAL(triggered()), this, SLOT(export_as_cairo_pdf()));
|
||||
exportCairoPDF = new QAction("Cairo",this);
|
||||
exportCairoPDF->setData(QByteArray("pdf"));
|
||||
connect(exportCairoPDF, SIGNAL(triggered()), this, SLOT(export_as_cairo_pdf()));
|
||||
#endif
|
||||
|
||||
#ifdef SVG_RENDERER
|
||||
exportMapnikSVG = new QAction("Mapnik",this);
|
||||
exportMapnikSVG->setData(QByteArray("svg"));
|
||||
connect(exportMapnikSVG, SIGNAL(triggered()), this, SLOT(export_as_mapnik_svg()));
|
||||
#endif
|
||||
|
||||
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
||||
|
@ -405,15 +435,19 @@ void MainWindow::createMenus()
|
|||
foreach (QAction *action, exportAsActs)
|
||||
exportMenu->addAction(action);
|
||||
|
||||
exportPdfMenu = new QMenu(tr("&Export As PDF"), this);
|
||||
exportPdfMenu->addAction(exportSkiaPdf);
|
||||
exportPdfMenu->addAction(exportCairoPdf);
|
||||
exportPDFMenu = new QMenu(tr("&Export As PDF"), this);
|
||||
exportPDFMenu->addAction(exportSkiaPDF);
|
||||
exportPDFMenu->addAction(exportCairoPDF);
|
||||
|
||||
exportSVGMenu = new QMenu(tr("&Export As SVG"), this);
|
||||
exportSVGMenu->addAction(exportMapnikSVG);
|
||||
|
||||
fileMenu = new QMenu(tr("&File"),this);
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(saveAct);
|
||||
fileMenu->addMenu(exportMenu);
|
||||
fileMenu->addMenu(exportPdfMenu);
|
||||
fileMenu->addMenu(exportPDFMenu);
|
||||
fileMenu->addMenu(exportSVGMenu);
|
||||
fileMenu->addAction(printAct);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(exitAct);
|
||||
|
|
|
@ -56,6 +56,7 @@ public slots:
|
|||
void export_as();
|
||||
void export_as_skia_pdf();
|
||||
void export_as_cairo_pdf();
|
||||
void export_as_mapnik_svg();
|
||||
void open(QString const& path = QString());
|
||||
void reload();
|
||||
void save();
|
||||
|
@ -98,14 +99,16 @@ private:
|
|||
QAction *panDownAct;
|
||||
QAction *reloadAct;
|
||||
QAction *layerInfo;
|
||||
QAction *exportSkiaPdf;
|
||||
QAction *exportCairoPdf;
|
||||
QAction *exportSkiaPDF;
|
||||
QAction *exportCairoPDF;
|
||||
QAction *exportMapnikSVG;
|
||||
//toolbars
|
||||
QToolBar *fileToolBar;
|
||||
QToolBar *editToolBar;
|
||||
//menus
|
||||
QMenu *exportMenu;
|
||||
QMenu *exportPdfMenu;
|
||||
QMenu *exportPDFMenu;
|
||||
QMenu *exportSVGMenu;
|
||||
QMenu *fileMenu;
|
||||
QMenu *helpMenu;
|
||||
//status bar
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
#include <mapnik/config_error.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
|
||||
#ifdef SVG_RENDERER
|
||||
#include <mapnik/svg/output/svg_renderer.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CAIRO
|
||||
// cairo
|
||||
#include <mapnik/cairo_renderer.hpp>
|
||||
|
@ -664,8 +668,6 @@ void MapWidget::export_skia_pdf(QString const& filename)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
{
|
||||
std::cerr << "Not supported" << std::endl;
|
||||
|
@ -675,6 +677,7 @@ void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|||
void MapWidget::export_cairo_pdf(QString const& filename)
|
||||
{
|
||||
save_to_cairo_file(*map_,filename.toStdString(),scaling_factor_);
|
||||
std::cerr << "Done" << std::endl;
|
||||
}
|
||||
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
{
|
||||
|
@ -690,6 +693,30 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SVG_RENDERER
|
||||
void MapWidget::export_mapnik_svg(QString const& filename)
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
std::ofstream output_stream(filename.toStdString().c_str());
|
||||
if (output_stream)
|
||||
{
|
||||
std::ostream_iterator<char> output_itr(output_stream);
|
||||
mapnik::svg_renderer<std::ostream_iterator<char> > ren(*map_, output_itr, scaling_factor_);
|
||||
try
|
||||
{
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught." << std::endl;
|
||||
}
|
||||
output_stream.close();
|
||||
}
|
||||
std::cerr << "Done" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
void MapWidget::updateRenderer(QString const& txt)
|
||||
{
|
||||
bool auto_swap = true;
|
||||
|
|
|
@ -98,6 +98,10 @@ public:
|
|||
void export_cairo_pdf(QString const& filename);
|
||||
#endif
|
||||
|
||||
#ifdef SVG_RENDERER
|
||||
void export_mapnik_svg(QString const& filename);
|
||||
#endif
|
||||
|
||||
public slots:
|
||||
void zoomToLevel(int level);
|
||||
void updateMap();
|
||||
|
|
Loading…
Reference in a new issue