mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
allow zooming to multiple features by their ID
Changed QgsMapCanvas::zoomToFeatureId() to QgsMapCanvas::zoomToFeatureIds() accepting multiple IDs instead of just one.
This commit is contained in:
parent
0ba089e6d4
commit
e5f1d87506
@ -168,10 +168,10 @@ class QgsMapCanvas : QGraphicsView
|
|||||||
@param layer optionally specify different than current layer */
|
@param layer optionally specify different than current layer */
|
||||||
void zoomToSelected( QgsVectorLayer* layer = NULL );
|
void zoomToSelected( QgsVectorLayer* layer = NULL );
|
||||||
|
|
||||||
/** Set canvas extent to the bounding box of a feature
|
/** Set canvas extent to the bounding box of a set of features
|
||||||
@param layer the vector layer
|
@param layer the vector layer
|
||||||
@param id the feature id*/
|
@param ids the feature ids*/
|
||||||
void zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id );
|
void zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids );
|
||||||
|
|
||||||
/** Pan to the selected features of current (vector) layer keeping same extent. */
|
/** Pan to the selected features of current (vector) layer keeping same extent. */
|
||||||
void panToSelected( QgsVectorLayer* layer = NULL );
|
void panToSelected( QgsVectorLayer* layer = NULL );
|
||||||
|
@ -409,11 +409,12 @@ void QgsDualView::zoomToCurrentFeature()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsFeatureId id = mFilterModel->rowToId( currentIndex );
|
QgsFeatureIds ids;
|
||||||
|
ids.insert( mFilterModel->rowToId( currentIndex ) );
|
||||||
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
|
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
|
||||||
if ( canvas )
|
if ( canvas )
|
||||||
{
|
{
|
||||||
canvas->zoomToFeatureId( mLayerCache->layer(), id );
|
canvas->zoomToFeatureIds( mLayerCache->layer(), ids );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1071,38 +1071,45 @@ void QgsMapCanvas::zoomToFeatureExtent( QgsRectangle& rect )
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapCanvas::zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id )
|
void QgsMapCanvas::zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids )
|
||||||
{
|
{
|
||||||
if ( !layer )
|
if ( !layer )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setFilterFid( id ).setSubsetOfAttributes( QgsAttributeList() ) );
|
QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setFilterFids( ids ).setSubsetOfAttributes( QgsAttributeList() ) );
|
||||||
|
QgsRectangle rect;
|
||||||
|
rect.setMinimal();
|
||||||
QgsFeature fet;
|
QgsFeature fet;
|
||||||
if ( !it.nextFeature( fet ) )
|
int featureCount = 0;
|
||||||
|
while ( it.nextFeature( fet ) )
|
||||||
|
{
|
||||||
|
QgsGeometry* geom = fet.geometry();
|
||||||
|
QString errorMessage;
|
||||||
|
if ( !geom || !geom->geometry() )
|
||||||
|
{
|
||||||
|
errorMessage = tr( "Feature does not have a geometry" );
|
||||||
|
}
|
||||||
|
else if ( geom->geometry()->isEmpty() )
|
||||||
|
{
|
||||||
|
errorMessage = tr( "Feature geometry is empty" );
|
||||||
|
}
|
||||||
|
if ( !errorMessage.isEmpty() )
|
||||||
|
{
|
||||||
|
emit messageEmitted( tr( "Zoom to feature id failed" ), errorMessage, QgsMessageBar::WARNING );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QgsRectangle r = mapSettings().layerExtentToOutputExtent( layer, geom->boundingBox() );
|
||||||
|
rect.combineExtentWith( &r );
|
||||||
|
featureCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( featureCount != ids.count() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsGeometry* geom = fet.geometry();
|
|
||||||
|
|
||||||
QString errorMessage;
|
|
||||||
if ( !geom || !geom->geometry() )
|
|
||||||
{
|
|
||||||
errorMessage = tr( "Feature does not have a geometry" );
|
|
||||||
}
|
|
||||||
else if ( geom->geometry()->isEmpty() )
|
|
||||||
{
|
|
||||||
errorMessage = tr( "Feature geometry is empty" );
|
|
||||||
}
|
|
||||||
if ( !errorMessage.isEmpty() )
|
|
||||||
{
|
|
||||||
emit messageEmitted( tr( "Zoom to feature id failed" ), errorMessage, QgsMessageBar::WARNING );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsRectangle rect = mapSettings().layerExtentToOutputExtent( layer, geom->boundingBox() );
|
|
||||||
zoomToFeatureExtent( rect );
|
zoomToFeatureExtent( rect );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,10 +238,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
@param layer optionally specify different than current layer */
|
@param layer optionally specify different than current layer */
|
||||||
void zoomToSelected( QgsVectorLayer* layer = nullptr );
|
void zoomToSelected( QgsVectorLayer* layer = nullptr );
|
||||||
|
|
||||||
/** Set canvas extent to the bounding box of a feature
|
/** Set canvas extent to the bounding box of a set of features
|
||||||
@param layer the vector layer
|
@param layer the vector layer
|
||||||
@param id the feature id*/
|
@param ids the feature ids*/
|
||||||
void zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id );
|
void zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids );
|
||||||
|
|
||||||
/** Pan to the selected features of current (vector) layer keeping same extent. */
|
/** Pan to the selected features of current (vector) layer keeping same extent. */
|
||||||
void panToSelected( QgsVectorLayer* layer = nullptr );
|
void panToSelected( QgsVectorLayer* layer = nullptr );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user