@@ -30,13 +30,32 @@ using namespace osgEarth;
30
30
using namespace osgEarth ::Drivers;
31
31
32
32
33
- QgsOsgEarthTileSource::QgsOsgEarthTileSource ( QgisInterface* theQgisInterface ) : TileSource(), mQGisIface(theQgisInterface)
33
+ QgsOsgEarthTileSource::QgsOsgEarthTileSource ( QgisInterface* theQgisInterface ) : TileSource(), mQGisIface(theQgisInterface), mCoordTranform( 0 )
34
34
{
35
35
}
36
36
37
37
void QgsOsgEarthTileSource::initialize ( const std::string& referenceURI, const Profile* overrideProfile)
38
38
{
39
39
setProfile ( osgEarth::Registry::instance ()->getGlobalGeodeticProfile () );
40
+ QgsMapRenderer* mainRenderer = mQGisIface ->mapCanvas ()->mapRenderer ();
41
+ mMapRenderer = new QgsMapRenderer ();
42
+
43
+ long epsgGlobe = 4326 ;
44
+ if (mainRenderer->destinationSrs ().epsg () != epsgGlobe)
45
+ {
46
+ QgsCoordinateReferenceSystem srcCRS;
47
+ srcCRS.createFromEpsg (mainRenderer->destinationSrs ().epsg ()); // FIXME: crs from canvas or first layer?
48
+ QgsCoordinateReferenceSystem destCRS;
49
+ destCRS.createFromEpsg (epsgGlobe);
50
+ // QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectionsEnabled",1);
51
+ mMapRenderer ->setDestinationSrs (destCRS);
52
+ mMapRenderer ->setProjectionsEnabled (true );
53
+ mCoordTranform = new QgsCoordinateTransform ( srcCRS, destCRS );
54
+ }
55
+ mMapRenderer ->setOutputUnits (mainRenderer->outputUnits ());
56
+ mMapRenderer ->setMapUnits ( QGis::Degrees );
57
+
58
+ mMapRenderer ->setLabelingEngine ( new QgsPalLabeling () );
40
59
}
41
60
42
61
osg::Image* QgsOsgEarthTileSource::createImage ( const TileKey* key,
@@ -68,19 +87,13 @@ osg::Image* QgsOsgEarthTileSource::createImage( const TileKey* key,
68
87
}
69
88
70
89
QgsMapRenderer* mainRenderer = mQGisIface ->mapCanvas ()->mapRenderer ();
71
- mMapRenderer = new QgsMapRenderer ();
72
90
mMapRenderer ->setLayerSet (mainRenderer->layerSet ());
73
- mMapRenderer ->setOutputUnits (mainRenderer->outputUnits ());
74
91
75
- if (configureMapRender ( qImage) != 0 )
76
- {
77
- return 0 ;
78
- }
92
+ mMapRenderer ->setOutputSize (QSize (qImage->width (), qImage->height ()), qImage->logicalDpiX ());
93
+
79
94
QgsRectangle mapExtent (xmin, ymin, xmax, ymax);
80
95
mMapRenderer ->setExtent (mapExtent);
81
96
82
- mMapRenderer ->setLabelingEngine ( new QgsPalLabeling () );
83
-
84
97
QPainter thePainter (qImage);
85
98
// thePainter.setRenderHint(QPainter::Antialiasing); //make it look nicer
86
99
mMapRenderer ->render (&thePainter);
@@ -105,48 +118,6 @@ osg::Image* QgsOsgEarthTileSource::createImage( const TileKey* key,
105
118
return image.release ();
106
119
}
107
120
108
- int QgsOsgEarthTileSource::configureMapRender ( const QPaintDevice* paintDevice ) const
109
- {
110
- if (!mMapRenderer || !paintDevice)
111
- {
112
- return 1 ; // paint device is needed for height, width, dpi
113
- }
114
-
115
- mMapRenderer ->setOutputSize (QSize (paintDevice->width (), paintDevice->height ()), paintDevice->logicalDpiX ());
116
-
117
- QGis::UnitType mapUnits = QGis::Degrees;
118
-
119
- QgsCoordinateReferenceSystem outputCRS;
120
-
121
- if (true ) // TODO
122
- {
123
- // disable on the fly projection
124
- QgsProject::instance ()->writeEntry (" SpatialRefSys" ," /ProjectionsEnabled" ,0 );
125
- }
126
- else
127
- {
128
- // enable on the fly projection
129
- QgsDebugMsg (" enable on the fly projection" );
130
- QgsProject::instance ()->writeEntry (" SpatialRefSys" ," /ProjectionsEnabled" ,1 );
131
-
132
- long epsgId = 4326 ;
133
-
134
- // destination SRS
135
- // outputCRS = QgsEPSGCache::instance()->searchCRS( epsgId );
136
- if ( !outputCRS.isValid () )
137
- {
138
- QgsDebugMsg (" Error, could not create output CRS from EPSG" );
139
- return 5 ;
140
- }
141
- mMapRenderer ->setDestinationSrs (outputCRS);
142
- mMapRenderer ->setProjectionsEnabled (true );
143
- mapUnits = outputCRS.mapUnits ();
144
- }
145
- mMapRenderer ->setMapUnits ( mapUnits );
146
-
147
- return 0 ;
148
- }
149
-
150
121
QImage* QgsOsgEarthTileSource::createImage ( int width, int height ) const
151
122
{
152
123
if ( width < 0 || height < 0 )
@@ -193,5 +164,6 @@ bool QgsOsgEarthTileSource::intersects(const TileKey* key)
193
164
double xmin, ymin, xmax, ymax;
194
165
key->getGeoExtent ().getBounds (xmin, ymin, xmax, ymax);
195
166
QgsRectangle extent = mQGisIface ->mapCanvas ()->fullExtent ();
167
+ if (mCoordTranform ) extent = mCoordTranform ->transformBoundingBox (extent);
196
168
return ! ( xmin >= extent.xMaximum () || xmax <= extent.xMinimum () || ymin >= extent.yMaximum () || ymax <= extent.yMinimum () );
197
169
}
0 commit comments