File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -697,9 +697,19 @@ void QgsMapCanvas::resizeEvent(QResizeEvent * e)
697
697
int width = e->size ().width (), height = e->size ().height ();
698
698
// int width = visibleWidth(), height = visibleHeight();
699
699
mCanvas ->resize (width, height);
700
-
700
+
701
+ // Adjust the size (in pixels) of that we draw by the margins in
702
+ // the widget that the drawing eventually gets placed in. In my testing
703
+ // the margin was 2 pixels on each border. Add 1 more pixel just to
704
+ // be sure that the drawn map appears fully within the margins in
705
+ // the widget.
706
+ int top, bottom, right, left;
707
+ getContentsMargins (&left, &top, &right, &bottom);
708
+ width = width - (left + right + 1 );
709
+ height = height - (top + bottom + 1 );
710
+
701
711
mMap ->resize (/* e->size()*/ QSize (width,height));
702
-
712
+
703
713
// notify canvas items of change
704
714
updateCanvasItemsPositions ();
705
715
Original file line number Diff line number Diff line change @@ -123,8 +123,10 @@ void QgsMapRender::adjustExtentToSize()
123
123
124
124
// calculate the translation and scaling parameters
125
125
// mupp = map units per pixel
126
- double muppY = mExtent .height () / myHeight;
127
- double muppX = mExtent .width () / myWidth;
126
+ double muppY = static_cast <double >(mExtent .height ())
127
+ / static_cast <double >(myHeight);
128
+ double muppX = static_cast <double >(mExtent .width ())
129
+ / static_cast <double >(myWidth);
128
130
mMupp = muppY > muppX ? muppY : muppX;
129
131
130
132
// calculate the actual extent of the mapCanvas
@@ -134,15 +136,15 @@ void QgsMapRender::adjustExtentToSize()
134
136
{
135
137
dymin = mExtent .yMin ();
136
138
dymax = mExtent .yMax ();
137
- whitespace = ((myWidth * mMupp ) - mExtent .width ()) / 2 ;
139
+ whitespace = ((myWidth * mMupp ) - mExtent .width ()) * 0.5 ;
138
140
dxmin = mExtent .xMin () - whitespace;
139
141
dxmax = mExtent .xMax () + whitespace;
140
142
}
141
143
else
142
144
{
143
145
dxmin = mExtent .xMin ();
144
146
dxmax = mExtent .xMax ();
145
- whitespace = ((myHeight * mMupp ) - mExtent .height ()) / 2 ;
147
+ whitespace = ((myHeight * mMupp ) - mExtent .height ()) * 0.5 ;
146
148
dymin = mExtent .yMin () - whitespace;
147
149
dymax = mExtent .yMax () + whitespace;
148
150
}
@@ -165,7 +167,7 @@ void QgsMapRender::adjustExtentToSize()
165
167
mExtent .setXmax (dxmax);
166
168
mExtent .setYmin (dymin);
167
169
mExtent .setYmax (dymax);
168
-
170
+
169
171
// update the scale
170
172
updateScale ();
171
173
You can’t perform that action at this time.
0 commit comments