Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Offline map overlay over Mapnik #1709

@at1839

Description

@at1839

Please note: issues related to or caused by osmbonuspack will be closed with a
suggestion to open an issue at https://github.com/MKergall/osmbonuspack

(feel free to delete whatever doesn't apply)

Issue Type

[ x] Question

The goal is to overlay tiles from offline maps to online, say Mapnik. We start with a TIFF scan of a map in paper format. The .sqlite archive is by Mobac where the .gpkg is Qgis made.

See below a bunch of wild code, just for testing purpose. I run the code, via Android Studio, onboard a quite old LG G2 Mini with LineageOS, Android version 7.1.2; actually I tried with most recent ones but I have a lot of issues, as an example onboard Android 11 the Geopackage stuff fires up an obscure database error and refuse to import the map, see issue #1706.

Do case …

Case 0 works.

Case 1 works. I have white tiles around my map but not an issue at now.

Case 2 works, again with white tiles around.

Case 3 mostly works. I see Mapnik’s tiles around my map but … those Mapnik tiles are just the previously cached ones, if I pan the map to a new square looks like online tiles are not downloaded, as if someone forced setUseDataConnection(false), ouch.

Case 4 doesn’t work. I do have nice Mapnik tiles and no trace of the Geopackage’s ones.

:)

Disclaimer. I’m quite a beginner. First at all I’d need to know if I’m on the right track or I badly misunderstood how to deal with the above goal.

And if I’m not dead wrong, what’s about my code? Please help :)

TyL. Paolo.

@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState);
   Context ctx = getApplicationContext();
   Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

   setContentView(R.layout.activity_main);
   mMapView = (MapView) findViewById(R.id.map);
   mMapView.setBuiltInZoomControls(true);
   mMapView.setMultiTouchControls(true);

   File fileSqlite = new File(getExternalFilesDir(null), "osmdroid/cesaneMTB.sqlite");
   OfflineTileProvider cesaneProvider = new OfflineTileProvider(new SimpleRegisterReceiver(this), new File[]{fileSqlite});
   ITileSource cesaneSource = FileBasedTileSource.getSource("cesaneMTB");
   TilesOverlay cesaneOverlay = new TilesOverlay(cesaneProvider, ctx);

   File fileGpkg = new File(getExternalFilesDir(null), "osmdroid/cesaneMTB.gpkg");
   File[] mapsGpkg = {fileGpkg};
   GeoPackageProvider geoPackageProvider = new GeoPackageProvider(mapsGpkg, this);
   List<GeopackageRasterTileSource>gpkgTileSources = geoPackageProvider.geoPackageMapTileModuleProvider().getTileSources();
   GeopackageRasterTileSource gpkgSrc = (GeopackageRasterTileSource) gpkgTileSources.get(0);
   TilesOverlay gpkgOverlay = new TilesOverlay(geoPackageProvider, ctx);
   if (!gpkgTileSources.isEmpty()) {
       log_d( "########################### DEBUG, just in case ... #############################" );
       log_d( "########################### DEBUG gpkg source set to " + gpkgSrc.name() );
   }

   int selectedSource = 0;

   switch(selectedSource) {
      case 0:
      // Mapnik
         mMapView.setTileSource(TileSourceFactory.MAPNIK);
         break;

      case 1:
      // cesaneMTB.sqlite
         mMapView.setTileProvider(cesaneProvider);
         mMapView.setTileSource(cesaneSource);
         break;

      case 2:
      // cesaneMTB.gpkg
         mMapView.setTileProvider(geoPackageProvider);
         mMapView.setTileSource(gpkgSrc);
         break;

      case 3:
      // Mapnik overlay cesaneMTB.sqlite
         mMapView.setTileSource(TileSourceFactory.MAPNIK);
         mMapView.getOverlays().add(cesaneOverlay);
         break;

      case 4:
      // Mapnik overlay cesaneMTB.gpkg
         mMapView.setTileSource(TileSourceFactory.MAPNIK);
         mMapView.getOverlays().add(gpkgOverlay);
         break;
     }

   IMapController mapController =  mMapView.getController();
   mapController.setZoom(MAP_ZOOM);
   mapController.setCenter(centerPoint);
   mMapView.invalidate();

} //  onCreate

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions