diff --git a/demo/viewer/mainwindow.cpp b/demo/viewer/mainwindow.cpp index 6ceaf0656..436a31ddc 100644 --- a/demo/viewer/mainwindow.cpp +++ b/demo/viewer/mainwindow.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // mapnik @@ -97,12 +98,15 @@ MainWindow::MainWindow() //connect mapview to layerlist connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update())); // slider - connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int))); + connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int))); // renderer selector - connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)), + connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)), mapWidget_, SLOT(updateRenderer(QString const&))); - - // + + // scale factor + connect(scale_factor_,SIGNAL(valueChanged(double)), + mapWidget_, SLOT(updateScaleFactor(double))); + // connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap())); connect(layerTab_,SIGNAL(layerSelected(int)), mapWidget_,SLOT(layerSelected(int))); @@ -373,16 +377,23 @@ void MainWindow::createToolBars() fileToolBar->addAction(infoAct); fileToolBar->addAction(reloadAct); fileToolBar->addAction(printAct); - + renderer_selector_ = new QComboBox(fileToolBar); renderer_selector_->setFocusPolicy(Qt::NoFocus); renderer_selector_->addItem("AGG"); #ifdef HAVE_CAIRO renderer_selector_->addItem("Cairo"); #endif - renderer_selector_->addItem("Grid"); + renderer_selector_->addItem("Grid"); fileToolBar->addWidget(renderer_selector_); + scale_factor_ = new QDoubleSpinBox(fileToolBar); + scale_factor_->setMinimum(0.1); + scale_factor_->setMaximum(5.0); + scale_factor_->setSingleStep(0.1); + scale_factor_->setValue(1.0); + + fileToolBar->addWidget(scale_factor_); slider_ = new QSlider(Qt::Horizontal,fileToolBar); slider_->setRange(1,18); slider_->setTickPosition(QSlider::TicksBelow); diff --git a/demo/viewer/mainwindow.hpp b/demo/viewer/mainwindow.hpp index e96fb78f2..25271693b 100644 --- a/demo/viewer/mainwindow.hpp +++ b/demo/viewer/mainwindow.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "mapwidget.hpp" @@ -37,6 +38,7 @@ class LayerTab; class StyleTab; class QSlider; class QComboBox; +class QDoubleSpinBox; class MainWindow : public QMainWindow { @@ -108,6 +110,7 @@ private: QStatusBar *status; QSlider * slider_; QComboBox * renderer_selector_; + QDoubleSpinBox * scale_factor_; mapnik::box2d default_extent_; }; diff --git a/demo/viewer/mapwidget.cpp b/demo/viewer/mapwidget.cpp index 295b141fe..218115548 100644 --- a/demo/viewer/mapwidget.cpp +++ b/demo/viewer/mapwidget.cpp @@ -184,16 +184,16 @@ void MapWidget::mousePressEvent(QMouseEvent* e) feature_ptr feat = fs->next(); if (feat) { - + feature_kv_iterator itr(*feat,true); feature_kv_iterator end(*feat); - + for ( ;itr!=end; ++itr) { info.push_back(QPair(QString(boost::get<0>(*itr).c_str()), boost::get<1>(*itr).to_string().c_str())); } - + typedef mapnik::coord_transform path_type; for (unsigned i=0; inum_geometries();++i) @@ -498,12 +498,12 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix) { unsigned width=map.width(); unsigned height=map.height(); - + image_32 buf(width,height); mapnik::agg_renderer ren(map,buf,scaling_factor); - + try - { + { ren.apply(); QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32); pix = QPixmap::fromImage(image.rgbSwapped()); @@ -527,23 +527,23 @@ void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix) { unsigned width=map.width(); unsigned height=map.height(); - + mapnik::grid buf(width,height,"F_CODE", 1); mapnik::grid_renderer ren(map,buf,scaling_factor); - + try - { + { ren.apply(); int * imdata = static_cast(buf.raw_data()); - + QImage image(width,height,QImage::Format_RGB32); for (unsigned i = 0 ; i < height ; ++i) - { + { for (unsigned j = 0 ; j < width ; ++j) { image.setPixel(j,i,qRgb((uint8_t)(imdata[i*width+j]>>8), (uint8_t)(imdata[i*width+j+1]>>8), - (uint8_t)(imdata[i*width+j+2]>>8))); + (uint8_t)(imdata[i*width+j+2]>>8))); } } pix = QPixmap::fromImage(image); @@ -567,12 +567,12 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix) { #ifdef HAVE_CAIRO - Cairo::RefPtr image_surface = + Cairo::RefPtr image_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, map.width(),map.height()); - + mapnik::cairo_renderer png_render(map, image_surface, scaling_factor); png_render.apply(); - + image_32 buf(image_surface); QImage image((uchar*)buf.raw_data(),buf.width(),buf.height(),QImage::Format_ARGB32); pix = QPixmap::fromImage(image.rgbSwapped()); @@ -588,6 +588,12 @@ void MapWidget::updateRenderer(QString const& txt) updateMap(); } +void MapWidget::updateScaleFactor(double scale_factor) +{ + set_scaling_factor(scale_factor); + updateMap(); +} + void MapWidget::updateMap() { if (map_) @@ -611,7 +617,7 @@ void MapWidget::updateMap() try { - projection prj(map_->srs()); // map projection + projection prj(map_->srs()); // map projection box2d ext = map_->get_current_extent(); double x0 = ext.minx(); double y0 = ext.miny(); @@ -623,7 +629,7 @@ void MapWidget::updateMap() update(); // emit signal to interested widgets emit mapViewChanged(); - } + } catch (...) { std::cerr << "Unknown exception caught!\n"; diff --git a/demo/viewer/mapwidget.hpp b/demo/viewer/mapwidget.hpp index 671cc5ab4..0aab462b8 100644 --- a/demo/viewer/mapwidget.hpp +++ b/demo/viewer/mapwidget.hpp @@ -53,8 +53,8 @@ public: AGG, Cairo, Grid - }; - + }; + private: boost::shared_ptr map_; int selected_; @@ -91,6 +91,7 @@ public slots: void updateMap(); void layerSelected(int); void updateRenderer(QString const& txt); + void updateScaleFactor(double scale_factor); signals: void mapViewChanged(); protected: