Permalink
Browse files

+ impl metawriter_renderer - initial stub

  • Loading branch information...
1 parent 03e6f9d commit b37212d9a0d49f748f74e1df64cc434722275b87 @artemp artemp committed Jun 8, 2012
@@ -150,16 +150,17 @@ bool has_metawriter(mapnik::Map const& m)
// returns empty shared_ptr when the metawriter isn't found, or is
// of the wrong type. empty pointers make it back to Python as a None.
-mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map & m, std::string const& name) {
- mapnik::metawriter_ptr metawriter = m.find_metawriter(name);
- mapnik::metawriter_inmem_ptr inmem;
- if (metawriter) {
- inmem = boost::dynamic_pointer_cast<mapnik::metawriter_inmem>(metawriter);
- }
+//mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map & m, std::string const& name) {
+// mapnik::metawriter_ptr metawriter = m.find_metawriter(name);
+/// mapnik::metawriter_inmem_ptr inmem;
- return inmem;
-}
+// if (metawriter) {
+// inmem = boost::dynamic_pointer_cast<mapnik::metawriter_inmem>(metawriter);
+// }
+//
+// return inmem;
+//}
// TODO - we likely should allow indexing by negative number from python
// for now, protect against negative values and kindly throw
@@ -482,13 +483,14 @@ void export_map()
"\n"
"Use a path like \"[z]/[x]/[y].json\" to create filenames.\n"
)
- .def("find_inmem_metawriter", find_inmem_metawriter,
- (arg("name")),
- "Gets an inmem metawriter, or None if no such metawriter "
- "exists.\n"
- "Use this after the map has been rendered to retrieve information "
- "about the hit areas rendered on the map.\n"
- )
+
+// .def("find_inmem_metawriter", find_inmem_metawriter,
+ // (arg("name")),
+ // "Gets an inmem metawriter, or None if no such metawriter "
+ // "exists.\n"
+ // "Use this after the map has been rendered to retrieve information "
+ // "about the hit areas rendered on the map.\n"
+ // )
.def("__deepcopy__",&map_deepcopy)
.add_property("parameters",make_function(params_nonconst,return_value_policy<reference_existing_object>()),"TODO")
View
@@ -39,6 +39,12 @@
#include <mapnik/config_error.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/save_map.hpp>
+#include <mapnik/metawriter_renderer.hpp>
+#ifdef HAVE_CAIRO
+// cairo
+#include <mapnik/cairo_renderer.hpp>
+#include <cairomm/surface.h>
+#endif
#endif
// qt
@@ -49,6 +55,8 @@
#include "layerdelegate.hpp"
#include "about_dialog.hpp"
+
+
MainWindow::MainWindow()
: filename_(),
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
@@ -256,6 +264,56 @@ void MainWindow::export_as()
}
}
+void MainWindow::export_as_pdf()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ QString initialPath = QDir::currentPath() + "/mapnik-cairo.pdf";
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Export As PDF"),
+ initialPath,
+ tr("%1 Files (*.%2);;All Files (*)")
+ .arg(QString("PDF"))
+ .arg(QString("pdf")));
+ if (!fileName.isEmpty())
+ {
+ std::cout << "FILE NAME:" << fileName.toStdString() << std::endl;
+#ifdef HAVE_CAIRO
+ boost::shared_ptr<mapnik::Map> map_ptr = mapWidget_->getMap();
+ if (map_ptr)
+ {
+ Cairo::RefPtr<Cairo::Surface> surface;
+ surface = Cairo::PdfSurface::create(fileName.toStdString().c_str(), map_ptr->width(),map_ptr->height());
+ mapnik::cairo_renderer<Cairo::Surface> pdf_render(*map_ptr, surface);
+ pdf_render.apply();
+ }
+#endif
+ }
+}
+
+void MainWindow::export_as_meta()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ QString initialPath = QDir::currentPath() + "/mapnik-meta.json";
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Meta JSON"),
+ initialPath,
+ tr("%1 Files (*.%2);;All Files (*)")
+ .arg(QString("META"))
+ .arg(QString("json")));
+ if (!fileName.isEmpty())
+ {
+ std::cout << "FILE NAME:" << fileName.toStdString() << std::endl;
+#ifdef HAVE_CAIRO
+ boost::shared_ptr<mapnik::Map> map_ptr = mapWidget_->getMap();
+ if (map_ptr)
+ {
+ mapnik::metawriter_renderer ren(*map_ptr);
+ ren.apply();
+ }
+#endif
+ }
+}
+
void MainWindow::print()
{
@@ -328,6 +386,14 @@ void MainWindow::createActions()
exportAsActs.append(action);
}
+ // export PDF
+ exportPdfAction = new QAction(QString("PDF (cairo)"), this);
+ connect(exportPdfAction, SIGNAL(triggered()), this, SLOT(export_as_pdf()));
+
+ // export META Json
+ exportMetaAction = new QAction(QString("META (json)"), this);
+ connect(exportMetaAction, SIGNAL(triggered()), this, SLOT(export_as_meta()));
+
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
printAct->setShortcut(tr("Ctrl+E"));
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
@@ -349,6 +415,8 @@ void MainWindow::createMenus()
fileMenu = new QMenu(tr("&File"),this);
fileMenu->addAction(openAct);
fileMenu->addAction(saveAct);
+ fileMenu->addAction(exportPdfAction);
+ fileMenu->addAction(exportMetaAction);
fileMenu->addMenu(exportMenu);
fileMenu->addAction(printAct);
fileMenu->addSeparator();
@@ -54,6 +54,8 @@ public slots:
void pan();
void info();
void export_as();
+ void export_as_pdf();
+ void export_as_meta();
void open(QString const& path = QString());
void reload();
void save();
@@ -88,6 +90,8 @@ public slots:
QAction *infoAct;
QAction *openAct;
QAction *saveAct;
+ QAction *exportPdfAction;
+ QAction *exportMetaAction;
QAction *printAct;
QAction *exitAct;
QAction *aboutAct;
View
@@ -28,7 +28,7 @@
#include <mapnik/feature_type_style.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/layer.hpp>
-#include <mapnik/metawriter.hpp>
+#include <mapnik/metawriter_factory.hpp>
#include <mapnik/params.hpp>
// boost
@@ -72,7 +72,7 @@ class MAPNIK_DECL Map
boost::optional<color> background_;
boost::optional<std::string> background_image_;
std::map<std::string,feature_type_style> styles_;
- std::map<std::string,metawriter_ptr> metawriters_;
+ std::map<std::string,metawriter> metawriters_;
std::map<std::string,font_set> fontsets_;
std::vector<layer> layers_;
aspect_fix_mode aspectFixMode_;
@@ -87,7 +87,7 @@ class MAPNIK_DECL Map
typedef std::map<std::string,feature_type_style>::iterator style_iterator;
typedef std::map<std::string,font_set>::const_iterator const_fontset_iterator;
typedef std::map<std::string,font_set>::iterator fontset_iterator;
- typedef std::map<std::string,metawriter_ptr>::const_iterator const_metawriter_iterator;
+ typedef std::map<std::string,metawriter>::const_iterator const_metawriter_iterator;
/*! \brief Default constructor.
*
@@ -173,7 +173,7 @@ class MAPNIK_DECL Map
* @return true If success.
* @return false If no success.
*/
- bool insert_metawriter(std::string const& name, metawriter_ptr const& writer);
+ bool insert_metawriter(std::string const& name, metawriter const& writer);
/*! \brief Remove a metawriter from the map.
* @param name The name of the writer.
@@ -184,12 +184,12 @@ class MAPNIK_DECL Map
* @param name The name of the writer.
* @return The writer if found. If not found return 0.
*/
- metawriter_ptr find_metawriter(std::string const& name) const;
+ metawriter find_metawriter(std::string const& name) const;
/*! \brief Get all metawriters.
* @return Const reference to metawriters.
*/
- std::map<std::string,metawriter_ptr> const& metawriters() const;
+ std::map<std::string,metawriter> const& metawriters() const;
/*! \brief Get first iterator in metawriters.
* @return Constant metawriter iterator.
@@ -27,13 +27,12 @@
#include <mapnik/feature.hpp>
#include <mapnik/ctrans.hpp>
#include <mapnik/projection.hpp>
-
// boost
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/concept_check.hpp>
-
+#include <boost/variant.hpp>
// stl
#include <set>
#include <string>
@@ -79,7 +78,7 @@ class metawriter_property_map
};
-/** All properties to be output by a metawriter. */
+// All properties to be output by a metawriter.
class metawriter_properties : public std::set<std::string>
{
public:
@@ -90,76 +89,23 @@ class metawriter_properties : public std::set<std::string>
std::string to_string() const;
};
-/** Abstract baseclass for all metawriter classes. */
-class metawriter
+// Abstract baseclass for all metawriter classes.
+class metawriter_base
{
-public:
- typedef coord_transform<CoordTransform,geometry_type> path_type;
- metawriter(metawriter_properties dflt_properties) :
+public:
+ explicit metawriter_base(metawriter_properties dflt_properties) :
dflt_properties_(dflt_properties),
width_(0),
height_(0) {}
- virtual ~metawriter() {}
- /** Output a rectangular area.
- * \param box Area (in pixel coordinates)
- * \param feature The feature being processed
- * \param prj_trans Projection transformation
- * \param t Coordinate transformation
- * \param properties List of properties to output
- */
- virtual void add_box(box2d<double> const& box, Feature const& feature,
- CoordTransform const& t,
- metawriter_properties const& properties)=0;
- virtual void add_text(boost::ptr_vector<text_path> &placements,
- box2d<double> const& extents,
- Feature const& feature,
- CoordTransform const& t,
- metawriter_properties const& properties)=0;
- virtual void add_polygon(path_type & path,
- Feature const& feature,
- CoordTransform const& t,
- metawriter_properties const& properties)=0;
- virtual void add_line(path_type & path,
- Feature const& feature,
- CoordTransform const& t,
- metawriter_properties const& properties)=0;
-
- /** Start processing.
- * Write file header, init database connection, ...
- *
- * \param properties metawriter_property_map object with userdefined values.
- * Useful for setting filename etc.
- */
- virtual void start(metawriter_property_map const& properties)
- {
- boost::ignore_unused_variable_warning(properties);
- }
-
- /** Stop processing.
- * Write file footer, close database connection, ...
- */
- virtual void stop() {}
- /** Set output size (pixels).
- * All features that are completely outside this size are discarded.
- */
- void set_size(int width, int height) { width_ = width; height_ = height; }
- /** Set Map object's srs. */
- virtual void set_map_srs(projection const& proj) { /* Not required when working with image coordinates. */ }
- /** Return the list of default properties. */
+
+ void set_size(int width, int height) { width_ = width; height_ = height; }
metawriter_properties const& get_default_properties() const { return dflt_properties_;}
protected:
metawriter_properties dflt_properties_;
- /** Output width (pixels). */
int width_;
- /** Output height (pixels). */
int height_;
};
-/** Shared pointer to metawriter object. */
-typedef boost::shared_ptr<metawriter> metawriter_ptr;
-/** Metawriter object + properties. */
-typedef std::pair<metawriter_ptr, metawriter_properties> metawriter_with_properties;
-
}
#endif // MAPNIK_METAWRITER_HPP
Oops, something went wrong.

0 comments on commit b37212d

Please sign in to comment.