简体   繁体   English

MapWinGis的离线平铺服务

[英]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. MapWinGIS具有PrefetchToFolder功能,可以将切片缓存到指定的文件系统文件夹以供进一步离线使用。 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 : 以下是使用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#. 我的编程语言是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 例如: mapserver

for windows : 对于Windows:

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

2) extract the root directory (c:/ms4w) 2)解压根目录(c:/ ms4w)

3)Start your MS4W Apache Web Server by running /ms4w/apache-install.bat (at the command line or by double-clicking it). 3)运行/ms4w/apache-install.bat(在命令行或双击它)启动MS4W Apache Web服务器。 This file installs Apache as a Windows service (called "Apache Web Server") so that it starts whenever your machine is restarted. 此文件将Apache安装为Windows服务(称为“Apache Web Server”),以便在重新启动计算机时启动它。 When executed, a DOS window should pop up with the following message: 执行时,应弹出DOS窗口,并显示以下消息:

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 4)复制tile文件/ ms4w / Apache / htdocs / maps

5) Then you should see this files in the http://localhost/maps 5)然后你应该在http:// localhost / maps中看到这些文件

tiles file genaration : 瓷砖文件genaration

For this process I use mapertive. 对于这个过程,我使用mapertive。 This program free and generate openstreet map. 这个程序免费并生成openstreet地图。 this is the link : http://maperitive.net/ 这是链接: 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. 请检查提供者添加方法的返回值,如果值为false,则更改+1值并再次尝试或尝试将投影更改为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 也许地图已添加但你没看到因为你的缩放级别所以在代码中添加map.zoomToTileLevel(1)行而不是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! 坦克Melih,正如你所说,我检查了所有的东西(除了wsg84,我对此一无所知)但仍然看不到地图! 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. 正如我所说, tile本地服务器运行良好。 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? 我正在做这个过程,我无法加载地图,我有来自maperitive的map.mbtiles中的tile,但我怎么能显示它:我必须将我的文件.mbtiles导出到.png? as.. 如..

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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