我使用osmdroid成功地将OpenStreetMap集成到我的Android应用程序中,并决定尝试使用OpenSeaMap作为地图图块提供程序(该应用程序以海洋为焦点)。
按照here概述的说明将自定义磁贴提供程序合并到 osmdroid 中,我添加了以下代码:
// Create a custom tile source
final IRegisterReceiver registerReceiver = new SimpleRegisterReceiver(context);
final ITileSource tileSource = new XYTileSource("Mapnik",
ResourceProxy.string.mapnik,
1,
18,
256,
".png",
new String[] {"http://tiles.openseamap.org/seamark/"});
// Create a file cache modular provider
final TileWriter tileWriter = new TileWriter();
final MapTileFilesystemProvider fileSystemProvider = new MapTileFilesystemProvider(registerReceiver, tileSource);
// Create a download modular tile provider
final NetworkAvailabliltyCheck networkAvailabliltyCheck = new NetworkAvailabliltyCheck(context);
final MapTileDownloader downloaderProvider = new MapTileDownloader(tileSource, tileWriter, networkAvailabliltyCheck);
// Create a custom tile provider array with the custom tile source and the custom tile providers
final MapTileProviderArray tileProviderArray = new MapTileProviderArray(tileSource, registerReceiver, new MapTileModuleProviderBase[] { fileSystemProvider, downloaderProvider });
// Create the mapview with the custom tile provider array
this.mapView = new MapView(context, 256, new DefaultResourceProxyImpl(context), tileProviderArray);
...值得注意的是,我编写的代码不包括GEMF文件存档。说实话,我不明白这个含义。希望有人也可以对这个话题有所了解。这种影响有点说明了。在提供OpenSeaMap信息的地方,呈现黑色图块。在进一步放大时,瓷砖似乎是混乱的。
当我继续进行实验时,我注意到有时,OpenSeaMap数据被正确呈现;
有没有人遇到与OpenSeaMap类似的问题?
答案 0 :(得分:0)
所以,这是一个双重的事情,这是我现在正在运行的代码;
// Create a custom tile source
final ITileSource seamarks = new XYTileSource("seamarks",
null,
0,
19,
256,
".png",
new String[] {"http://tiles.openseamap.org/seamark/"});
final MapTileProviderBasic tileProvider = new MapTileProviderBasic(context, seamarks);
final TilesOverlay seamarksOverlay = new TilesOverlay(tileProvider, context);
seamarksOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
seamarksOverlay.setUseSafeCanvas(true);
// Create the mapview with the custom tile provider array
this.mapView = new MapView(context, 256);
this.mapView.setMultiTouchControls(true);
this.mapView.setUseSafeCanvas(true);
this.mapView.getOverlays().add(seamarksOverlay);
... setLoadingBackgroundColor
状态有助于避免黑色瓷砖,并且有一点耐心允许覆盖从服务器上拉下来,它有点慢!