-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
#255 LocalTile overlay #1876
#255 LocalTile overlay #1876
Conversation
Added android native AirMapLocalTile and its respective react component similar to UrlTile. Local tile can load localy stored tiles as overlay similarly as UrlTile.
Added ios sources to project Added ios sources to project
@zavadpe could you please fix the issues travis found so we can review the PR? Thanks 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except the NSLog
comment. Maybe @alvelig wants to have a look too 😊
lib/ios/AirMaps/AIRMap.m
Outdated
@@ -62,6 +63,7 @@ @implementation AIRMap | |||
|
|||
- (instancetype)init | |||
{ | |||
NSLog(@"AirMap.init................"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove all NSLog
instances ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this one somehow slipped my attention..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zavadpe there are more :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just found them :)
Apparently looks ok. |
Guess you meant @rborn ;) |
@rborn let's merge. I created an issue for documentation. We can merge it later. I'm going to make a PR for documenting offline and custom tiles. Any help is welcome anyway. |
README.md
Outdated
</MapView> | ||
``` | ||
|
||
For Android: if original (for example Google) tiles are not desirable (no need to download them when using offline tiles), set mapType to 'none'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what you mean in this phrase :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if you add LocalTile overlay into the map in Android, you can still see that google map loads tiles underneath your 'offline' tiles (if device is online). That can go against the whole reason why offline tiles are used in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does mapType={"none"} help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zavadpe maybe you should explain that in the file like you did for me? 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it helped me in my project :) I'm using this snippet:
mapType={Platform.OS == "android" ? "none" : "standard"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rborn ok, I'll add more thorough explanation ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is to replace GoogleMaps not to be bound to GMaps license agreement. Not saying that we will do it right now, but just a way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alvelig Get it, sounds like fun :)
LGTM, @alvelig ? |
LGTM. Thank you @zavadpe! BTW do you mind helping us triage the issues? |
@zavadpe We could define it actually @christopherdro should we follow any rules defined before? Or we are to define our own process? |
@type88 It seems you are trying to load offline tiles directly from your project structure. You need to store them locally in your device and load them using absolute path. I recommend to unzip them from assets on first start or something similar. |
@zavadpe Thanks for this. Your solution presents one more riddle for me to solve. I've never done what you are suggesting, can you recommend a starting point or any working examples? Do I need to install something like react-native-fs or zip? |
@type88 Yes, exactly. In a project I'm working on I for example use react-native-fs together with react-native-zip-archive to unzip tiles archive I'm downloading from our API. Once tiles are stored locally in a device, it should work as expected. |
@zavadpe is there a way to use your implementation with MBTiles? MBTiles follows the {z}/{x}/{y} structure. The only thing I am not sure about is how to feed the extracted data from the database back to The {z}{x}{y} values can be retrieved using url(forTilePath:). However, how to feed the data back from the database to |
@386sx any progress on this? |
@Stophface Currently, MBTiles can not be used with |
@zavadpe I found that: https://github.com/jjlabella/CustomTileOverlay. I think
are of interest (assuming accessing the database would be done on the JavSscript side). So theoretically it is possible to read The way I see it we could extend your On the other hand: Accessing the |
@Stophface Reading MBTiles file (with the help of the repo you found) and passing the data to MKTileOverlay shouldn't be a problem (just check AIRMapLocalTileOverlay.m loadTileAtPath method). It all must happen on native side with similar implementation on android. As for data format obtained from MBTiles file, it should be the same. |
@zavadpe It definitely will be a problem for me because I never wrote anything in Swift/Objecitve-C/Java before - only JavaScript and Python. However, I am happy to give it a try. Managing large datasets unbundled on the native file system is a pain. And I think a lot of other users would profit from being able to use |
@zavadpe Sooo, I forked the repo v0.20.1 (because of that problem #2051 I used v0.20.1). All the code I edit will go into it. If successful, I will pull my changes into the repo I forked and make a pull request to this repo. After investigating your LocalTile and the way the react-native-maps project is set up (that took a while), I think its better to reuse some of your code but create a different component. Something like |
@Stophface Yeah, I also think it could be separate component. Feel free to add me in loop, when you have something working (or opened PR from your fork to upstream). Good luck! |
@zavadpe Could you have a look at this https://github.com/Stophface/react-native-maps-0.20.1/issues/1? I am not sure how to make the component I created "known" to |
@zavadpe any tips on how to test this with Expo? (Sorry kind of new to react-native programming.) I'm running the Expo app on an iOS simulator and my android and not sure how to put the file in my local storage to access it. On my android I put the directory with the tiles in the right format in my downloads folder and try to access the path with '/storage/emulated/0/Download/{z}/{x}/{y}.png' but no luck--it just shows as blank with no map. I believe the expo app should have file permissions? |
@h3ll0w0rld123 Can you access the files on a different way? Maybe your path is wrong. Try accessing the images not through |
@Stophface Good idea, just tried it and looks like it's not reading it. Is it a permissions thing? Image code:
Map code:
How are you guys testing local storage? |
@h3ll0w0rld123 I never worked with expo... Maybe its a permission problem, maybe the path is not correct. But now you know that its not a I access the file system with |
@Stophface, @h3ll0w0rld123 Sorry guys, I'm busy these days and most of the time not near my computer. If |
@zavadpe No worries and thanks for doing this! So I got past the permissions issue, turns out Expo has a similar Filesystem. I'm able to add it to the file directory in the iOS simulator, and verified the app can read it via image, but it's still not working with LocalTile. Image now working:
But this is not working:
What is tileSize and does that matter? The doc says |
@h3ll0w0rld123 Nice! The TileSize matters. Its either 256 or 512 Pixel - depending how your tiles got created. Here a short explanation of the difference. If in doubt about your tile size: Normally tiles are created 256 x 256 Pixels. Looking at your screenshot it looks to me like you need an |
Thanks @Stophface, good to know yep it is indeed 256 pixels. So I don't think it's an API issue. I used the JTileDownloader and selected OpenCycleMap, and that image just has a water mark on it (my thoughts are that it should still work). Unless I'm missing something? |
Apologies if this isn't the best place to ask this, but would it be possible to add support for webp format tiles? It works in android but not iOS with the react-native-webp-support package. From the package: |
Related to my thing and for anyone else using Expo, looks like urltile works. But regardless, localtile is also awesome, great work! |
@zavadpe I submited my PR with MBTiles support for Google Specification #2208 It would be nice to pass a prop through which specification schema for the tiles is used. There is iOS
Soo integration here (line 28) while on Android these two lines are needed Android
See integration here (line 56-57) A simple if/else would do
and then (pseudo code)
However, for me its pretty hard to add a new variable from JavaScript and pass it all the way through to these two files: and Wanna contribute? |
Thanks for the PR @Stophface. I'm eagerly awaiting it! I made some comments on there, hope to learn more about the code. Regarding the TMS format, for local tiles wouldn't a solution be for the developer to manually convert their local tiles from TMS to XYZ? It's a one time thing and can be automated, so I wouldn't worry about it too much? The only way I can see this being a problem is if the file is downloaded from a 3rd party source, but I'd argue that for this type of thing self hosting a custom version would be better anyway. |
@h3ll0w0rld123 can you share how you got UrlTile to work with the localTiles? I followed your same errors entirely, from permissions and loading an image on top of the map successfully from the tilesPath, but no matter whether i use LocalTile or UrlTile this doesn't seem to be working. My only guess is that the format of the tiles is not mapping correctly. My tiles are in folders representing the zoom levels. (0, 1, 2, 3) were originally working in a webView with react-leaflet on native, but I am trying to migrate this code into the react-native maps for a more debuggable & testable interface. My tiles path is:
And I have tried both of the following
Sorry if this comment is a bit StackOverflow-esque, but the steps you have gone through seems identical to the steps I have taken thus far... there must be something minor I am missing, if it is not the folder structure for zoom levels. |
@zavadpe Peter thank you for your insights into this. I’m having some issues implementing this. Do you have some quick code examples you could share in your working usage of LocalTiles? |
@hariDasu any luck getting yours working? |
@systemlevel no, but i have abandoned this for a while and have stuck with using [https://github.com/react-native-community/react-native-webview](rn-community webview) |
Added support for locally stored tile overlay similar to UrlTile component. Usage example in CustomTilesLocal.js file, but basically one just adds tile overlay within the map:
<MapView ... >
<LocalTile
pathTemplate="/path/to/localy/stored/tiles/{z}/{x}/{y}.png"
tileSize={256}
/>
</MapView>
Path just points to the path where tiles are stored.