Skip to content

Commit

Permalink
Partial fix for ticket #474 (crash with mixture of projections).
Browse files Browse the repository at this point in the history
Qgis no longer crashes, but the zoom to layer doesn't quite work all
of the time yet. Note that the toolbar zoom to layer works fine - it's
just the legend one that has problems.


git-svn-id: http://svn.osgeo.org/qgis/trunk@6341 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Dec 29, 2006
1 parent 5c94ec6 commit 546b8e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/gui/qgsmaplayer.cpp
Expand Up @@ -631,8 +631,10 @@ bool QgsMapLayer::projectExtent(QgsRect& extent, QgsRect& r2)
catch (QgsCsException &cse)
{
QgsLogger::warning("Transform error caught in " + QString(__FILE__) + ", line " + QString::number(__LINE__));
extent = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
r2 = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
// Return the untransformed extent when the transformation
// fails rather then the largest extent possible!
//extent = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
//r2 = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
}
}
return split;
Expand Down
46 changes: 16 additions & 30 deletions src/legend/qgslegend.cpp
Expand Up @@ -1687,59 +1687,45 @@ void QgsLegend::zoomToLayerExtent()
return;
}

double xmin = DBL_MAX;
double ymin = DBL_MAX;
double xmax = -DBL_MAX;
double ymax = -DBL_MAX;

QgsRect transformedExtent;
QgsRect layerExtent;
QgsCoordinateTransform *ct;
QgsRect r2;
QgsMapLayer* theLayer;
bool first(true);

for(std::list<QgsLegendLayerFile*>::iterator it= layerFiles.begin(); it != layerFiles.end(); ++it)
{
theLayer = (*it)->layer();
if(theLayer)
{
layerExtent = theLayer->extent();

if (QgsProject::instance()->readNumEntry("SpatialRefSys", "/ProjectionsEnabled",0) != 0
&& (ct = theLayer->coordinateTransform()))
{
//transform layer extent to canvas coordinate system
transformedExtent = ct->transform(layerExtent);
}
else
{
// do not transform when projections are not enabled
transformedExtent = layerExtent;
}

if(transformedExtent.xMin() < xmin)
if (theLayer->projectionsEnabled())
{
xmin = transformedExtent.xMin();
}

if(transformedExtent.yMin() < ymin)
{
ymin = transformedExtent.yMin();
// std::cerr<<__FILE__<<__LINE__<<' '
// << layerExtent.stringRep().toLocal8Bit().data() << '\n';

bool split = theLayer->projectExtent(layerExtent, r2);

// std::cerr<<__FILE__<<__LINE__<<' '
// << layerExtent.stringRep().toLocal8Bit().data() << '\n';
}

if(transformedExtent.xMax() > xmax)
if (first)
{
xmax = transformedExtent.xMax();
transformedExtent = layerExtent;
first = false;
}

if(transformedExtent.yMax() > ymax)
else
{
ymax = transformedExtent.yMax();
transformedExtent.combineExtentWith(&layerExtent);
}
}
}

//zoom to bounding box
mMapCanvas->setExtent(QgsRect(xmin, ymin, xmax, ymax));
mMapCanvas->setExtent(transformedExtent);
mMapCanvas->render();
mMapCanvas->refresh();
}
Expand Down

0 comments on commit 546b8e2

Please sign in to comment.