osgEarth 2.1.1
Public Member Functions | Private Attributes

TMSSource Class Reference

Inheritance diagram for TMSSource:
Collaboration diagram for TMSSource:

List of all members.

Public Member Functions

 TMSSource (const TileSourceOptions &options)
void initialize (const std::string &referenceURI, const Profile *overrideProfile)
osg::Image * createImage (const osgEarth::TileKey &key, ProgressCallback *progress)
virtual int getPixelsPerTile () const
virtual std::string getExtension () const

Private Attributes

osg::ref_ptr< TileMap_tileMap
bool _invertY
const TMSOptions _options

Detailed Description

Definition at line 45 of file ReaderWriterTMS.cpp.


Constructor & Destructor Documentation

TMSSource::TMSSource ( const TileSourceOptions options) [inline]

Definition at line 48 of file ReaderWriterTMS.cpp.

                                                : TileSource(options), _options(options)
    {
        _invertY = _options.tmsType() == "google";
    }

Member Function Documentation

osg::Image* TMSSource::createImage ( const osgEarth::TileKey key,
ProgressCallback progress 
) [inline, virtual]

Creates an image for the given TileKey. The returned object is new and is the responsibility of the caller.

Implements osgEarth::TileSource.

Definition at line 130 of file ReaderWriterTMS.cpp.

    {
        if (_tileMap.valid() && key.getLevelOfDetail() <= getMaxDataLevel() )
        {
            std::string image_url = _tileMap->getURL( key, _invertY );
                
            //OE_NOTICE << "TMSSource: Key=" << key.str() << ", URL=" << image_url << std::endl;

            
            osg::ref_ptr<osg::Image> image;
            
            if (!image_url.empty())
            {
                HTTPClient::readImageFile( image_url, image, 0L, progress ); //getOptions(), progress );
            }

            if (!image.valid())
            {
                if (image_url.empty() || !_tileMap->intersectsKey(key))
                {
                    //We couldn't read the image from the URL or the cache, so check to see if the given key is less than the max level
                    //of the tilemap and create a transparent image.
                    if (key.getLevelOfDetail() <= _tileMap->getMaxLevel())
                    {
                        OE_INFO << LC << "Returning empty image " << std::endl;
                        return ImageUtils::createEmptyImage();
                    }
                }
            }
            return image.release();
        }
        return 0;
    }

Here is the call graph for this function:

virtual std::string TMSSource::getExtension ( ) const [inline, virtual]

Gets the preferred extension for this TileSource

Reimplemented from osgEarth::TileSource.

Definition at line 170 of file ReaderWriterTMS.cpp.

    {
        return _tileMap->getFormat().getExtension();
    }
virtual int TMSSource::getPixelsPerTile ( ) const [inline, virtual]

Gets the number of pixels per tile for this TileSource.

Reimplemented from osgEarth::TileSource.

Definition at line 165 of file ReaderWriterTMS.cpp.

    {
        return _tileMap->getFormat().getWidth();
    }
void TMSSource::initialize ( const std::string &  referenceURI,
const Profile overrideProfile 
) [inline, virtual]

Initialize the TileSource. The profile should be computed and set here using setProfile()

Implements osgEarth::TileSource.

Definition at line 54 of file ReaderWriterTMS.cpp.

    {
        const Profile* result = NULL;

        URI tmsURI = _options.url().value();
        if ( tmsURI.empty() )
        {
            OE_WARN << LC << "Fail: TMS driver requires a valid \"url\" property" << std::endl;
            return;
        }

        //Find the full path to the URL
        //If we have a relative path and the map file contains a server address, just concat the server path and the url together
        if (osgEarth::isRelativePath(tmsURI.full()) && osgDB::containsServerAddress(referenceURI))
        {
            tmsURI = URI( osgDB::getFilePath(referenceURI) + std::string("/") + tmsURI.full() );
        }

        //If the path doesn't contain a server address, get the full path to the file.
        if (!osgDB::containsServerAddress(tmsURI.full()))
        {
            tmsURI = URI( tmsURI.full(), referenceURI );
            //tmsPath = osgEarth::getFullPath(referenceURI, tmsURI);
        }

                // Attempt to read the tile map parameters from a TMS TileMap XML tile on the server:
        _tileMap = TileMapReaderWriter::read( tmsURI.full(), 0L ); //getOptions() );


                //Take the override profile if one is given
                if (overrideProfile)
                {
                    OE_INFO << LC << "Using override profile " << overrideProfile->toString() << std::endl;                             
                        result = overrideProfile;
                        _tileMap = TileMap::create( 
                _options.url()->full(),
                overrideProfile, 
                _options.format().value(),
                _options.tileSize().value(), 
                _options.tileSize().value() );
                }
                else
                {
                if (_tileMap.valid())
                        {
                                result = _tileMap->createProfile();
                        }
                        else
                        {
                OE_WARN << LC << "Error reading TMS TileMap, and no overrides set (url=" << tmsURI.full() << ")" << std::endl;          
                            return;
                        }
                }

        //Automatically set the min and max level of the TileMap
        if (_tileMap.valid() && _tileMap->getTileSets().size() > 0)
        {
          OE_INFO << LC << "TileMap min/max " << _tileMap->getMinLevel() << ", " << _tileMap->getMaxLevel() << std::endl;
          if (_tileMap->getDataExtents().size() > 0)
          {
              for (DataExtentList::iterator itr = _tileMap->getDataExtents().begin(); itr != _tileMap->getDataExtents().end(); ++itr)
              {
                  this->getDataExtents().push_back(*itr);
              }
          }
          else
          {
              //Push back a single area that encompasses the whole profile going up to the max level
              this->getDataExtents().push_back(DataExtent(result->getExtent(), 0, _tileMap->getMaxLevel()));
          }
        }

                setProfile( result );
    }

Here is the call graph for this function:


Member Data Documentation

bool TMSSource::_invertY [private]

Definition at line 178 of file ReaderWriterTMS.cpp.

Reimplemented from osgEarth::TileSource.

Definition at line 179 of file ReaderWriterTMS.cpp.

osg::ref_ptr<TileMap> TMSSource::_tileMap [private]

Definition at line 177 of file ReaderWriterTMS.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines