how to use Openmap vector tiles with mapbox android Sdk - android

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.

Related

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

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.

how to hide or show KML layer in google map Android studio

my code is here to upload the kml file .
layer = new KmlLayer(mMap, inputstrm, getApplicationContext());
layer.addLayerToMap();
layer.visibility(true);
I have loaded KML file in googleMap android studio but I can not figure out how to make layer visible status.there is my problem Please someone help
If your layer can call visibility,try this:
layer.visibility(View.GONE);
or
layer.visibility(View.INVISIBLE);
accoriding to your test , change to this, try it:
layer.setVisibility(View.VISIBLE);//show
layer.setVisibility(View.GONE);//hide , or use View.INVISIBLE

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?

Categories

Resources