Re: Localhost map source



On Thu, Oct 6, 2011 at 11:06, Gerard Toonstra <gtoonstra gmail com> wrote:
> Hello,
>
> This may be useful to others as well and hopefully this may lead the
> developers to rethink some of the API on map sources.
>
> I'm using the gtkChamplain widget to display a map in a python based app.
> Rather than using the standard openstreetmap url, I rendered my own
> tiles and wanted to redirect the mapview to use localhost for that purpose.
>
> In C and with a bit of digging in the sources, it's not too difficult to
> figure out a way to do this using the factory and mapsourcedesc objects.
> In python however, I got stuck somewhere and then figured out this way to
> use a mapchain created outside of the factory, which is set on the mapview
> instead:
>
> ---------------------------------
>
>         map_chain = Champlain.MapSourceChain()
>
>         errorRenderer = Champlain.ErrorTileRenderer.new( 256 )
>         null_source = Champlain.NullTileSource.new_full( errorRenderer )
>         map_chain.push( null_source )
>
>         imgrenderer = Champlain.ImageRenderer()
>         tile_source = Champlain.NetworkTileSource.new_full(
>             "Localhost",
>             "Localhost sources",
>             "license",
>             "license-uri",
>             0,
>             17,
>             256,
>             Champlain.MapProjection.MAP_PROJECTION_MERCATOR,
>             "http://localhost/tiles/#Z#/#X#/#Y#.png";,
>             imgrenderer )
>         map_chain.push( tile_source )
>
>         map_chain.push( Champlain.FileCache.new_full( 100000000, None,
> imgrenderer ) )
>         map_chain.push( Champlain.MemoryCache.new_full( 100, imgrenderer ))
>
>         self.view.set_map_source( map_chain )
>
> ---------------------------------------------
>
> Hope that helps someone.
>

By the way if you have some really specific needs for map sources, you
can implement your own map source by implementing the
ChamplainMapSource abstract class and setting it as map source using
set_map_source. The most important method is fill_tile() where you
pass the tile with requested coordinates and which should set the tile
to the corresponding image.

It's a bit more difficult if you want to support the current chain
mechanism and use the caching for example.

Jiri


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]