Connecting to local offline OSM server?

Dec 31, 2012 at 8:25 AM

I put together a local Ubuntu based OSM server in a VMWare container based on the mostly complete instructions here:

http://wiki.planimate.com/Tile_Server_%282012%29#Install_prepared_world_boundary_data

Since my Sharpmap project will not be connected to the internet, I want to use that server as the repository for the tiles.  However, I can't figure out how to connect to a local server by it's IP address (192.168.1.120).  Can someone give me the instructions on how to connect to it?  In my project, the "normal" way works fine for the online servers.

 

TileAsyncLayer osmLayer = new TileAsyncLayer(new OsmTileSource(), "TileLayer - OSM");

Thanks,

Dirk
Coordinator
Jan 3, 2013 at 4:36 PM

hmm, you could work around it with a custom tile provider. Like this:

    public class CustomOsmTileSource : TileSource
    {
        public CustomOsmTileSource()
            : base(new WebTileProvider(
                new TmsRequest("http://{S}.localhost", "png", new[] { "a", "b", "c" })),
            new SphericalMercatorInvertedWorldSchema())
        {
        }

        public Extent Extent { get { return Schema.Extent; } }
    } 

I should improve this to allow to insert just a custom url as string.

Paul

Jan 4, 2013 at 6:27 AM
Edited Jan 4, 2013 at 6:28 AM

Hey Paul,

Well I'm closer when I use this code:

 

    public class CustomOsmTileSource : TileSource
    {
        public CustomOsmTileSource(string sIP)
            : base(new WebTileProvider(
                new TmsRequest("http://{S}." + sIP, "png", new[] { "a", "b", "c" })),
            new SphericalMercatorInvertedWorldSchema())
        {

        }

        public Extent Extent { get { return Schema.Extent; } }
    } 

 

And this call:

 TileAsyncLayer osmLayer = new TileAsyncLayer(new CustomOsmTileSource("192.168.1.120"), "TileLayer - OSM");

However, where the tiles would normally show up on the map, I'm getting a bunch of: "The remote name could not be resolved: a.192.168.1.120" (with the 'a' part also containing 'b' & 'c' obviously too).

What I do know is that on that VMWare OSM server, I can go and browse the tiles by the following URL format: http://192.168.1.120/osm_tiles/0/0/0.png (which returns to me the map of the entire world).  Any way to set up that constructor to handle this sort of format rather than the a/b/c type?

Thanks,

Dirk

Developer
Jan 4, 2013 at 7:18 AM
dirkkaiser wrote:

What I do know is that on that VMWare OSM server, I can go and browse the tiles by the following URL format: http://192.168.1.120/osm_tiles/0/0/0.png (which returns to me the map of the entire world).  Any way to set up that constructor to handle this sort of format rather than the a/b/c type?

But can you get the tiles from the browser on the machine that eventually should use brutile? Maybe some firewall/access restrictions or virtual network configuration problem?

Not knowing which version of BruTile you use (0.6.4?), there may be an OsmTileServerConfig class that you can use to setup your OsmTileSource

var osmConfig = new OsmTileServerConfig("http://192.168.1.100/{0}/{1}/{2}/{3}", 1, new[] {"osm_tiles"}, 4, 9);
var osmRequest = new OsmRequest(osmConfig);
var osmSource = new OsmTileSource(osmRequest, new MemoryCache<byte[]>(100, 200));

Note: The parameters 4 and 9 are the minimum and maximum zoom level

If that is not available, you need to setup your CustomOsmTileSource with a request like this:

var req = new TmsRequest("http://192.168.1.100/{S}", "png", new [] { "osm_tiles" });

Hth FObermaier

Jan 5, 2013 at 8:31 AM
Edited Jan 5, 2013 at 8:40 AM

 

Hey FObermaier,

I just tried your second one as I'm running the 0.6.4 Brutile version.  And it worked!  Thanks SO much.!  Final code for anyone else looking to do this:

 

    public class CustomOsmTileSource : TileSource
    {
        public CustomOsmTileSource(string sIP)
            : base(new WebTileProvider(
                new TmsRequest("http://" + sIP + "/{S}", "png", new[] { "osm_tiles" })),
            new SphericalMercatorInvertedWorldSchema())
        {

        }


        public Extent Extent { get { return Schema.Extent; } }
    } 

 

And the call:

 

                    TileAsyncLayer osmLayer = new TileAsyncLayer(new CustomOsmTileSource("192.168.1.120"), "TileLayer - OSM");
                    this.mapBox1.Map.BackgroundLayer.Add(osmLayer);

 

Gets you this image:  https://picasaweb.google.com/geodirk/Prepar3D_OSM#5829893040251828850

 

Thanks again for the help!

- Dirk

Coordinator
Jan 9, 2013 at 2:15 PM

@dirkkaiser thanks for reporting back!

@FObermaier thanks for helper out over here :)

May 22, 2013 at 2:55 PM
Hi,
This thread is very useful.

If I want to use my PostgresSQL as my server, how do I set it up? I'm not being lazy, I just want to be redirected to the right information

Thank you very much.