Skip to content
Permalink
Browse files

[FEATURE] Add a menu entry to zoom to a layer's scale range

  • Loading branch information
Patrick Valsecchi
Patrick Valsecchi committed Mar 9, 2016
1 parent a112dfe commit 556b621ad6b6daf943325296d74f6a4bc2842ea0
Showing with 30 additions and 0 deletions.
  1. +25 −0 src/app/qgisapp.cpp
  2. +1 −0 src/app/qgisapp.h
  3. +4 −0 src/app/qgsapplayertreeviewmenuprovider.cpp
@@ -7938,6 +7938,31 @@ void QgisApp::setLayerScaleVisibility()
delete dlg;
}

void QgisApp::zoomToLayerScale()
{
if ( !mLayerTreeView )
return;

QList<QgsMapLayer*> layers = mLayerTreeView->selectedLayers();

if ( layers.length() < 1 )
return;

QgsMapLayer* layer = mLayerTreeView->currentLayer();
if ( layer && layer->hasScaleBasedVisibility() )
{
const double scale = mMapCanvas->scale();
if ( scale > layer->maximumScale() )
{
mMapCanvas->zoomScale( layer->maximumScale() * QGis::SCALE_PRECISION );
}
else if ( scale <= layer->minimumScale() )
{
mMapCanvas->zoomScale( layer->minimumScale() );
}
}
}

void QgisApp::setLayerCRS()
{
if ( !( mLayerTreeView && mLayerTreeView->currentLayer() ) )
@@ -744,6 +744,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void duplicateLayers( const QList<QgsMapLayer *>& lyrList = QList<QgsMapLayer *>() );
//! Set Scale visibility of selected layers
void setLayerScaleVisibility();
void zoomToLayerScale();
//! Set CRS of a layer
void setLayerCRS();
//! Assign layer CRS to project
@@ -11,6 +11,7 @@
#include "qgslayertreemodel.h"
#include "qgslayertreemodellegendnode.h"
#include "qgslayertreeviewdefaultactions.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
@@ -105,6 +106,9 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );

if ( !vlayer->isInScaleRange( mCanvas->scale() ) )
menu->addAction( tr( "&Zoom to Layer Scale" ), QgisApp::instance(), SLOT( zoomToLayerScale() ) );

// set layer crs
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );

0 comments on commit 556b621

Please sign in to comment.
You can’t perform that action at this time.