[Android][Mapbox] How to add others tile source to Mapbox map? - android

I'm looking for a solution to add other tile source to Mapbox map. For example, I have an tile source url like this https://tile.openstreetmap.org/{z}/{x}/{y}.png and I want to add this tile above original Mapbox Layer. I intend to use RasterLayer, but I don't know which url format should be inputed to this Layer, Mapbox document isn't clear.
Anyone could help me a solution for this issue?
Thanks!!

You should use the RasterSource with a TileSet :
RasterSource source = new RasterSource("source-id", new TileSet("2.1.0", baseUrl + "/{z}/{x}/{y}.png"));
map.addSource(source);

Another solution is to upload your tilesets with your mapbox studio account.
Drag and drop a MBTiles, KML, GPX, GeoJSON, Shapefile (zipped), or CSV file here to convert it into vector tiles. To create raster tiles, drag and drop a GeoTIFF file.

Related

how to use Openmap vector tiles with mapbox android Sdk

I am very new to Android development, but I managed to make bellow link work
https://www.mapbox.com/android-docs/map-sdk/overview/
Now I can load map by using mapbox API.
I just need one help , how can i use openmap vector tiles with this SDK, what do i need to change ?
I have installed vector tiles like this
http://mydomain:9090/styles/osm-bright/?vector#8/22.615/90.344
I did not find any documentation for this
Can any one please help me .
In order to use tiles hosted by a third-party, you need to set up a TileSet and then a VectorSource out of that set.
TileSet tileSet = new TileSet("2.1.0", TILE_SET_URL);
VectorSource source = new VectorSource(ID_SOURCE, tileSet);
Also important to note is, that when using vector tiles you need to define a source layer.
LineLayer lineLayer = new LineLayer(ID_LINE_LAYER, ID_SOURCE);
lineLayer.setSourceLayer("source-layer");
More on the source layer here, and a more elaborate example can be found in the Mapbox Demo App's repository.

How to use offline style definitions or map tiles in MapBox iOS/Android SDK?

I want to make offline map applications using mapbox iOS/Android SDK.
But, I load style from local filesystem, like below: (Sorry, I'm Xamarin user, so write in c#)
var bundlePath = NSBundle.MainBundle.BundlePath;
var filePath = Path.Combine(bundlePath, "gsimaps.json");
var styleURL = NSUrl.CreateFileUrl (filePath, null);
var mapView = new MapView (Bounds, styleURL);
Then error shows:
[ERROR] {Map}[Setup]: loading style failed: response class is not NSHTTPURLResponse
Are there any way to load styles from local data?
From file, from DB, from memory, any means are OK, I want to know the way to use local data.
And also, are there any ways to use local raster tile in MapBox SDK? (From file, DB, or memory..)
In Android,
First, declare a map_style.json inside assets folder
Then in Java code
mapView.setStyleUrl("asset://map_style.json");
You should take a look at my github project (Tiles for Android/iOS/UWP) but I have a problem with the updating of these tiles -> Double update for tiles..
MapBox have a plan to implement local interface:
https://github.com/mapbox/mapbox-gl-native/issues/7471

Load Mbtiles using Nutiteq SDK from Mapbox

I am figuring out the way to load the mbtiles from mapbox using nutiteq SDK. I know how to load the mbtiles offline using this code
// 1. Create tile data source from mbtiles file
MBTilesTileDataSource tileDataSource = new MBTilesTileDataSource("/sdcard/estonia_ntvt.mbtiles");
// 2. Load vector tile styleset
UnsignedCharVector styleBytes = AssetUtils.loadBytes("osmbright.zip");
MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);
// 3. Create vector tile decoder using the styleset
VectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);
// 4. Create vector tile layer, using previously created data source and decoder
TileLayer vectorTileLayer = new VectorTileLayer(tileDataSource, vectorTileDecoder);
// 5. Add vector tile layer
mapView.getLayers().add(vectorTileLayer);
Is there a way to load it directly from mapbox mbtiles url using Nutiteq SDK?
What do you mean by "mapbox mbtiles url", can you give an example? By mbtiles you mean offline packages?
I can think of following MapBox URLs:
a. For MapBox as online raster source see https://developer.nutiteq.com/guides/raster-tile-sources
b. For MapBox as online vector source you need to define also styling, and it needs a bit more coding:
// load style file from assets. Nutiteq style is quite well compatible with MapBox Streets,
// even though NT vector tiles are a bit different
UnsignedCharVector styleBytes = AssetUtils.loadBytes("nutibright-v2.zip");
if (styleBytes != null){
// Create style set
MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);
MBVectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);
// Create tile data source and layer for vector tiles
TileDataSource vectorTileDataSource = new HTTPTileDataSource(0, 14, "http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v5/{zoom}/{x}/{y}.vector.pbf?access_token=pk...YOUR-MAPBOX-KEY");
VectorTileLayer baseLayer = new VectorTileLayer(vectorTileDataSource, vectorTileDecoder);
// add layer to map
mapView.getLayers().add(baseLayer);
}

How to draw an overlay using KML on our own app in Android?

I want to draw an overlay using .kml files, just look like this. But on my own app in MapActivity.
31.kml, display district in Jakarta, Indonesia
or
the example that I get from googling
I'd already try this code, but it's just open google map app even that already give me a map with KML's overlay.
final Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=http://dl.dropbox.com/u/32264286/Unggahan/31.kml"));startActivity(myIntent);
Is it possible? And how can I implement this? Does anybody can help me.
Thanks in advance.
Best regards,
#AdityaSetyadi
To draw the maps using KML, on option is to write the code to parse KML and draw the overlays.
The solution is present with this link
How to draw a path on a map using kml file?

How can I implement offline maps using osmdroid by saving map tiles images into sqlite database?

I have a project that has a requirement of displaying map data in offline mode also. I have used OpenStreet maps for the same. I have saved map images(tiles) and each tile is referenced by a tilekey in database. I want to access these map tiles from database and use them accordingly.
Please suggest me.
Thanks in advance.
Map tiles in Osmdroid are provided by map tile providers. The default tile provider used by Osmdroid is MapTileProviderBasic. This provider extends MapTileProviderArray, which means that it is an array of a few other tile providers - when a tile is requested these tile providers are asked one by one for a tile image until one of them provides it. Take a look at the constructor of MapTileProviderBasic:
public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
final INetworkAvailablityCheck aNetworkAvailablityCheck,
final ITileSource pTileSource) {
super(pTileSource, pRegisterReceiver);
final TileWriter tileWriter = new TileWriter();
final MapTileFilesystemProvider fileSystemProvider =
new MapTileFilesystemProvider(pRegisterReceiver, pTileSource);
mTileProviderList.add(fileSystemProvider);
final MapTileFileArchiveProvider archiveProvider =
new MapTileFileArchiveProvider(pRegisterReceiver, pTileSource);
mTileProviderList.add(archiveProvider);
final MapTileDownloader downloaderProvider =
new MapTileDownloader(pTileSource, tileWriter, aNetworkAvailablityCheck);
mTileProviderList.add(downloaderProvider);
}
There are three map tile providers added to the array of providers, in this order:
MapTileFilesystemProvider - provides tiles from the file system (SD card directory)
MapTileFileArchiveProvider - provides tiles from archive in file system
MapTileDownloader - provides tiles by downloading them from the Internet (e.g. from OSM servers)
So the MapTileProviderBasic looks for a given tile first in the file system, if the tile is not available then it looks for it in archive files and again if it is not available there it downloads the tile from the Internet.
Ok, this is the default mechanism. If you want to change this mechanism to look for tiles stored in a DB then you can create you own class similar to MapTileProviderBasic. So your class could also extend MapTileProviderArray and just use other providers in the constructor. In Osmdroid there is a class DatabaseFileArchive which could probably help you in reading tiles from the DB.
After creating your own tile provider you should use it instead of the default one. Map tile providers are attached to the MapView. Some of the constructors of MapView take MapTileProviderBase as an argument - you can use one of them to attach your own provider.
The simplest way to get offline maps to work with the default provider MapTileProviderBasic is to put your map arhive(s) in OSMDROID_PATH.
In other words, download your .zip, .sqlite, .mbtiles or .gemf file into the osmdroid/ directory.
If you look at MapTileFileArchiveProvider you see it calls getArchiveFiles() in ArchiveFileFactory which chooses the right archive provider based on the file extensions.

Categories

Resources