Closed GoogleCodeExporter closed 8 years ago
The sqlite archive format was added in revision 683 for issue 132.
Original comment by neilboyd
on 12 Dec 2012 at 6:30
I think what I'm saying is it's not clear how to properly load MOBAC OSMAND
SQLite tiles and I'd like to know how to do so properly. Other have been asking
this as well:
http://stackoverflow.com/questions/13827324/how-to-use-mobac-created-osmand-sqli
te-tile-source-file-offline
http://stackoverflow.com/questions/12968594/downloading-specific-maptiles-to-cac
he-in-osmdroid
As you can see in my sample code, I'm already using ArchiveFileFactory, which
indeed supports a variety of archive file types, including sqlite. The tiles
are still coming up empty.
Can you please comment on my use of MapTileModuleProviderBase, MapView,
MapTileFileArchiveProvider and SimpleRegisterReceiver? Am I using it right? Do
you have an existing sample on how to do this properly with the API? If I'm
doing it right, then I should probably investigate if my MOBAC map has an
issue. BTW, I'm using the latest MOBAC, downloaded 5 days ago. Thank you!
Original comment by ch...@mckenzieic.com
on 12 Dec 2012 at 3:57
In issue 132 which I linked to in my previous comment it says "you have to
chose the osmdroid sqlite format".
I assume that osmdroid sqlite format is different to osmand sqlite format.
Original comment by neilboyd
on 12 Dec 2012 at 8:26
Arg... Sorry that was a persistent typo. I've reattached a fresh MOBAC exported
Osmdroid sqlite map file. I'm still getting grey squares.
Now, can you please comment on my use of MapTileModuleProviderBase, MapView,
MapTileFileArchiveProvider and SimpleRegisterReceiver?
Thank you.
Original comment by ch...@mckenzieic.com
on 12 Dec 2012 at 11:30
Attachments:
Ok, my usage is good. I don't know exactly what my problem was, but I had some
trouble with the osmdroid sqllite file written to the device. I ended up
getting the zip format working. Just a suggestion, a small offline mapping
sample would be really helpful. Maybe I'm just over worked or lazy. Either way
I've got offline working perfectly now. Thanks for being patent with me. :)
Original comment by ch...@mckenzieic.com
on 14 Dec 2012 at 6:25
Kinda late, but is it still possible for you to provide your solution?
Would be really helpfull, thanks :)
Original comment by stefan.e...@gmail.com
on 2 Jul 2013 at 1:19
Sure, I'm not certain anymore what exactly was going wrong at the time, but
here's my implementation of the MapView. From what I've come up with, you can't
set and offline MapView outside of its construction. Meaning you have to
construct the MapView with a provided MapTileProviderArray that includes the
offline source. e.g. .zip or .sqlite file. I can't remember why this was an
issue for me in my actual application. I think I was having problems with app
orientation change. Since MapView is a valid View, it get constructed without
your help by Android. In order to construct it with my offline provider, I had
to extend MapView with my own constructor, that created and supplied the
offline provider.
So far my app seems to have no issues with this approach. It loads the maps
correctly and I don't get any orientation change memory leaks/errors when I
flip my tablet a dozen times or so.
Hope this helps.
MainActivity.java:
@Override
public void onCreate(final Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
...
this.mapView = (FieldMapView) findViewById(R.id.mapview);
...
// Example getting the map controller and setting the center
MapController mapController = this.mapView.getController();
mapController.setCenter(new GeoPoint(Nodes.LAT_DEFAULT, Nodes.LONG_DEFAULT));
...
}
public static String getMapTileArchiveFilename() {
return "default_map.zip";
}
main_activity.xml: (the layout)
...
<com.test.FieldMapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"/>
...
com.test.FieldMapView.java:
public class FieldMapView extends MapView {
public FieldMapView(Context context, AttributeSet attrs) throws Exception {
// Sigh... MapView has to be constructed as an offline caching view,
// which is the reason I've got these static calls in here...
super(context, 256, new DefaultResourceProxyImpl(context), FieldMapView
.getOfflineMapProvider(context, MainActivity.getMapTileArchiveFilename()), null, attrs);
this.setUseDataConnection(false);
this.setBuiltInZoomControls(true);
this.setMultiTouchControls(true);
this.setLongClickable(false);
}
public static MapTileProviderArray getOfflineMapProvider(Context context,
String mapArchiveFilename) throws Exception {
XYTileSource TILERENDERER = new XYTileSource("OSM CloudMade 1",
ResourceProxy.string.offline_mode, 16, 18, 256, ".png",
"http://127.0.0.1");
SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(
context);
IArchiveFile[] archives = { ArchiveFileFactory
.getArchiveFile(FieldMapView.getMapsSdCard(context,
mapArchiveFilename)) };
MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(
simpleReceiver, TILERENDERER, archives);
MapTileProviderArray mapProvider = new MapTileProviderArray(
TILERENDERER, null,
new MapTileModuleProviderBase[] { moduleProvider });
mapProvider.setUseDataConnection(false);
return mapProvider;
}
public FieldMapView(Context context, int tileSizePixels,
ResourceProxy resourceProxy, MapTileProviderBase aTileProvider,
Handler tileRequestCompleteHandler) {
super(context, tileSizePixels, resourceProxy, aTileProvider,
tileRequestCompleteHandler);
}
public FieldMapView(Context context, int tileSizePixels,
ResourceProxy resourceProxy, MapTileProviderBase aTileProvider) {
super(context, tileSizePixels, resourceProxy, aTileProvider);
}
public FieldMapView(Context context, int tileSizePixels,
ResourceProxy resourceProxy) {
super(context, tileSizePixels, resourceProxy);
}
public FieldMapView(Context context, int tileSizePixels) {
super(context, tileSizePixels);
}
public void onStop() {
this.getTileProvider().clearTileCache();
}
// TODO: Create a factory static method to construct the FieldMapView properly, use isInEditMode()
// to skip writing the file out, so it'll work with the Eclipse visualizer!
public static File getMapsSdCard(Context context, String mapArchiveFilename)
throws IOException {
Log.d("TEC3M", "Trying to load map tiles to: " + mapArchiveFilename);
File mapFile = new File(context.getFilesDir(), mapArchiveFilename);
if (!mapFile.exists()) {
// mapFile.delete();
FileOutputStream fos = context.openFileOutput(mapArchiveFilename,
Context.MODE_PRIVATE);
InputStream in = context.getResources().openRawResource(
R.raw.default_map);
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();
}
mapFile = new File(context.getFilesDir(), mapArchiveFilename);
}
return mapFile;
}
}
Original comment by ch...@mckenzieic.com
on 2 Jul 2013 at 2:43
This ticket is resolved.
Original comment by kurtzm...@gmail.com
on 10 Jul 2013 at 10:08
Original issue reported on code.google.com by
ch...@mckenzieic.com
on 11 Dec 2012 at 7:42Attachments: