Cordova support?
I'm using Cordova/Ionic in order to serve offline tiles. I'm doing this by leveraging sqlite-ext to open a mbtiles file on the device and serve the tiles from there. Is there a way to to use pmtiles in Cordova in similar manor? From the documentation it seems that there's a need to use memory mapped file or something similar, have you experimented with this?
I'm not really familiar with Cordova; what interface does it provide to access files on disk?
PMTiles is designed for HTTP and standard browser apis like fetch. If you have access to a "native" API with direct filesystem I/O, you may find MBTiles a better drop-in solution.
Thanks for your quick response! Cordova file API is the following: https://cordova.apache.org/docs/en/10.x/reference/cordova-plugin-file/ Which doesn't seem to support memory mapped files as most of the communication between the native and webview (which is how Cordova presents its UI) is based on moving objects from one place to another and less about "keeping pointers". In any case, it was worth a shot :-)
That looks like it can work; I already have an implementation built on the Web File API as part of the inspector, but it's not abstracted out into the library:
https://github.com/protomaps/PMTiles/blob/master/examples/inspector.html#L76
the key thing is the File API's slice method, which is higher level than mmap; memory-mapping is not strictly necessary or optimal depending on your programming model.
True, but if I won't be using memory map I'll need to load the entire data into memory, right? In my case it's about 0.5 GB of data, which is not ideal when talking about mobile device, right?
It depends on Cordova's implementation of the File API - the inspector mentioned above https://protomaps.github.io/PMTiles/examples/inspector.html certainly doesn't load the entire file into memory at least on Chrome, Firefox and Safari, because the slice method can do efficient random I/O - this is a very typical demand of these APIs and probably itself uses mmap under the hood.
Can you test if Cordova's implementation does this successfully with some random non-tile data like a bunch of zeroes? if so we can consider a File API implementation of a generic JavaScript interface to go alongside fetch as part of the 1.0 TypeScript rewrite I'm doing.
Thanks!! I'll have to check, but it might take me a while...
In theory, Cordova can work out of the box now with FileAPISource: https://github.com/protomaps/PMTiles/blob/master/js/index.ts#L239 or may require a slightly custom implementation. Is there any action items here or an example open source test project to try this with?
I don't have anything easy to setup to test this unfortunately. I'm also not sure how appealing this might be as I recently switched to capacitor where the sqlite plugin seems to be supported and not "semi-supported" like sqlite-ext was. An example of this working in an app as an offline source would probably be a great example, but it might be a bit too much to do just for this...
OK, I am going mark this as closed now because the Source TypeScript class is extensible so it should "just work" for any JS environment.