From c94a18c603c20139a803ea732d83d284f34c7609 Mon Sep 17 00:00:00 2001 From: gsherman Date: Sat, 27 Jul 2002 06:16:51 +0000 Subject: [PATCH] fixes to rendering code git-svn-id: http://svn.osgeo.org/qgis/trunk@45 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgscoordinatetransform.cpp | 3 ++- src/qgsmapcanvas.cpp | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/qgscoordinatetransform.cpp b/src/qgscoordinatetransform.cpp index d9d8f4acf4b..90fd06b2615 100644 --- a/src/qgscoordinatetransform.cpp +++ b/src/qgscoordinatetransform.cpp @@ -28,7 +28,8 @@ QgsCoordinateTransform::~QgsCoordinateTransform(){ QgsPoint QgsCoordinateTransform::transform(QgsPoint p){ // transform x double dx = (p.x() - xMin)/mapUnitsPerPixel; - double dy = (yMax - (p.y() - yMin))/mapUnitsPerPixel; + double dy = yMax - ((p.y() - yMin))/mapUnitsPerPixel; + // double dy = (yMax - (p.y() - yMin))/mapUnitsPerPixel; return QgsPoint(dx,dy); } diff --git a/src/qgsmapcanvas.cpp b/src/qgsmapcanvas.cpp index a72668b6b48..e6855704728 100644 --- a/src/qgsmapcanvas.cpp +++ b/src/qgsmapcanvas.cpp @@ -36,7 +36,9 @@ void QgsMapCanvas::addLayer(QgsMapLayer *lyr){ // update extent if warranted if(layers.size() == 1){ fullExtent = lyr->extent(); + fullExtent.scale(1.1); currentExtent = fullExtent; + } // set zpos to something... @@ -53,9 +55,22 @@ void QgsMapCanvas::render2(){ muppX = currentExtent.width()/width(); cout << "MuppX is: " << muppX << "\nMuppY is: " << muppY << endl; m_mupp = muppY > muppX?muppY:muppX; - m_mupp *= 1.20; - coordXForm->setParameters(m_mupp, currentExtent.xMin(), - currentExtent.yMin(), currentExtent.yMax()); + // calculate the actual extent of the mapCanvas + double dxmin,dymin,dymax,whitespace; + if(muppY > muppX){ + dymin = currentExtent.yMin(); + dymax = currentExtent.yMax(); + whitespace = ((width() *m_mupp) - currentExtent.width())/2; + dxmin = currentExtent.xMin() - whitespace; + }else{ + dxmin = currentExtent.xMin(); + whitespace = ((height() *m_mupp) - currentExtent.height())/2; + dymin = currentExtent.yMin() - whitespace; + dymax = currentExtent.yMax() + whitespace; + + } + cout << "dxmin: " << dxmin << endl << "dymin: " << dymin << endl << "dymax: " << dymax << endl << "whitespace: " << whitespace << endl; + coordXForm->setParameters(m_mupp, dxmin,dymin,height()); //currentExtent.xMin(), currentExtent.yMin(), currentExtent.yMax()); // render all layers in the stack, starting at the base map::iterator mi = layers.begin(); while(mi != layers.end()){