简体   繁体   中英

Offline tile services for MapWinGis

MapWinGIS has a function for PrefetchToFolder which can Caches tiles to the specified file system folder for further offline use. This function works perfectly, But how can I load that tiles for creating offline map in a restricted area? Here is a sample 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 is some code which can fetch but can't 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());
    }

you should use server for this. forexample : mapserver

for windows :

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

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

3)Start your MS4W Apache Web Server by running /ms4w/apache-install.bat (at the command line or by double-clicking it). This file installs Apache as a Windows service (called "Apache Web Server") so that it starts whenever your machine is restarted. When executed, a DOS window should pop up with the following message:

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 tile files /ms4w/Apache/htdocs/maps

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

tiles file genaration :

For this process I use mapertive. This program free and generate openstreet map. this is the link : http://maperitive.net/

Code Example :

    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 =

在此输入图像描述

Yes this solution works. Please check the return value of providers add method if the value is false change the +1 value and try again or try to change projection to wsg84. maybe map is added but you didnt see because of your zoom level so add the map.zoomToTileLevel(1) line in your code instead of currentzoom

Tanks Melih, As you told, I checked every things (except wsg84, which I don't know anything about that) but still can't see 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 the provider everything works perfectly but this provider can't load map. As I told, tile local server works good. Thanks again for your effort.

我的输出

将您的URL http:/ localhost / ...更改为http:// localhost / ...您错过了'/'

I'm doing this process and I can not load the map, i have the tiles in map.mbtiles from maperitive but how i can show it: i have to export my file .mbtiles to .png? as..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM