Beispiel #1
0
void MainWindow::createActions()
{ 
   //exportAct = new QAction(tr("&Export as ..."),this);
   //exportAct->setShortcut(tr("Ctrl+E"));
   //connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
   zoomAllAct = new QAction(QIcon(":/images/home.png"),tr("Zoom All"),this);
   connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all()));
    
   zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"),tr("Zoom To Box"),this);
   zoomBoxAct->setCheckable(true);
   connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box()));
    
   panAct = new QAction(QIcon(":/images/pan.png"),tr("Pan"),this);
   panAct->setCheckable(true);
   connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
    
   infoAct = new QAction(QIcon(":/images/info.png"),tr("Info"),this);
   infoAct->setCheckable(true);
   connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
   
   toolsGroup=new QActionGroup(this);
   toolsGroup->addAction(zoomBoxAct);
   toolsGroup->addAction(panAct);
   toolsGroup->addAction(infoAct);
   zoomBoxAct->setChecked(true);
       
   openAct=new QAction(tr("Open Map definition"),this);
   connect(openAct,SIGNAL(triggered()),this,SLOT(open()));
   saveAct=new QAction(tr("Save Map definition"),this);
   connect(saveAct,SIGNAL(triggered()),this,SLOT(save()));

   panLeftAct = new QAction(QIcon(":/images/left.png"),tr("&Pan Left"),this);
   connect(panLeftAct, SIGNAL(triggered()), this, SLOT(pan_left()));
   panRightAct = new QAction(QIcon(":/images/right.png"),tr("&Pan Right"),this);
   connect(panRightAct, SIGNAL(triggered()), this, SLOT(pan_right()));
   panUpAct = new QAction(QIcon(":/images/up.png"),tr("&Pan Up"),this);
   connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up()));
   panDownAct = new QAction(QIcon(":/images/down.png"),tr("&Pan Down"),this);
   connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down()));
   
   reloadAct = new QAction(QIcon(":/images/reload.png"),tr("Reload"),this);
   connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
   
   layerInfo = new QAction(QIcon(":/images/info.png"),tr("&Layer info"),layerTab_);
   connect(layerInfo, SIGNAL(triggered()), layerTab_,SLOT(layerInfo()));
   connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_,SLOT(layerInfo2(QModelIndex const&)));
   foreach (QByteArray format, QImageWriter::supportedImageFormats()) 
   {
      QString text = tr("%1...").arg(QString(format).toUpper());
      
      QAction *action = new QAction(text, this);
      action->setData(format);
      connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
      exportAsActs.append(action);
   }
Beispiel #2
0
void Map::zoom_all()
{
    try
    {
        if (layers_.empty())
        {
            return;
        }
        projection proj0(srs_);
        box2d<double> ext;
        bool success = false;
        bool first = true;
        std::vector<layer>::const_iterator itr = layers_.begin();
        std::vector<layer>::const_iterator end = layers_.end();
        while (itr != end)
        {
            if (itr->active())
            {
                std::string const& layer_srs = itr->srs();
                projection proj1(layer_srs);
                proj_transform prj_trans(proj0,proj1);
                box2d<double> layer_ext = itr->envelope();
                if (prj_trans.backward(layer_ext, PROJ_ENVELOPE_POINTS))
                {
                    success = true;
                    MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " original ext=" << itr->envelope();
                    MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " transformed to map srs=" << layer_ext;
                    if (first)
                    {
                        ext = layer_ext;
                        first = false;
                    }
                    else
                    {
                        ext.expand_to_include(layer_ext);
                    }
                }
            }
            ++itr;
        }
        if (success)
        {
            if (maximum_extent_) {
                ext.clip(*maximum_extent_);
            }
            zoom_to_box(ext);
        }
        else
        {
            if (maximum_extent_)
            {
                MAPNIK_LOG_ERROR(map) << "could not zoom to combined layer extents"
                    << " so falling back to maximum-extent for zoom_all result";
                zoom_to_box(*maximum_extent_);
            }
            else
            {
                std::ostringstream s;
                s << "could not zoom to combined layer extents "
                  << "using zoom_all because proj4 could not "
                  << "back project any layer extents into the map srs "
                  << "(set map 'maximum-extent' to override layer extents)";
                throw std::runtime_error(s.str());
            }
        }
    }
    catch (proj_init_error const& ex)
    {
        throw mapnik::config_error(std::string("Projection error during map.zoom_all: ") + ex.what());
    }
}
Beispiel #3
0
void Map::zoom_all() 
{
    if (maximum_extent_) {
        zoom_to_box(*maximum_extent_);
    }
    else
    {
        try 
        {
            if (!layers_.size() > 0)
                return;
            projection proj0(srs_);
            box2d<double> ext;
            bool success = false;
            bool first = true;
            std::vector<layer>::const_iterator itr = layers_.begin();
            std::vector<layer>::const_iterator end = layers_.end();
            while (itr != end)
            {
                if (itr->isActive())
                {
                    std::string const& layer_srs = itr->srs();
                    projection proj1(layer_srs);
                    
                    proj_transform prj_trans(proj0,proj1);
                        
                    box2d<double> layer_ext = itr->envelope();
                    // TODO - consider using more robust method: http://trac.mapnik.org/ticket/751
                    if (prj_trans.backward(layer_ext))
                    {
                        success = true;
            #ifdef MAPNIK_DEBUG
                        std::clog << " layer " << itr->name() << " original ext: " << itr->envelope() << "\n";
                        std::clog << " layer " << itr->name() << " transformed to map srs: " << layer_ext << "\n";
            #endif                
                        if (first)
                        {
                            ext = layer_ext;
                            first = false;
                        }
                        else 
                        {
                            ext.expand_to_include(layer_ext);
                        }
                    }
                }
                ++itr;
            }
            if (success) {
                zoom_to_box(ext);
            } else {
                std::ostringstream s;
                s << "could not zoom to combined layer extents "
                  << "using zoom_all because proj4 could not "
                  << "back project any layer extents into the map srs "
                  << "(set map 'maximum-extent' to override layer extents)";
                throw std::runtime_error(s.str());
            }
        }
        catch (proj_init_error & ex)
        {
            std::clog << "proj_init_error:" << ex.what() << "\n";
        }    
    }
}