Search code examples
androidopenstreetmapopenseamap

Integrating OpenSeaMap into Android application


I successfully integrated OpenStreetMap into my Android application using osmdroid and decided to try my hand at using OpenSeaMap as the map tile provider (the application is ocean-focussed).

Following the instructions outlined here for incorporating a custom tile provider into osmdroid I added the following code:

    // 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);

...notably, the code I've written excludes the GEMF file archive. To be honest, I don't understand the implications of this. Hopefully someone can shed some light on this topic as well. The effect of this is somewhat telling. Where OpenSeaMap information is provided a black tile is presented. Upon zooming in further, the tiles appear to be jumbled.

Black tiles where OpenSeaMap is adding content

As I continue to experiment, I noticed that sometimes, the OpenSeaMap data is rendered correctly;

Kind of working OpenSeaMap

Has anyone experienced similar issues with OpenSeaMap?


Solution

  • So, this was a bit of a two-fold thing, here is the code I'm running now;

    // 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);
    

    ...the setLoadingBackgroundColor state helped to avoid the black tiles and a bit of patience allowed the overlay to be pulled down from the server, it's a bit slow!