Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Allow loadTileAtPath prop for LocalTile #2007

Closed
mellet opened this issue Feb 2, 2018 · 4 comments
Closed

[Feature Request] Allow loadTileAtPath prop for LocalTile #2007

mellet opened this issue Feb 2, 2018 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mellet
Copy link
Contributor

mellet commented Feb 2, 2018

A great feature would be the possibility to pass a loadTileAtPath prop that takes a function that allows you to load tiles with whatever means you want.

In some cases there is no direct access to the filesystem, or you want to get tile tiles from a local database etc.

A example would be when developing in Expo, as they only expose their own filesystem api that does not work when passed in to LocalTile.

Example usage

fetchTileExpo => async ({z,x,y}) => {
   const path = `${Expo.FileSystem.documentDirectory}tiles/${z}/${x}/${y}.png`
   const imageData = await Expo.FileSystem.readAsStringAsync(path)
   const image = new Image()
   image.src = `data:image/png;base64,${imageData}`
   return image
}

<MapView region={this.state.region}>
  <LocalTile
    loadTileAtPath={this.fetchTileExpo}
    tileSize={256}
  />
</MapView>

Looking at the source code the LocalTile looks like it already uses the native version of this, but just fetches the tile from the filesystem.

Would be great to be able to pass our own functions here that returns the tile, then the developer can customise how to fetch the tile if there is some special way that it needs to be done (Expo filesystem, database, some map service that needs some math done to x, y, z to get the correct tile etc).

@rborn rborn added enhancement New feature or request help wanted Extra attention is needed labels Feb 2, 2018
@mellet
Copy link
Contributor Author

mellet commented Feb 2, 2018

I actually managed to get offline maps working in Expo.
It looks like the Expo Filesystem is handled as if it was a url. So I can actually pass it to the MapTile.UrlTile.

However, this feature might still be good for some use cases.

@markmssd
Copy link

markmssd commented Feb 3, 2018

Great article, thanks for taking the time to explain your solution in details :) I will probably use it in a near future.

@h3ll0w0rld123
Copy link

Awesome work! This saved me, I was working for hours and couldn't figure out why localtile didn't work.

I had a question about your tile fetching though. It looks like you make a separate request for each tile. For performance, I'm hoping to download a compressed file, then uncompress in one go. I see expo doesn't have that feature and using a different library would require a detachment. Do you have any thoughts on this? Did you have to worry about performance?

@h3ll0w0rld123
Copy link

Also, looking at the source code, I believe the idea you suggested is not possible because the loading has to be done on the native side, not javascript. If so, I think this issue can be closed?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants