Support of customized MapSource in MapSourceMgr

2 posts / 0 new
Last post
poocka
poocka's picture
Offline
Joined: 6 Apr 2010
Posts:
Support of customized MapSource in MapSourceMgr

Creation of custom map source is impossible even after adding new MapSource type into MapSourceKind enum.
The project will compile however at runtime will fail, because singletone object MapSourceMgr that is lays in bundled library MAP has no way to handle (or knowing) new map type.

The constructor contents:

         //-------------------------------------------------------------------------
        MapSourceMgr::MapSourceMgr( ) :
        //-------------------------------------------------------------------------
                mMap( )
        {
                for ( int i = 0; i < MapSourceKind_Last; i++ )
                        mMap[(MapSourceKind)i] = NULL;

                mMap[MapSourceKind_OpenStreetMap] = newobject( OpenStreetMapSource, new OpenStreetMapSource( ) );
                mMap[MapSourceKind_GoogleMap] = newobject( GoogleMapSource, new GoogleMapSource( GoogleMapsMapKind_StreetMap ) );
                mMap[MapSourceKind_GoogleAerial] = newobject( GoogleMapSource, new GoogleMapSource( GoogleMapsMapKind_Aerial ) );
                mMap[MapSourceKind_GoogleHybrid] = newobject( GoogleMapSource, new GoogleMapSource( GoogleMapsMapKind_Hybrid ) );
                mMap[MapSourceKind_CloudMade1] = newobject( CloudMadeMapSource, new CloudMadeMapSource( 1 ) );
                mMap[MapSourceKind_CloudMade7] = newobject( CloudMadeMapSource, new CloudMadeMapSource( 7 ) );
                //mMap[MapSourceKind_VirtualEarth] = newobject( VirtualEarthMapSource, new VirtualEarthMapSource( ) );
        }

So as it shown - no instances of other types created, then letter when Widget will try to set map source to new one application will crash.

It would be wise to add an method to add/remove MapSource types at run time. Since all of that type maps differs in source of tiles it may be better to no create SourceType class for each map (google, OSM ... ) but to add just tile's URL template, as it done in JavaScript API of those map engines.
I mean:
instead of

        void OpenStreetMapSource::getTileUrl( char* buffer, MapTileCoordinate tileXY )
        //-------------------------------------------------------------------------
        {
                sprintf( buffer, "http://tile.openstreetmap.org/%d/%d/%d.png", tileXY.getMagnification( ), tileXY.getX( ), tileXY.getY( ) );
        }

have something like:

        void GenericMapSource::setTileUrlTemplate(char *buffer){
              mTileUrlTemplate = buffer; // buffer="http://tile.openstreetmap.org/%d/%d/%d.png"
        }
        void GenericMapSource::getTileUrl( char* buffer, MapTileCoordinate tileXY )
        //-------------------------------------------------------------------------
        {
                sprintf( buffer, mTileUrlTemplate, tileXY.getMagnification( ), tileXY.getX( ), tileXY.getY( ) );
        }

So the Developer may change tiles on the fly (like day/night map ).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
larsv
larsv's picture
Offline
Joined: 27 Oct 2008
Posts:

Yeah that's a known (but not well documented) limitation in this first rev. Thanks for the reminder.

MapSourceMgr should have a dynamic list of map sources.