titanium-mapbox icon indicating copy to clipboard operation
titanium-mapbox copied to clipboard

Ability to have mbtiles outside of bundle dir

Open firefountain opened this issue 9 years ago • 17 comments

Right now.. I can't for the life of me figure out a way to get the sdk to read mbtiles that are not bundled with the app.

If we want to download a map after the app is compiled, its impossible to load it up..Everything get's downloaded to the Documents dir, outside the bundle.

Anyway to quickly change it?

firefountain avatar Sep 08 '14 13:09 firefountain

@firefountain did you find a way to achieve this ?

psyzz avatar Oct 15 '14 14:10 psyzz

My priorities shifted to another issue. But a little bit of research showed that you can changed it on the source code in iOS.

Dig a bit. You need to chance a few things when you load the map. RMMBTilesSource

firefountain avatar Oct 15 '14 14:10 firefountain

Sorry haven't had any free time to spend on this due to work and personal obligations -- yes this should be possible with some changes with referencing the path in RMMBTilesSource. When I get a chance I will take a look.

adampax avatar Oct 15 '14 14:10 adampax

Ok, thanks guys i make some changes in RMMBTilesSource and ComPolancomediaMapboxView.m to do the thing. Now i'll try to add eventlistener 'click' on annotation popup

psyzz avatar Nov 04 '14 15:11 psyzz

@arshavinho Care to share the code?

I can give you the event listener for the "click" on annotation. Already have that made!

firefountain avatar Nov 05 '14 12:11 firefountain

@firefountain yes, did you have make anothers features ? I need to set image for annotations, i know @adampax already try this. I also need eventlistener click on polygon.

I'm really not comfortable with objC so to have mbtiles outside of bundle dir, i don't produce an optimized code. I will post my code tomorow but the trick is to use - (id)initWithTileSetURL:(NSURL *)tileSetURL and set "map" with Ti.Filesystem.getFile(path_to_mbtiles).resolve()

var mapView = mapbox.createView({
        // map: '/maps/road-trip',
                map: Ti.Filesystem.getFile(path_to_mbtiles).resolve(),
                minZoom: 7,
        maxZoom: 12,
        zoom: 9,
        centerLatLng: [18.467354,-91.903534],
        width: Ti.UI.FILL,
        height: Ti.UI.FILL,
        debugTiles:true
    });

psyzz avatar Nov 05 '14 20:11 psyzz

@arshavinho Could you share your code? Thanks!

fyi: I'll implement the ability to import a geoJSON Layer soon.

maikkley avatar Nov 10 '14 15:11 maikkley

All, sorry for being offline for a while, been busy moving to another country. I will hopefully have some more availability in the coming weeks to help with some of the new stuff people want implemented.

adampax avatar Nov 10 '14 16:11 adampax

Yes, i comment line 62 - 77 in ComPolancomediaMapboxView.m and add:

mapSource = [[RMMBTilesSource alloc] initWithTileSetURL:[NSURL fileURLWithPath:mapPath]];

You need to send the mbtiles file path with .resolve() :

var mapView = mapbox.createView({
        // map: '/maps/road-trip',
        map: Ti.Filesystem.getFile(path_to_mbtiles).resolve(),
        minZoom: 7,
        maxZoom: 12,
        zoom: 9,
        centerLatLng: [18.467354,-91.903534],
        width: Ti.UI.FILL,
        height: Ti.UI.FILL,
        debugTiles:true
    });

psyzz avatar Nov 10 '14 19:11 psyzz

@adampax i noticed that the memory used isn't release when we close the window, did you notice ? I moved to Ti.Map and add MKTileOverlay for that

psyzz avatar Nov 10 '14 19:11 psyzz

@arshavinho I'm going to open a new issue and drop my code there. Easier to control

https://github.com/adampax/titanium-mapbox/issues/12

There you go!

firefountain avatar Nov 11 '14 14:11 firefountain

@adampax

You think you could proof and incorporate my code...I think I'm on the right track. I can't test as I can't figure out how to compile!

I want to still be able to use the resources directory (default) for testing but also need the ability to download maps OTA or via iTunes and use them.

Thanks!

line59:
        NSLog(@"[VIEW LIFECYCLE EVENT] addMap");

        NSString *mapPath = [TiUtils stringValue:[self.proxy valueForKey:@"map"]];
        id mapSource;

        //check absolute path
        NSString *mapInApplicationDataFolder = [[NSBundle mainBundle] pathForResource:
                          mapPath ofType:@".mbtiles" inDirectory:@"applicationDataDirectory"]; //is this right? or somehow use the fullly resolved path instead

        //check if file exists, otherwise try to add remote map
        NSString *mapInResourcesFolder = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[mapPath stringByAppendingString:@".mbtiles"]];

        BOOL fileExistsAppData = [[NSFileManager defaultManager] fileExistsAtPath:mapInApplicationDataFolder];
        NSLog(@"mapFile exists in AppData: %i", fileExistsAppData);

        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:mapInResourcesFolder];
        NSLog(@"mapFile exists in Resources (default): %i", fileExists);

        if( fileExistsAppData)
        {
            mapSource = [[RMMBTilesSource alloc] initWithTileSetURL:[NSURL fileURLWithPath:mapInApplicationDataFolder]];  //arshavinho credit  //mapInApplicationDataFolder generate proper URL?? or do we want to somehow use Ti.Filesystem.getFile(path_to_mbtiles).resolve()
        }
        else if(fileExists)
        {
            mapSource = [[RMMBTilesSource alloc] initWithTileSetResource:mapPath ofType:@"mbtiles"];

        } else
        {
            mapSource = [[RMMapBoxSource alloc] initWithMapID:mapPath];

        }

nitrag avatar Mar 10 '15 21:03 nitrag

@nitrag Why you dont use Titanium Code for loading the mbtiles and use it with the mapbox module?

maikkley avatar Mar 10 '15 21:03 maikkley

I thought the resources directory was read-only? So a download would land in ApplicationData which I could not get mapbox to see. Unless I'm missing something?

Download mbtiles from internet to save for offline use. <--trying to accomplish On Mar 10, 2015 5:40 PM, "maikkley" [email protected] wrote:

@nitrag https://github.com/nitrag Why you dont use Titanium Code for loading the mbtiles and use it with the mapbox module?

— Reply to this email directly or view it on GitHub https://github.com/adampax/titanium-mapbox/issues/10#issuecomment-78154436 .

nitrag avatar Mar 10 '15 21:03 nitrag

Yes you are right, the resource dir is read only. But you can access application dir with the module. Try so get file and the resolve method. This works for me :-)

maikkley avatar Mar 10 '15 22:03 maikkley

This still required the modification to ComPolancomediaMapboxView.m thought right?

I can't get the module to build for the life of me. Can anyone provide exact steps from cloning the git to building app? I'm probably missing some small detail. I would really like to contribute to this repo.

nitrag avatar Mar 11 '15 02:03 nitrag

OK I figured it out. Had to build with 3.4.1. Will attempt with 3.5.0 tomorrow and post my working code for both the AppData or Resources data file locations!

nitrag avatar Mar 11 '15 03:03 nitrag