如何使用MOBAC OSMDroid SQLite的瓷砖源文件离线产生的? [英] How to use MOBAC created OSMDroid SQLite tile source file offline?

查看:827
本文介绍了如何使用MOBAC OSMDroid SQLite的瓷砖源文件离线产生的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在拉我的头发试图让自己的下线移动阿特拉斯造物主OSMDroid的SQLite地图与OSMDroid 3.0.8没有运气的工作。这是一个漫长的3天。我会尝试从我的应用程序片段来解释。我一直延伸ItemizedIconOverlay和OverlayItem所以我希望它不会太混乱了。

我创造了我自己的OSMDroid的SQLite地图有3个不同的缩放级别文件的一个小的,像10平方公里。我复制产生的base.sqlite文件到我的项目/ RES /生/目录。请注意,在我的应用程序的GeoPoints应该完全在地图上的瓦范围内。而base.sqlite文件应该被保存到应用程序特定的数据目录。

接下来我草皮上我的电话/ osmdroid目录中,以便我能得到previously缓存地图了。我想我有我自己的离线地图工作,直到我打开飞行模式,发现缓存的地图仍然可用。

现在我得到的是空白。我不知道如何得到这个正在进行。我已经看到了几个例子,但一吨的实验后,我还没有成功地让其中的任何工作。

 私人哈希表<字符串,NodeOverlayItem>节点=新的Hashtable<字符串,NodeOverlayItem>();

私人图形页面图形页面;
私人上下文的背景下;

私人LocationManager locManager;

私人MapController mapController;
私人MapTileProviderArray mapProvider;
私人字符串mapTileArchivePath =base.sqlite;

私人ResourceProxy resourceProxy;

@覆盖
公共无效的onCreate(最终捆绑savedInstanceState){
    super.onCreate(savedInstanceState);

    尝试 {
        this.mapView =新的图形页面(本,256);
        this.mapView.setBuiltInZoomControls(真正的);
        this.mapView.setMultiTouchControls(真正的);

        this.context = this.getApplicationContext();
        this.resourceProxy =新DefaultResourceProxyImpl(上下文);

        XYTileSource TILERENDERER =新XYTileSource(测试,
            ResourceProxy.string.offline_mode,
            1,20,256,.PNG,http://127.0.0.1);
        SimpleRegisterReceiver simpleReceiver =新SimpleRegisterReceiver(this.context);

        IArchiveFile []档案= {ArchiveFileFactory.getArchiveFile(this.getMapsFile())};
        MapTileModuleProviderBase moduleProvider =新MapTileFileArchiveProvider(
                simpleReceiver,
                TILERENDERER,
                档案);
        this.mapProvider =新MapTileProviderArray(TILERENDERER,空,新MapTileModuleProviderBase [] {m​​oduleProvider});
        this.mapProvider.setUseDataConnection(假);
        this.mapView =新的图形页面(本,256,this.resourceProxy,this.mapProvider);
        this.mapView.setUseDataConnection(假);

        mapController = mapView.getController();
        mapController.setZoom(18);
        mapController.setCenter(新的GeoPoint((int)的(45.349622 * 1E6),(int)的( -  75.880700 * 1E6)));

        this.setContentView(图形页面);
    }赶上(例外前){
        Log.e(测试,ex.getMessage());
    }
}


公共文件getMapsFile()抛出IOException异常{
    Log.d(测试,试图加载地图图块为:+ this.mapTileArchivePath);
    FileOutputStream中FOS = this.openFileOutput(this.mapTileArchivePath,Context.MODE_PRIVATE);

    InputStream的时间= getResources()openRawResource(R.raw.osmdroid)。
    byte []的BUFF =新的字节[1024];
    INT读= 0;
    尝试 {
    而((读= in.read(BUFF))大于0){
      fos.write(BUFF,0,读);
    }
    } 最后 {
      附寄();
      fos.close();
    }
    返回新的文件(this.getFilesDir(),this.mapTileArchivePath);
    }
 

解决方案

OK!我知道我做错了,我拥有这一切,现在的工作! (我很高兴:)

首先,我有写我的原始资源映射文件到应用程序特定的目录中的一些麻烦(如openFileOutput()),我使用Galaxy Nexus的不具备一个SD插槽,所以我不能倾倒地图文件到SD。确保映射文件要使用的字节与原件相比。 Eclipse的DDMS角度来看是非常有用的查看设备的文件结构。

我也切换到OSMdroid Zip格式。然后我确定XYTileSource()名匹配由MOBAC Zip文件创建的目录,以及保证了瓷砖的大小和缩放级别的比赛。

  XYTileSource TILERENDERER =新XYTileSource(OSM CloudMade 1,ResourceProxy.string.offline_mode,16,18,256,png格式,http://127.0.0.1 );
 

MOBAC默认会创建256像素的瓷砖。我创建了一个图谱文件,16,17,18缩放级别。 PNG是默认MOBAC平铺图像格式。

另外,如果你的地图文件有任何问题,ArchiveFileFactory.getArchiveFile()会赶上他们,甚至在MapTileFileArchiveProvider。

下面是我的使用情况。只是尽一切努力正确地得到您的IArchive设置,你应该确定:

  XYTileSource TILERENDERER =新XYTileSource(OSM CloudMade 1,ResourceProxy.string.offline_mode,16,18,256,png格式,http://127.0.0.1 );
        SimpleRegisterReceiver simpleReceiver =新SimpleRegisterReceiver(this.context);
        IArchiveFile []档案= {ArchiveFileFactory.getArchiveFile(this.getMapsSdCard())};
        MapTileModuleProviderBase moduleProvider =新MapTileFileArchiveProvider(
                simpleReceiver,
                TILERENDERER,
                档案);
        this.mapProvider =新MapTileProviderArray(TILERENDERER,空,新MapTileModuleProviderBase [] {m​​oduleProvider});
        this.mapProvider.setUseDataConnection(假);
        this.mapView =新的图形页面(本,256,this.resourceProxy,this.mapProvider);
        this.mapView.setUseDataConnection(假);
 

也许我是唯一一个谁曾与这个麻烦,但osmdroid没有清楚地记录如何做到这一点,当我打开的问题,我不能让他们对我的使用意见。如果他们说我是正确实施MapTileFileArchiveProvider或包括良好的脱机映射样,我会专注于一切首位。

I've been pulling my hair out trying to get my own offline Mobile Atlas Creator OSMDroid SQLite map working with OSMDroid 3.0.8 without luck. It's been a long 3 days. I'll try to explain with clips from my application. I've been extending ItemizedIconOverlay and OverlayItem so I hope it doesn't get too confusing.

I created my own OSMDroid SQLite map file with 3 different zoom levels for a small are, like 10 square kms. I copied the resulting "base.sqlite" file into my project /res/raw/ directory. Note that the GeoPoints in my application should be well within the map's tile range. The "base.sqlite" file should get saved to the application specific data directory.

Next I turfed the /osmdroid directory on my phone so I could get the previously cached maps off. I thought I had my own offline maps working until I turned on Airplane mode and noticed the cached maps were still available.

Now all I get is blanks. I have no clue how to get this going. I've see a couple of examples but after a ton of experimentation I haven't been successful in getting any of them working.

private Hashtable<String, NodeOverlayItem> nodes = new Hashtable<String, NodeOverlayItem>();

private MapView mapView;
private Context context;

private LocationManager locManager;

private MapController mapController;
private MapTileProviderArray mapProvider;
private String mapTileArchivePath = "base.sqlite";

private ResourceProxy resourceProxy;

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        this.mapView = new MapView(this, 256);
        this.mapView.setBuiltInZoomControls(true);
        this.mapView.setMultiTouchControls(true);

        this.context = this.getApplicationContext();
        this.resourceProxy = new DefaultResourceProxyImpl(context);

        XYTileSource TILERENDERER = new XYTileSource("test", 
            ResourceProxy.string.offline_mode, 
            1, 20, 256, ".png", "http://127.0.0.1");
        SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this.context);

        IArchiveFile[] archives = { ArchiveFileFactory.getArchiveFile(this.getMapsFile()) };
        MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(
                simpleReceiver, 
                TILERENDERER, 
                archives);
        this.mapProvider = new MapTileProviderArray(TILERENDERER, null, new MapTileModuleProviderBase[] { moduleProvider });
        this.mapProvider.setUseDataConnection(false);
        this.mapView = new MapView(this, 256, this.resourceProxy, this.mapProvider);
        this.mapView.setUseDataConnection(false);

        mapController = mapView.getController();
        mapController.setZoom(18);
        mapController.setCenter(new GeoPoint((int)(45.349622 * 1E6), (int)(-75.880700 *1E6)));

        this.setContentView(mapView);
    } catch(Exception ex) {
        Log.e("test", ex.getMessage());
    }    
}


public File getMapsFile() throws IOException {
    Log.d("test", "Trying to load map tiles to: " + this.mapTileArchivePath);
    FileOutputStream fos = this.openFileOutput(this.mapTileArchivePath, Context.MODE_PRIVATE);

    InputStream in = getResources().openRawResource(R.raw.osmdroid);
    byte[] buff = new byte[1024];
    int read = 0;
    try {
    while ((read = in.read(buff)) > 0) {
      fos.write(buff, 0, read);
    }
    } finally {
      in.close();
      fos.close();
    }
    return new File(this.getFilesDir(), this.mapTileArchivePath);
    }

解决方案

OK! I know what I doing wrong and I have it all working now! (I'm excited :)

Firstly, I had some trouble with writing my Raw resource map file to the application specific directory (e.g. openFileOutput()) I'm using a Galaxy Nexus which doesn't have an SD slot so I can't dump the map file to SD. Ensure the maps file you intend to use is byte compared with the original copy. Eclipse's DDMS perspective is useful to view a device's file structure.

I also switched to the OSMdroid Zip format. I then made sure the XYTileSource() name matched the directory created in the Zip file by MOBAC, plus ensure the tile size and zoom levels match.

XYTileSource TILERENDERER = new XYTileSource("OSM CloudMade 1", ResourceProxy.string.offline_mode, 16, 18, 256, ".png", "http://127.0.0.1");

MOBAC by default will create 256 pixel tiles. I created an atlas file with 16, 17, and 18 zoom levels. PNG is the default MOBAC tile image format.

Also, if your map file has any issues, ArchiveFileFactory.getArchiveFile() will catch them, even before MapTileFileArchiveProvider.

Here's my usage. Just make every effort to get your IArchive setup correctly and you should be ok:

        XYTileSource TILERENDERER = new XYTileSource("OSM CloudMade 1", ResourceProxy.string.offline_mode, 16, 18, 256, ".png", "http://127.0.0.1");
        SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this.context);
        IArchiveFile[] archives = { ArchiveFileFactory.getArchiveFile(this.getMapsSdCard()) };
        MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(
                simpleReceiver, 
                TILERENDERER, 
                archives);
        this.mapProvider = new MapTileProviderArray(TILERENDERER, null, new MapTileModuleProviderBase[] { moduleProvider });
        this.mapProvider.setUseDataConnection(false);
        this.mapView = new MapView(this, 256, this.resourceProxy, this.mapProvider);
        this.mapView.setUseDataConnection(false);

Maybe I'm the only one who had trouble with this, but osmdroid doesn't clearly document how to do this, and when I opened the issue I couldn't get them to comment on my usage. If they had said I was implementing MapTileFileArchiveProvider correctly or included a good offline mapping sample, I would have focused on everything else first.

这篇关于如何使用MOBAC OSMDroid SQLite的瓷砖源文件离线产生的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆