Skip to content

Commit a75f9d2

Browse files
committed
Initial support for non-WGS-84 layers
1 parent b942557 commit a75f9d2

File tree

2 files changed

+24
-52
lines changed

2 files changed

+24
-52
lines changed

src/plugins/globe/qgsosgearthtilesource.cpp

+23-51
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,32 @@ using namespace osgEarth;
3030
using namespace osgEarth::Drivers;
3131

3232

33-
QgsOsgEarthTileSource::QgsOsgEarthTileSource( QgisInterface* theQgisInterface ) : TileSource(), mQGisIface(theQgisInterface)
33+
QgsOsgEarthTileSource::QgsOsgEarthTileSource( QgisInterface* theQgisInterface ) : TileSource(), mQGisIface(theQgisInterface), mCoordTranform(0)
3434
{
3535
}
3636

3737
void QgsOsgEarthTileSource::initialize( const std::string& referenceURI, const Profile* overrideProfile)
3838
{
3939
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() );
4059
}
4160

4261
osg::Image* QgsOsgEarthTileSource::createImage( const TileKey* key,
@@ -68,19 +87,13 @@ osg::Image* QgsOsgEarthTileSource::createImage( const TileKey* key,
6887
}
6988

7089
QgsMapRenderer* mainRenderer = mQGisIface->mapCanvas()->mapRenderer();
71-
mMapRenderer = new QgsMapRenderer();
7290
mMapRenderer->setLayerSet(mainRenderer->layerSet());
73-
mMapRenderer->setOutputUnits(mainRenderer->outputUnits());
7491

75-
if(configureMapRender( qImage) != 0)
76-
{
77-
return 0;
78-
}
92+
mMapRenderer->setOutputSize(QSize(qImage->width(), qImage->height()), qImage->logicalDpiX());
93+
7994
QgsRectangle mapExtent(xmin, ymin, xmax, ymax);
8095
mMapRenderer->setExtent(mapExtent);
8196

82-
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
83-
8497
QPainter thePainter(qImage);
8598
//thePainter.setRenderHint(QPainter::Antialiasing); //make it look nicer
8699
mMapRenderer->render(&thePainter);
@@ -105,48 +118,6 @@ osg::Image* QgsOsgEarthTileSource::createImage( const TileKey* key,
105118
return image.release();
106119
}
107120

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-
150121
QImage* QgsOsgEarthTileSource::createImage( int width, int height ) const
151122
{
152123
if( width < 0 || height < 0 )
@@ -193,5 +164,6 @@ bool QgsOsgEarthTileSource::intersects(const TileKey* key)
193164
double xmin, ymin, xmax, ymax;
194165
key->getGeoExtent().getBounds(xmin, ymin, xmax, ymax);
195166
QgsRectangle extent = mQGisIface->mapCanvas()->fullExtent();
167+
if (mCoordTranform) extent = mCoordTranform->transformBoundingBox(extent);
196168
return ! ( xmin >= extent.xMaximum() || xmax <= extent.xMinimum() || ymin >= extent.yMaximum() || ymax <= extent.yMinimum() );
197169
}

src/plugins/globe/qgsosgearthtilesource.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ namespace osgEarth { namespace Drivers
4545

4646
private:
4747

48-
int configureMapRender( const QPaintDevice* paintDevice ) const;
4948
QImage* createImage( int width, int height ) const;
5049
bool intersects(const TileKey* key);
5150

5251
//! Pointer to the QGIS interface object
5352
QgisInterface *mQGisIface;
53+
QgsCoordinateTransform *mCoordTranform;
5454
QgsMapRenderer* mMapRenderer;
5555

5656
};

0 commit comments

Comments
 (0)