mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-22 00:06:57 -04:00
[FEATURE] Add a menu entry to zoom to a layer's scale range
This commit is contained in:
parent
a112dfe63e
commit
556b621ad6
@ -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() ) );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user