Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

How to use external vector tile source #1901

Closed
smazokha opened this issue Jul 18, 2015 · 4 comments
Closed

How to use external vector tile source #1901

smazokha opened this issue Jul 18, 2015 · 4 comments

Comments

@smazokha
Copy link

I am working on android application and want to implement mapbox gl in it.

But I don't want to use Mapbox maps data, I want to parse OSM on my own and use it as data source.
In this issue #1900 I was asking if there is a possibility to implement my idea and it was told that this is possible. The only thing I have to think of is vector tile source that conforms to the Mapbox Vector Tile Spec.

So now the question:

How can I use my own new vector tile source with Mapbox GL in Android (in the future) and iOS? How can it be implemented? Are there any tutorials / examples about it?

IMPORTANT: I am not talking about data overlaid on top of base maps as in the answer #1900 . The question is about using entirely different source of maps data with mapbox gl native renderer.

Thanks for help.

@tmpsantos
Copy link
Contributor

As you learned from #1900, the only vector tile format that Mapbox GL knows how to render is the one following our spec.

That said, it doesn't necessary need to fetch the tiles from Mapbox servers. You can generate your vector tiles from whatever source of data you have and point Mapbox GL to it using a custom style.

Here is where we point to our source file on the "Dark" style. You can replace it with something like http://example.com/mysource.json.

And here is how a source.json must look like.

Finally, you don't need to get the vector tiles from the network via HTTP. You could, for instance, get it from a SQLite database on the disk. Mapbox GL uses an abstraction called FileSource and performs Requests to it. The DefaultFileSource on Android will turn these requests into HTTP requests.

You could implement you own FileSource getting the vector tile data from anywhere you want. For instance, the unit tests getting tiles from the filesystem using a custom FileSource. Have a look at it here

I'm more experienced with Mapbox GL as used on Linux Desktop/Server or OSX. I guess for Android will not be so different. I'm not sure if Android is exposing the FileSource interface, but if it is not, it is open source, right? 😄

@ljbade
Copy link
Contributor

ljbade commented Jul 29, 2015

@tmpsantos Eventually when the offline maps features land it will be possible to load from a MBTiles files.

@iranianmind00
Copy link

As you learned from #1900, the only vector tile format that Mapbox GL knows how to render is the one following our spec.

That said, it doesn't necessary need to fetch the tiles from Mapbox servers. You can generate your vector tiles from whatever source of data you have and point Mapbox GL to it using a custom style.

Here is where we point to our source file on the "Dark" style. You can replace it with something like http://example.com/mysource.json.

And here is how a source.json must look like.

Finally, you don't need to get the vector tiles from the network via HTTP. You could, for instance, get it from a SQLite database on the disk. Mapbox GL uses an abstraction called FileSource and performs Requests to it. The DefaultFileSource on Android will turn these requests into HTTP requests.

You could implement you own FileSource getting the vector tile data from anywhere you want. For instance, the unit tests getting tiles from the filesystem using a custom FileSource. Have a look at it here

I'm more experienced with Mapbox GL as used on Linux Desktop/Server or OSX. I guess for Android will not be so different. I'm not sure if Android is exposing the FileSource interface, but if it is not, it is open source, right? 😄

some links are moved now . can you help me to find some guides for FileSource implementation ? or any other offline vector tile data ?

@Guilherme-B
Copy link

Guilherme-B commented Apr 22, 2019

some links are moved now . can you help me to find some guides for FileSource implementation ? or any other offline vector tile data ?

As far as I can tell, here is the test file:
offline_download.test.cpp

Not having dug this thoroughly, the API allows you to modify the baseURL, meaning, where the maps will be retrieved from via public abstract Builder baseUrl(@NonNull String baseUrl); from MapRouteTiles.java. For this purpose, you might need to call autoBuild() directly, as build() will attempt to validate your MapBox user key.

Update:
I don't usually work with Mapbox, thus, am not quite familiar with the project's structure. But it seems that FileSource.* holds the actual URL handling logic. And the test the previous developers mentioned can be found at: offline_download.test.cpp#L139

Update #2:
Found it. You should manually override ResourceTransformCallback

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants