Offline Services for MapWinGis

MapWinGIS has a PrefetchToFolder function that can cache tiles to a specified file system folder for later offline use. This feature works great, but how can I load these tiles to create an offline map in the restricted area? Below is an example of using PrefetchToFolder:

        double y = 39;    // latitude, deg.
        double x = 140;     // longitude, deg.
        double span = 5;  // deg.
        Extents ext = new Extents();
        ext.SetBounds(x - span, y - span, 0.0, x + span, y + span, 0.0);
        axMap1.Tiles.PrefetchToFolder(ext, 8, 0, @"c:\map1", ".png", StopFunction());

      

My programming language is C #.

Here's the code that you can get, but cannot load:

    private void btnLoad_Click(object sender, EventArgs e)
    {
        TileProviders providers = axMap1.Tiles.Providers; ;
        int providerId = (int)tkTileProvider.ProviderCustom + 1;    
        providers.Add(providerId, "MyProvider", @"file:///C|/map1/{zoom}/{x}/{y}.png", tkTileProjection.SphericalMercator, 1, 18);

        axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
        axMap1.TileProvider = tkTileProvider.ProviderCustom;
        axMap1.Tiles.ProviderId = providerId;

        axMap1.Latitude = 39;
        axMap1.Longitude = 140;
        axMap1.CurrentZoom = 8;

    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        double y = 39;    // latitude, deg.
        double x = 140;     // longitude, deg.
        double span = 5;  // deg.
        Extents ext = new Extents();
        ext.SetBounds(x - span, y - span, 0.0, x + span, y + span, 0.0);
       axMap1.Tiles.PrefetchToFolder(ext,1 , 0, @"c:\map1", ".png", StopFunction());
    }

      

+3


source to share


4 answers


you must use a server for this. For example: maperver

for windows:

1) download ms4w: http://www.maptools.org/ms4w/index.phtml?page=downloads.html

2) extract the root directory (c: / ms4w)

3) Start the MS4W Apache web server by running / ms 4w / apache-install.bat (from the command line or by double clicking on it). This file installs Apache as a Windows service (called the "Apache Web Server") so that it starts up whenever your computer is restarted. When executing a DOS window, the following message should appear:

Installing the Apache MS4W Web Server service
The Apache MS4W Web Server service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service
can be started.
The Apache MS4W Web Server service is starting.
The Apache MS4W Web Server service was started successfully.

      

4) copy chunk files / ms 4w / Apache / htdocs / maps



5) Then you should see these files in http: // localhost / maps

splitting chunk files :

I am using mapertive for this process. This program is free and creates an open map. this is the link: http://maperitive.net/

Sample code:

    TileProviders providers = axMap1.Tiles.Providers; ;
    int providerId = (int)tkTileProvider.ProviderCustom + 1;    
    providers.Add(providerId, "MyProvider", "http:/localhost/maps/{zoom}/{x}/{y}.png", tkTileProjection.SphericalMercator, 1, 18);

    axMap1.Tiles.ProviderId = providerId;
    axMap1.CurrentZoom = 8;

      

result =

enter image description here

+1


source


Yes, this solution works. Check the return value of the add providers method, if false, change the value to +1 and try again, or try changing the forecast to wsg84. maybe the map is added, but you didn't see it because of your zoom level, so add in your code map.zoomToTileLevel (1) instead of currentzoom

Melih tanks. As you said, I've tested everything (except wsg84, which I don't know anything about) but still can't see the map! Here is my code:

        axMap1.CtlbackColor = Color.Transparent;
        TileProviders providers = axMap1.Tiles.Providers;
        int providerId = (int)tkTileProvider.ProviderCustom + 100;
        //providers.Add(providerId, "Custom TMS provider", "http://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png", tkTileProjection.SphericalMercator, 1, 18);
        providers.Add(providerId, "CustomTMSprovider", @"http://localhost/maps/Tiles/{zoom}/{x}/{y}.png", tkTileProjection.SphericalMercator, 1, 18);
        axMap1.Tiles.ProviderId = providerId;
        axMap1.Projection = tkMapProjection.PROJECTION_WGS84;
        axMap1.GrabProjectionFromData = true;
        axMap1.ZoomBehavior = tkZoomBehavior.zbUseTileLevels;
        axMap1.ZoomToTileLevel(2);

      



If I change provider everything works fine, but that provider cannot load the map. As I said, the local tile server works well. Thanks again for your efforts.

My conclusion

0


source


change your url http: / localhost / ... as http: // localhost / ... you missed the '/'

0


source


I am doing this process and I cannot load the map, I have tiles in map.mbtiles from maperitive, but how can I show this: I need to export a .mbtiles file to .png? as..

" http: // localhost / maps / Tiles / {zoom} / {x} / {y} .png"

-1


source







All Articles